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: {
|
2021-03-25 11:04:31 +01:00
|
|
|
language: DefaultLanguage.en.key,
|
|
|
|
spellchecker: {
|
2021-03-25 16:48:20 +01:00
|
|
|
enabled: true,
|
|
|
|
languages: []
|
2021-03-25 11:04:31 +01:00
|
|
|
}
|
2019-02-16 11:41:58 +01:00
|
|
|
}
|
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(() => {
|
2020-11-30 14:30:06 +01:00
|
|
|
ipcMain.handle('get-preferences', () => {
|
|
|
|
return {
|
2018-12-30 08:29:12 +01:00
|
|
|
language: {
|
2021-03-25 11:04:31 +01:00
|
|
|
language: DefaultLanguage.ja.key,
|
|
|
|
spellchecker: {
|
2021-03-25 16:48:20 +01:00
|
|
|
enabled: true,
|
|
|
|
languages: []
|
2021-03-25 11:04:31 +01:00
|
|
|
}
|
2018-12-30 08:29:12 +01:00
|
|
|
}
|
2020-11-30 14:30:06 +01:00
|
|
|
}
|
2018-12-30 08:29:12 +01:00
|
|
|
})
|
|
|
|
})
|
2020-11-30 14:30:06 +01:00
|
|
|
afterEach(() => {
|
|
|
|
ipcMain.removeHandler('get-preferences')
|
|
|
|
})
|
2018-12-30 08:29:12 +01:00
|
|
|
it('should be updated', async () => {
|
|
|
|
await store.dispatch('Language/loadLanguage')
|
|
|
|
expect(store.state.Language.language.language).toEqual(DefaultLanguage.ja.key)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('changeLanguage', () => {
|
|
|
|
beforeEach(() => {
|
2020-11-30 14:30:06 +01:00
|
|
|
ipcMain.handle('change-language', (_, key: string) => {
|
|
|
|
return key
|
2018-12-30 08:29:12 +01:00
|
|
|
})
|
|
|
|
})
|
2020-11-30 14:30:06 +01:00
|
|
|
afterEach(() => {
|
|
|
|
ipcMain.removeHandler('change-language')
|
|
|
|
})
|
2018-12-30 08:29:12 +01:00
|
|
|
it('should be changed', async () => {
|
|
|
|
await store.dispatch('Language/changeLanguage', DefaultLanguage.ja.key)
|
|
|
|
expect(store.state.Language.language.language).toEqual(DefaultLanguage.ja.key)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|