Fix test, import locales

Co-authored-by: Robert Schäfer <git@roschaefer.de>
This commit is contained in:
Matt Rider 2019-06-12 19:29:51 -03:00
parent 97e8fa1af8
commit 8d72532098
2 changed files with 37 additions and 31 deletions

View File

@ -14,39 +14,43 @@ describe('ContributionForm.vue', () => {
let expectedParams
let deutschOption
let cancelBtn
let mocks
const postTitle = 'this is a title for a post'
const postContent = 'this is a post'
const computed = { locale: () => 'English' }
const mocks = {
$t: jest.fn(),
$apollo: {
mutate: jest
.fn()
.mockResolvedValueOnce({
data: {
CreatePost: {
title: postTitle,
slug: 'this-is-a-title-for-a-post',
content: postContent,
contentExcerpt: postContent,
language: 'en',
beforeEach(() => {
mocks = {
$t: jest.fn(),
$apollo: {
mutate: jest
.fn()
.mockResolvedValueOnce({
data: {
CreatePost: {
title: postTitle,
slug: 'this-is-a-title-for-a-post',
content: postContent,
contentExcerpt: postContent,
language: 'en',
},
},
},
})
.mockRejectedValue({ message: 'Not Authorised!' }),
},
$toast: {
error: jest.fn(),
success: jest.fn(),
},
$i18n: {
locale: () => 'en',
},
$router: {
back: jest.fn(),
push: jest.fn(),
},
}
})
.mockRejectedValue({ message: 'Not Authorised!' }),
},
$toast: {
error: jest.fn(),
success: jest.fn(),
},
$i18n: {
locale: () => 'en',
},
$router: {
back: jest.fn(),
push: jest.fn(),
},
}
})
describe('mount', () => {
const Wrapper = () => {
@ -55,6 +59,7 @@ describe('ContributionForm.vue', () => {
beforeEach(() => {
wrapper = Wrapper()
wrapper.setData({ form: { languageOptions: [{ label: 'Deutsch', value: 'de' }] } })
})
describe('CreatePost', () => {

View File

@ -48,6 +48,7 @@
import gql from 'graphql-tag'
import HcEditor from '~/components/Editor'
import orderBy from 'lodash/orderBy'
import locales from '~/locales'
export default {
components: {
@ -92,7 +93,7 @@ export default {
computed: {
locale() {
let locale
locale = process.env.locales.find(this.returnLocaleName)
locale = locales.find(this.returnLocaleName)
return locale.name
},
},
@ -141,7 +142,7 @@ export default {
}
},
availableLocales() {
orderBy(process.env.locales, 'name').map(locale => {
orderBy(locales, 'name').map(locale => {
this.form.languageOptions.push({ label: locale.name, value: locale.code })
})
},