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

131 lines
3.3 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 General, { GeneralState } from '@/store/Preferences/General'
import { MyWindow } from '~/src/types/global'
2020-11-30 14:30:06 +01:00
import { IpcMainInvokeEvent } from 'electron'
2022-04-25 15:33:49 +02:00
import { RootState } from '@/store'
;(window as any as MyWindow).ipcRenderer = ipcRenderer
const state = (): GeneralState => {
return {
general: {
sound: {
fav_rb: true,
toot: true
},
timeline: {
cw: false,
nsfw: false,
hideAllAttachments: false
},
other: {
launch: false
}
},
loading: false
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: General.actions,
mutations: General.mutations
}
}
2022-04-25 15:33:49 +02:00
const preferencesStore = () => ({
namespaced: true,
modules: {
General: initStore()
}
})
const app = {
namespaced: true,
actions: {
loadPreferences(_) {
return true
}
}
}
describe('Preferences/General', () => {
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(),
App: app
}
})
})
describe('loadGeneral', () => {
beforeEach(() => {
2020-11-30 14:30:06 +01:00
ipcMain.handle('get-preferences', () => {
return {
general: {
sound: {
fav_rb: false,
toot: false
}
}
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/General/loadGeneral')
expect(store.state.Preferences.General.general.sound.fav_rb).toEqual(false)
expect(store.state.Preferences.General.general.sound.toot).toEqual(false)
expect(store.state.Preferences.General.loading).toEqual(false)
})
})
describe('updateSound', () => {
beforeEach(() => {
2020-11-30 14:30:06 +01:00
ipcMain.handle('update-preferences', (_: IpcMainInvokeEvent, config: any) => {
return config
})
})
2020-11-30 14:30:06 +01:00
afterEach(() => {
ipcMain.removeHandler('update-preferences')
})
it('should be updated', async () => {
2022-04-25 15:33:49 +02:00
await store.dispatch('Preferences/General/updateSound', {
fav_rb: false,
toot: false
})
2022-04-25 15:33:49 +02:00
expect(store.state.Preferences.General.general.sound.fav_rb).toEqual(false)
expect(store.state.Preferences.General.general.sound.toot).toEqual(false)
expect(store.state.Preferences.General.loading).toEqual(false)
})
})
describe('updateTimeline', () => {
beforeEach(() => {
2020-11-30 14:30:06 +01:00
ipcMain.handle('update-preferences', (_: IpcMainInvokeEvent, config: any) => {
return config
})
})
2020-11-30 14:30:06 +01:00
afterEach(() => {
ipcMain.removeHandler('update-preferences')
})
it('should be updated', async () => {
2022-04-25 15:33:49 +02:00
await store.dispatch('Preferences/General/updateTimeline', {
cw: true,
nsfw: true,
2019-02-18 14:16:19 +01:00
hideAllAttachments: true
})
2022-04-25 15:33:49 +02:00
expect(store.state.Preferences.General.general.timeline.cw).toEqual(true)
expect(store.state.Preferences.General.general.timeline.nsfw).toEqual(true)
expect(store.state.Preferences.General.general.timeline.hideAllAttachments).toEqual(true)
expect(store.state.Preferences.General.loading).toEqual(false)
})
})
})