1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2024-12-12 00:45:19 +01:00
Whalebird-desktop-client-ma.../spec/renderer/integration/store/Preferences/Language.spec.ts

68 lines
1.7 KiB
TypeScript
Raw Normal View History

import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import { ipcMain, ipcRenderer } from '~/spec/mock/electron'
import Language, { LanguageState } from '@/store/Preferences/Language'
import DefaultLanguage from '~/src/constants/language'
import { MyWindow } from '~/src/types/global'
2020-04-11 11:22:49 +02:00
;((window as any) as MyWindow).ipcRenderer = ipcRenderer
const state = (): LanguageState => {
return {
language: {
language: DefaultLanguage.en.key
}
}
}
const initStore = () => {
return {
namespaced: true,
state: state,
actions: Language.actions,
mutations: Language.mutations
}
}
describe('Preferences/Language', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Language: initStore()
}
})
})
describe('loadLanguage', () => {
beforeEach(() => {
ipcMain.once('get-preferences', (event: any, _) => {
event.sender.send('response-get-preferences', {
language: {
language: DefaultLanguage.ja.key
}
})
})
})
it('should be updated', async () => {
await store.dispatch('Language/loadLanguage')
expect(store.state.Language.language.language).toEqual(DefaultLanguage.ja.key)
})
})
describe('changeLanguage', () => {
beforeEach(() => {
ipcMain.once('change-language', (event: any, key: string) => {
event.sender.send('response-change-language', key)
})
})
it('should be changed', async () => {
await store.dispatch('Language/changeLanguage', DefaultLanguage.ja.key)
expect(store.state.Language.language.language).toEqual(DefaultLanguage.ja.key)
})
})
})