2018-12-30 08:29:12 +01:00
|
|
|
import { createLocalVue } from '@vue/test-utils'
|
|
|
|
import Vuex from 'vuex'
|
2019-12-04 14:35:53 +01:00
|
|
|
import { ipcMain, ipcRenderer } from '~/spec/mock/electron'
|
2019-04-06 15:08:29 +02:00
|
|
|
import Language, { LanguageState } from '@/store/Preferences/Language'
|
2018-12-30 08:29:12 +01:00
|
|
|
import DefaultLanguage from '~/src/constants/language'
|
2019-12-04 14:35:53 +01:00
|
|
|
import { MyWindow } from '~/src/types/global'
|
2020-04-11 11:22:49 +02:00
|
|
|
;((window as any) as MyWindow).ipcRenderer = ipcRenderer
|
2018-12-30 08:29:12 +01:00
|
|
|
|
2019-04-06 15:08:29 +02:00
|
|
|
const state = (): LanguageState => {
|
2019-02-16 11:41:58 +01:00
|
|
|
return {
|
|
|
|
language: {
|
|
|
|
language: DefaultLanguage.en.key
|
|
|
|
}
|
2018-12-30 08:29:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-16 11:41:58 +01:00
|
|
|
const initStore = () => {
|
|
|
|
return {
|
|
|
|
namespaced: true,
|
|
|
|
state: state,
|
|
|
|
actions: Language.actions,
|
|
|
|
mutations: Language.mutations
|
|
|
|
}
|
2018-12-30 08:29:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('Preferences/Language', () => {
|
|
|
|
let store
|
|
|
|
let localVue
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
localVue = createLocalVue()
|
|
|
|
localVue.use(Vuex)
|
|
|
|
store = new Vuex.Store({
|
|
|
|
modules: {
|
2019-02-16 11:41:58 +01:00
|
|
|
Language: initStore()
|
2018-12-30 08:29:12 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('loadLanguage', () => {
|
|
|
|
beforeEach(() => {
|
2019-03-28 15:35:25 +01:00
|
|
|
ipcMain.once('get-preferences', (event: any, _) => {
|
2018-12-30 08:29:12 +01:00
|
|
|
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(() => {
|
2019-03-28 15:35:25 +01:00
|
|
|
ipcMain.once('change-language', (event: any, key: string) => {
|
2018-12-30 08:29:12 +01:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|