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

128 lines
3.2 KiB
TypeScript
Raw Normal View History

import { createLocalVue } from '@vue/test-utils'
import Vuex 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'
2020-04-11 11:22:49 +02:00
;((window as any) as MyWindow).ipcRenderer = ipcRenderer
const state = (): GeneralState => {
return {
general: {
sound: {
fav_rb: true,
toot: true
},
timeline: {
cw: false,
nsfw: false,
2021-06-10 18:07:41 +02:00
hideAllAttachments: false,
useMarkerTimeline: []
},
other: {
launch: false
}
},
loading: false
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: General.actions,
mutations: General.mutations
}
}
const app = {
namespaced: true,
actions: {
loadPreferences(_) {
return true
}
}
}
describe('Preferences/General', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Preferences: initStore(),
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 () => {
await store.dispatch('Preferences/loadGeneral')
expect(store.state.Preferences.general.sound.fav_rb).toEqual(false)
expect(store.state.Preferences.general.sound.toot).toEqual(false)
expect(store.state.Preferences.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 () => {
await store.dispatch('Preferences/updateSound', {
fav_rb: false,
toot: false
})
expect(store.state.Preferences.general.sound.fav_rb).toEqual(false)
expect(store.state.Preferences.general.sound.toot).toEqual(false)
expect(store.state.Preferences.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 () => {
await store.dispatch('Preferences/updateTimeline', {
cw: true,
nsfw: true,
2019-02-18 14:16:19 +01:00
hideAllAttachments: true
})
expect(store.state.Preferences.general.timeline.cw).toEqual(true)
expect(store.state.Preferences.general.timeline.nsfw).toEqual(true)
2019-02-18 14:16:19 +01:00
expect(store.state.Preferences.general.timeline.hideAllAttachments).toEqual(true)
expect(store.state.Preferences.loading).toEqual(false)
})
})
})