refs #209 Add unit/integration tests for Preferences/Notification
This commit is contained in:
parent
bad672c275
commit
5380cf12ab
|
@ -25,4 +25,4 @@ jobs:
|
||||||
- node_modules
|
- node_modules
|
||||||
- run:
|
- run:
|
||||||
name: spec
|
name: spec
|
||||||
command: npm run spec:unit
|
command: npm run spec
|
||||||
|
|
|
@ -41,7 +41,7 @@ describe('Preferences/General', () => {
|
||||||
general: {
|
general: {
|
||||||
sound: {
|
sound: {
|
||||||
fav_rb: false,
|
fav_rb: false,
|
||||||
toot: false,
|
toot: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -0,0 +1,96 @@
|
||||||
|
import { createLocalVue } from '@vue/test-utils'
|
||||||
|
import Vuex from 'vuex'
|
||||||
|
import { ipcMain } from '~/spec/mock/electron'
|
||||||
|
import Notification from '@/store/Preferences/Notification'
|
||||||
|
|
||||||
|
const state = {
|
||||||
|
notification: {
|
||||||
|
notify: {
|
||||||
|
reply: true,
|
||||||
|
reblog: true,
|
||||||
|
favourite: true,
|
||||||
|
follow: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const initState = {
|
||||||
|
namespaced: true,
|
||||||
|
state: state,
|
||||||
|
actions: Notification.actions,
|
||||||
|
mutations: Notification.mutations
|
||||||
|
}
|
||||||
|
|
||||||
|
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: {
|
||||||
|
Notification: initState,
|
||||||
|
App: App
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('loadNotification', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
ipcMain.once('get-preferences', (event, _) => {
|
||||||
|
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(() => {
|
||||||
|
ipcMain.once('update-preferences', (event, conf) => {
|
||||||
|
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()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
|
@ -0,0 +1,35 @@
|
||||||
|
import Notification from '@/store/Preferences/Notification'
|
||||||
|
|
||||||
|
describe('Preferences/Notification', () => {
|
||||||
|
let state
|
||||||
|
beforeEach(() => {
|
||||||
|
state = {
|
||||||
|
notification: {
|
||||||
|
notify: {
|
||||||
|
reply: true,
|
||||||
|
reblog: true,
|
||||||
|
favourite: true,
|
||||||
|
follow: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
describe('mutations', () => {
|
||||||
|
it('updateNotification', () => {
|
||||||
|
Notification.mutations.updateNotification(state, {
|
||||||
|
notify: {
|
||||||
|
reply: false,
|
||||||
|
reblog: false,
|
||||||
|
favourite: false,
|
||||||
|
follow: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
expect(state.notification.notify).toEqual({
|
||||||
|
reply: false,
|
||||||
|
reblog: false,
|
||||||
|
favourite: false,
|
||||||
|
follow: false
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
|
@ -40,10 +40,13 @@ export default {
|
||||||
const config = {
|
const config = {
|
||||||
notification: newNotification
|
notification: newNotification
|
||||||
}
|
}
|
||||||
ipcRenderer.send('update-preferences', config)
|
return new Promise((resolve, reject) => {
|
||||||
ipcRenderer.once('response-update-preferences', (event, conf) => {
|
ipcRenderer.send('update-preferences', config)
|
||||||
commit('updateNotification', conf.notification)
|
ipcRenderer.once('response-update-preferences', (event, conf) => {
|
||||||
dispatch('App/loadPreferences', null, { root: true })
|
commit('updateNotification', conf.notification)
|
||||||
|
dispatch('App/loadPreferences', null, { root: true })
|
||||||
|
resolve(conf.notification)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue