Whalebird-desktop-client-ma.../spec/renderer/integration/store/App.spec.ts

108 lines
2.9 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 App from '@/store/App'
import DisplayStyle from '~/src/constants/displayStyle'
2019-04-17 13:46:47 +02:00
import { LightTheme, DarkTheme } from '~/src/constants/themeColor'
import Theme from '~/src/constants/theme'
import TimeFormat from '~/src/constants/timeFormat'
import Language from '~/src/constants/language'
import DefaultFonts from '@/utils/fonts'
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 = () => {
return {
theme: LightTheme,
fontSize: 14,
displayNameStyle: DisplayStyle.DisplayNameAndUsername.value,
notify: {
reply: true,
reblog: true,
favourite: true,
follow: true
},
timeFormat: TimeFormat.Absolute.value,
language: Language.en.key,
defaultFonts: DefaultFonts,
ignoreCW: false,
ignoreNSFW: false,
2019-02-18 14:16:19 +01:00
hideAllAttachments: false
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: App.actions,
mutations: App.mutations
}
}
describe('App', () => {
2022-04-25 15:33:49 +02:00
let store: Store<RootState>
beforeEach(() => {
2022-04-25 15:33:49 +02:00
store = createStore({
modules: {
App: initStore()
}
})
})
describe('loadPreferences', () => {
describe('error', () => {
it('should not change', async () => {
2020-11-30 14:30:06 +01:00
ipcMain.handle('get-preferences', async () => {
throw new Error()
})
await store.dispatch('App/loadPreferences').catch(err => {
expect(err instanceof Error).toEqual(true)
expect(store.state.App.theme).toEqual(LightTheme)
})
2020-11-30 14:30:06 +01:00
ipcMain.removeHandler('get-preferences')
})
})
describe('success', () => {
it('should be changed', async () => {
2020-11-30 14:30:06 +01:00
ipcMain.handle('get-preferences', () => {
return {
general: {
timeline: {
cw: true,
nsfw: true
}
},
language: {
language: Language.en.key
},
notification: {
notify: {
reply: true,
reblog: true,
favourite: true,
follow: true
}
},
appearance: {
theme: Theme.Dark.key,
fontSize: 13,
displayNameStyle: DisplayStyle.DisplayNameAndUsername.value,
timeFormat: TimeFormat.Absolute.value,
customThemeColor: LightTheme,
font: DefaultFonts[0]
}
2020-11-30 14:30:06 +01:00
}
})
await store.dispatch('App/loadPreferences')
expect(store.state.App.fontSize).toEqual(13)
expect(store.state.App.theme).toEqual(DarkTheme)
expect(store.state.App.ignoreCW).toEqual(true)
expect(store.state.App.ignoreNSFW).toEqual(true)
2020-11-30 14:30:06 +01:00
ipcMain.removeHandler('get-preferences')
})
})
})
})