2022-04-25 15:33:49 +02:00
|
|
|
import { createStore, Store } 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'
|
2022-04-25 15:33:49 +02:00
|
|
|
import { RootState } from '@/store'
|
|
|
|
;(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
|
|
|
}
|
|
|
|
|
2022-04-25 15:33:49 +02:00
|
|
|
const preferencesStore = () => ({
|
|
|
|
namespaced: true,
|
|
|
|
modules: {
|
|
|
|
Language: initStore()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-12-30 08:29:12 +01:00
|
|
|
describe('Preferences/Language', () => {
|
2022-04-25 15:33:49 +02:00
|
|
|
let store: Store<RootState>
|
2018-12-30 08:29:12 +01:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-04-25 15:33:49 +02:00
|
|
|
store = createStore({
|
2018-12-30 08:29:12 +01:00
|
|
|
modules: {
|
2022-04-25 15:33:49 +02:00
|
|
|
Preferences: preferencesStore()
|
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 () => {
|
2022-04-25 15:33:49 +02:00
|
|
|
await store.dispatch('Preferences/Language/loadLanguage')
|
|
|
|
expect(store.state.Preferences.Language.language.language).toEqual(DefaultLanguage.ja.key)
|
2018-12-30 08:29:12 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
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 () => {
|
2022-04-25 15:33:49 +02:00
|
|
|
await store.dispatch('Preferences/Language/changeLanguage', DefaultLanguage.ja.key)
|
|
|
|
expect(store.state.Preferences.Language.language.language).toEqual(DefaultLanguage.ja.key)
|
2018-12-30 08:29:12 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|