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

133 lines
3.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 Notification, { NotificationState } from '@/store/Preferences/Notification'
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 = (): NotificationState => {
return {
notification: {
notify: {
reply: true,
reblog: true,
favourite: true,
follow: true,
follow_request: true,
reaction: true,
status: true,
poll_vote: true,
poll_expired: true
}
}
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: Notification.actions,
mutations: Notification.mutations
}
}
2022-04-25 15:33:49 +02:00
const preferencesStore = () => ({
namespaced: true,
modules: {
Notification: initStore()
}
})
const App = {
namespaced: true,
actions: {
loadPreferences: jest.fn()
}
}
describe('Preferences/Notification', () => {
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('loadNotification', () => {
beforeEach(() => {
2020-11-30 14:30:06 +01:00
ipcMain.handle('get-preferences', () => {
return {
notification: {
notify: {
reply: false,
reblog: false,
favourite: false,
follow: false,
follow_request: false,
reaction: false,
2021-03-21 13:40:40 +01:00
status: false,
poll_vote: false,
poll_expired: false
}
}
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/Notification/loadNotification')
expect(store.state.Preferences.Notification.notification).toEqual({
notify: {
reply: false,
reblog: false,
favourite: false,
follow: false,
follow_request: false,
reaction: false,
2021-03-21 13:40:40 +01:00
status: false,
poll_vote: false,
poll_expired: false
}
})
})
})
})
describe('updateNotify', () => {
beforeEach(() => {
2020-11-30 14:30:06 +01:00
ipcMain.handle('update-preferences', (_, conf: object) => {
return conf
})
})
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/Notification/updateNotify', {
reply: false,
reblog: false
})
2022-04-25 15:33:49 +02:00
expect(store.state.Preferences.Notification.notification).toEqual({
notify: {
reply: false,
reblog: false,
favourite: true,
follow: true,
follow_request: true,
reaction: true,
2021-03-21 13:40:40 +01:00
status: true,
poll_vote: true,
poll_expired: true
}
})
expect(App.actions.loadPreferences).toBeCalled()
})
})
})