2018-12-30 08:56:38 +01:00
|
|
|
import { createLocalVue } from '@vue/test-utils'
|
|
|
|
import Vuex 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'
|
2020-04-11 11:22:49 +02:00
|
|
|
;((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
|
|
|
}
|
|
|
|
|
|
|
|
const App = {
|
|
|
|
namespaced: true,
|
|
|
|
actions: {
|
|
|
|
loadPreferences: jest.fn()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Preferences/Notification', () => {
|
|
|
|
let store
|
|
|
|
let localVue
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
localVue = createLocalVue()
|
|
|
|
localVue.use(Vuex)
|
|
|
|
store = new Vuex.Store({
|
|
|
|
modules: {
|
2019-02-16 11:41:58 +01:00
|
|
|
Notification: initStore(),
|
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 () => {
|
|
|
|
await store.dispatch('Notification/loadNotification')
|
|
|
|
expect(store.state.Notification.notification).toEqual({
|
|
|
|
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 () => {
|
|
|
|
await store.dispatch('Notification/updateNotify', {
|
|
|
|
reply: false,
|
|
|
|
reblog: false
|
|
|
|
})
|
|
|
|
expect(store.state.Notification.notification).toEqual({
|
|
|
|
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()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|