diff --git a/.circleci/config.yml b/.circleci/config.yml index 55cc62df..30c3029b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -25,4 +25,4 @@ jobs: - node_modules - run: name: spec - command: npm run spec:unit + command: npm run spec diff --git a/spec/integration/store/Preferences/General.spec.js b/spec/integration/store/Preferences/General.spec.js index fa4e8e20..2ed26472 100644 --- a/spec/integration/store/Preferences/General.spec.js +++ b/spec/integration/store/Preferences/General.spec.js @@ -41,7 +41,7 @@ describe('Preferences/General', () => { general: { sound: { fav_rb: false, - toot: false, + toot: false } } }) diff --git a/spec/integration/store/Preferences/Notification.spec.js b/spec/integration/store/Preferences/Notification.spec.js new file mode 100644 index 00000000..860e5efd --- /dev/null +++ b/spec/integration/store/Preferences/Notification.spec.js @@ -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() + }) + }) +}) diff --git a/spec/unit/store/Preferences/Notification.spec.js b/spec/unit/store/Preferences/Notification.spec.js new file mode 100644 index 00000000..49376cd2 --- /dev/null +++ b/spec/unit/store/Preferences/Notification.spec.js @@ -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 + }) + }) + }) +}) diff --git a/src/renderer/store/Preferences/Notification.js b/src/renderer/store/Preferences/Notification.js index 836e8e5b..2d90d1a3 100644 --- a/src/renderer/store/Preferences/Notification.js +++ b/src/renderer/store/Preferences/Notification.js @@ -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) + }) }) } }