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

86 lines
2.1 KiB
TypeScript
Raw Normal View History

2022-04-25 15:33:49 +02:00
import { createStore, Store } 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'
2022-04-25 15:33:49 +02:00
import { RootState } from '@/store'
;(window as any as MyWindow).ipcRenderer = ipcRenderer
const state = (): LanguageState => {
return {
language: {
language: DefaultLanguage.en.key,
spellchecker: {
enabled: true,
languages: []
}
}
}
}
const initStore = () => {
return {
namespaced: true,
state: state,
actions: Language.actions,
mutations: Language.mutations
}
}
2022-04-25 15:33:49 +02:00
const preferencesStore = () => ({
namespaced: true,
modules: {
Language: initStore()
}
})
describe('Preferences/Language', () => {
2022-04-25 15:33:49 +02:00
let store: Store<RootState>
beforeEach(() => {
2022-04-25 15:33:49 +02:00
store = createStore({
modules: {
2022-04-25 15:33:49 +02:00
Preferences: preferencesStore()
}
})
})
describe('loadLanguage', () => {
beforeEach(() => {
2020-11-30 14:30:06 +01:00
ipcMain.handle('get-preferences', () => {
return {
language: {
language: DefaultLanguage.ja.key,
spellchecker: {
enabled: true,
languages: []
}
}
2020-11-30 14:30:06 +01:00
}
})
})
2020-11-30 14:30:06 +01:00
afterEach(() => {
ipcMain.removeHandler('get-preferences')
})
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)
})
})
describe('changeLanguage', () => {
beforeEach(() => {
2020-11-30 14:30:06 +01:00
ipcMain.handle('change-language', (_, key: string) => {
return key
})
})
2020-11-30 14:30:06 +01:00
afterEach(() => {
ipcMain.removeHandler('change-language')
})
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)
})
})
})