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

View File

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