diff --git a/package.json b/package.json index 9f4dfc22..40322aa0 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/spec/integration/store/Preferences/General.spec.js b/spec/integration/store/Preferences/General.spec.js new file mode 100644 index 00000000..fa4e8e20 --- /dev/null +++ b/spec/integration/store/Preferences/General.spec.js @@ -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) + }) + }) +}) diff --git a/spec/unit/store/Preferences/General.spec.js b/spec/unit/store/Preferences/General.spec.js new file mode 100644 index 00000000..cd0bbc24 --- /dev/null +++ b/spec/unit/store/Preferences/General.spec.js @@ -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) + }) + }) +}) diff --git a/src/renderer/store/Preferences/General.js b/src/renderer/store/Preferences/General.js index 92e7f423..56cf8ac5 100644 --- a/src/renderer/store/Preferences/General.js +++ b/src/renderer/store/Preferences/General.js @@ -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) + }) }) } }