refs #209 Add unit/integration tests for Preferences/Notification

This commit is contained in:
AkiraFukushima 2018-12-30 16:56:38 +09:00
parent bad672c275
commit 5380cf12ab
5 changed files with 140 additions and 6 deletions

View File

@ -25,4 +25,4 @@ jobs:
- node_modules
- run:
name: spec
command: npm run spec:unit
command: npm run spec

View File

@ -41,7 +41,7 @@ describe('Preferences/General', () => {
general: {
sound: {
fav_rb: false,
toot: false,
toot: false
}
}
})

View File

@ -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()
})
})
})

View File

@ -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
})
})
})
})

View File

@ -40,10 +40,13 @@ export default {
const config = {
notification: newNotification
}
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('response-update-preferences', (event, conf) => {
commit('updateNotification', conf.notification)
dispatch('App/loadPreferences', null, { root: true })
return new Promise((resolve, reject) => {
ipcRenderer.send('update-preferences', config)
ipcRenderer.once('response-update-preferences', (event, conf) => {
commit('updateNotification', conf.notification)
dispatch('App/loadPreferences', null, { root: true })
resolve(conf.notification)
})
})
}
}