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