refs #209 Add unit/integration tests for Preferences/General
This commit is contained in:
parent
2cfbb9d2cd
commit
883b9d3e48
|
@ -39,7 +39,7 @@
|
|||
"test": "npm run unit && npm run e2e",
|
||||
"unit": "karma start test/unit/karma.conf.js",
|
||||
"postinstall": "npm run lint:fix",
|
||||
"spec:unit": "NODE_ENV=test jest -u"
|
||||
"spec": "NODE_ENV=test jest -u"
|
||||
},
|
||||
"build": {
|
||||
"productName": "Whalebird",
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
import { createLocalVue } from '@vue/test-utils'
|
||||
import Vuex from 'vuex'
|
||||
import { ipcMain } from '~/spec/mock/electron'
|
||||
import General from '@/store/Preferences/General'
|
||||
|
||||
const state = {
|
||||
general: {
|
||||
sound: {
|
||||
fav_rb: true,
|
||||
toot: true
|
||||
}
|
||||
},
|
||||
loading: false
|
||||
}
|
||||
|
||||
const Preferences = {
|
||||
namespaced: true,
|
||||
state: state,
|
||||
actions: General.actions,
|
||||
mutations: General.mutations
|
||||
}
|
||||
|
||||
describe('Preferences/General', () => {
|
||||
let store
|
||||
let localVue
|
||||
|
||||
beforeEach(() => {
|
||||
localVue = createLocalVue()
|
||||
localVue.use(Vuex)
|
||||
store = new Vuex.Store({
|
||||
modules: {
|
||||
Preferences
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('loadGeneral', () => {
|
||||
beforeEach(() => {
|
||||
ipcMain.once('get-preferences', (event, _) => {
|
||||
event.sender.send('response-get-preferences', {
|
||||
general: {
|
||||
sound: {
|
||||
fav_rb: false,
|
||||
toot: false,
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
it('should be updated', async () => {
|
||||
await store.dispatch('Preferences/loadGeneral')
|
||||
expect(store.state.Preferences.general.sound.fav_rb).toEqual(false)
|
||||
expect(store.state.Preferences.general.sound.toot).toEqual(false)
|
||||
expect(store.state.Preferences.loading).toEqual(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('updateSound', () => {
|
||||
beforeEach(() => {
|
||||
ipcMain.once('update-preferences', (event, config) => {
|
||||
event.sender.send('response-update-preferences', config)
|
||||
})
|
||||
})
|
||||
it('should be updated', async () => {
|
||||
await store.dispatch('Preferences/updateSound', {
|
||||
fav_rb: false,
|
||||
toot: false
|
||||
})
|
||||
expect(store.state.Preferences.general.sound.fav_rb).toEqual(false)
|
||||
expect(store.state.Preferences.general.sound.toot).toEqual(false)
|
||||
expect(store.state.Preferences.loading).toEqual(false)
|
||||
})
|
||||
})
|
||||
})
|
|
@ -0,0 +1,29 @@
|
|||
import General from '@/store/Preferences/General'
|
||||
|
||||
describe('Preferences/General', () => {
|
||||
let state
|
||||
beforeEach(() => {
|
||||
state = {
|
||||
general: {
|
||||
sound: {
|
||||
fav_rb: true,
|
||||
toot: true
|
||||
}
|
||||
},
|
||||
loading: false
|
||||
}
|
||||
})
|
||||
|
||||
describe('mutations', () => {
|
||||
it('updateGeneral', () => {
|
||||
General.mutations.updateGeneral(state, {
|
||||
sound: {
|
||||
fav_rb: false,
|
||||
toot: false
|
||||
}
|
||||
})
|
||||
expect(state.general.sound.fav_rb).toEqual(false)
|
||||
expect(state.general.sound.toot).toEqual(false)
|
||||
})
|
||||
})
|
||||
})
|
|
@ -46,15 +46,19 @@ const General = {
|
|||
const config = {
|
||||
general: newGeneral
|
||||
}
|
||||
ipcRenderer.send('update-preferences', config)
|
||||
ipcRenderer.once('error-update-preferences', (event, err) => {
|
||||
ipcRenderer.removeAllListeners('response-update-preferences')
|
||||
commit('changeLoading', false)
|
||||
})
|
||||
ipcRenderer.once('response-update-preferences', (event, conf) => {
|
||||
ipcRenderer.removeAllListeners('error-update-preferences')
|
||||
commit('updateGeneral', conf.general)
|
||||
commit('changeLoading', false)
|
||||
return new Promise((resolve, reject) => {
|
||||
ipcRenderer.send('update-preferences', config)
|
||||
ipcRenderer.once('error-update-preferences', (event, err) => {
|
||||
ipcRenderer.removeAllListeners('response-update-preferences')
|
||||
commit('changeLoading', false)
|
||||
reject(err)
|
||||
})
|
||||
ipcRenderer.once('response-update-preferences', (event, conf) => {
|
||||
ipcRenderer.removeAllListeners('error-update-preferences')
|
||||
commit('updateGeneral', conf.general)
|
||||
commit('changeLoading', false)
|
||||
resolve(conf)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue