2022-04-25 15:33:49 +02:00
|
|
|
import { createStore, Store } from 'vuex'
|
2019-12-04 14:35:53 +01:00
|
|
|
import { ipcMain, ipcRenderer } from '~/spec/mock/electron'
|
2019-04-06 15:08:29 +02:00
|
|
|
import Notification, { NotificationState } from '@/store/Preferences/Notification'
|
2019-12-04 14:35:53 +01:00
|
|
|
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
|
2018-12-30 08:56:38 +01:00
|
|
|
|
2019-04-06 15:08:29 +02:00
|
|
|
const state = (): NotificationState => {
|
2019-02-16 11:41:58 +01:00
|
|
|
return {
|
|
|
|
notification: {
|
|
|
|
notify: {
|
|
|
|
reply: true,
|
|
|
|
reblog: true,
|
|
|
|
favourite: true,
|
2020-04-25 14:25:28 +02:00
|
|
|
follow: true,
|
2020-05-23 16:21:33 +02:00
|
|
|
follow_request: true,
|
2021-03-02 03:28:03 +01:00
|
|
|
reaction: true,
|
2021-03-21 13:27:47 +01:00
|
|
|
status: true,
|
2021-03-23 17:28:10 +01:00
|
|
|
poll_vote: true,
|
|
|
|
poll_expired: true
|
2019-02-16 11:41:58 +01:00
|
|
|
}
|
2018-12-30 08:56:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-16 11:41:58 +01:00
|
|
|
const initStore = () => {
|
|
|
|
return {
|
|
|
|
namespaced: true,
|
|
|
|
state: state(),
|
|
|
|
actions: Notification.actions,
|
|
|
|
mutations: Notification.mutations
|
|
|
|
}
|
2018-12-30 08:56:38 +01:00
|
|
|
}
|
|
|
|
|
2022-04-25 15:33:49 +02:00
|
|
|
const preferencesStore = () => ({
|
|
|
|
namespaced: true,
|
|
|
|
modules: {
|
|
|
|
Notification: initStore()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-12-30 08:56:38 +01:00
|
|
|
const App = {
|
|
|
|
namespaced: true,
|
|
|
|
actions: {
|
|
|
|
loadPreferences: jest.fn()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Preferences/Notification', () => {
|
2022-04-25 15:33:49 +02:00
|
|
|
let store: Store<RootState>
|
2018-12-30 08:56:38 +01:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-04-25 15:33:49 +02:00
|
|
|
store = createStore({
|
2018-12-30 08:56:38 +01:00
|
|
|
modules: {
|
2022-04-25 15:33:49 +02:00
|
|
|
Preferences: preferencesStore(),
|
2018-12-30 08:56:38 +01:00
|
|
|
App: App
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('loadNotification', () => {
|
|
|
|
beforeEach(() => {
|
2020-11-30 14:30:06 +01:00
|
|
|
ipcMain.handle('get-preferences', () => {
|
|
|
|
return {
|
2018-12-30 08:56:38 +01:00
|
|
|
notification: {
|
|
|
|
notify: {
|
|
|
|
reply: false,
|
|
|
|
reblog: false,
|
|
|
|
favourite: false,
|
2020-04-25 14:38:23 +02:00
|
|
|
follow: false,
|
2020-05-23 16:21:33 +02:00
|
|
|
follow_request: false,
|
2021-03-02 03:28:03 +01:00
|
|
|
reaction: false,
|
2021-03-21 13:40:40 +01:00
|
|
|
status: false,
|
2021-03-23 17:28:10 +01:00
|
|
|
poll_vote: false,
|
|
|
|
poll_expired: false
|
2018-12-30 08:56:38 +01:00
|
|
|
}
|
|
|
|
}
|
2020-11-30 14:30:06 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
afterEach(() => {
|
|
|
|
ipcMain.removeHandler('get-preferences')
|
2018-12-30 08:56:38 +01:00
|
|
|
})
|
|
|
|
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({
|
2018-12-30 08:56:38 +01:00
|
|
|
notify: {
|
|
|
|
reply: false,
|
|
|
|
reblog: false,
|
|
|
|
favourite: false,
|
2020-04-25 14:38:23 +02:00
|
|
|
follow: false,
|
2020-05-23 16:21:33 +02:00
|
|
|
follow_request: false,
|
2021-03-02 03:28:03 +01:00
|
|
|
reaction: false,
|
2021-03-21 13:40:40 +01:00
|
|
|
status: false,
|
2021-03-23 17:28:10 +01:00
|
|
|
poll_vote: false,
|
|
|
|
poll_expired: false
|
2018-12-30 08:56:38 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('updateNotify', () => {
|
|
|
|
beforeEach(() => {
|
2020-11-30 14:30:06 +01:00
|
|
|
ipcMain.handle('update-preferences', (_, conf: object) => {
|
|
|
|
return conf
|
2018-12-30 08:56:38 +01:00
|
|
|
})
|
|
|
|
})
|
2020-11-30 14:30:06 +01:00
|
|
|
afterEach(() => {
|
|
|
|
ipcMain.removeHandler('update-preferences')
|
|
|
|
})
|
2018-12-30 08:56:38 +01:00
|
|
|
it('should be updated', async () => {
|
2022-04-25 15:33:49 +02:00
|
|
|
await store.dispatch('Preferences/Notification/updateNotify', {
|
2018-12-30 08:56:38 +01:00
|
|
|
reply: false,
|
|
|
|
reblog: false
|
|
|
|
})
|
2022-04-25 15:33:49 +02:00
|
|
|
expect(store.state.Preferences.Notification.notification).toEqual({
|
2018-12-30 08:56:38 +01:00
|
|
|
notify: {
|
|
|
|
reply: false,
|
|
|
|
reblog: false,
|
|
|
|
favourite: true,
|
2020-04-25 14:38:23 +02:00
|
|
|
follow: true,
|
2020-05-23 16:21:33 +02:00
|
|
|
follow_request: true,
|
2021-03-02 03:28:03 +01:00
|
|
|
reaction: true,
|
2021-03-21 13:40:40 +01:00
|
|
|
status: true,
|
2021-03-23 17:28:10 +01:00
|
|
|
poll_vote: true,
|
|
|
|
poll_expired: true
|
2018-12-30 08:56:38 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
expect(App.actions.loadPreferences).toBeCalled()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|