2018-12-30 08:56:38 +01:00
|
|
|
import { createLocalVue } from '@vue/test-utils'
|
|
|
|
import Vuex from 'vuex'
|
|
|
|
import { ipcMain } from '~/spec/mock/electron'
|
2019-04-06 15:08:29 +02:00
|
|
|
import Notification, { NotificationState } from '@/store/Preferences/Notification'
|
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,
|
|
|
|
follow: true
|
|
|
|
}
|
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(() => {
|
2019-03-28 15:35:25 +01:00
|
|
|
ipcMain.once('get-preferences', (event: any, _) => {
|
2018-12-30 08:56:38 +01:00
|
|
|
event.sender.send('response-get-preferences', {
|
|
|
|
notification: {
|
|
|
|
notify: {
|
|
|
|
reply: false,
|
|
|
|
reblog: false,
|
|
|
|
favourite: false,
|
|
|
|
follow: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
it('should be updated', async () => {
|
|
|
|
await store.dispatch('Notification/loadNotification')
|
|
|
|
expect(store.state.Notification.notification).toEqual({
|
|
|
|
notify: {
|
|
|
|
reply: false,
|
|
|
|
reblog: false,
|
|
|
|
favourite: false,
|
|
|
|
follow: false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('updateNotify', () => {
|
|
|
|
beforeEach(() => {
|
2019-03-28 15:35:25 +01:00
|
|
|
ipcMain.once('update-preferences', (event: any, conf: object) => {
|
2018-12-30 08:56:38 +01:00
|
|
|
event.sender.send('response-update-preferences', conf)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
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,
|
|
|
|
follow: true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
expect(App.actions.loadPreferences).toBeCalled()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|