|
| 1 | +import { expect } from 'chai'; |
| 2 | +import * as actions from '../../actions'; |
| 3 | +import settingsMiddleware from '../../middleware/settings'; |
| 4 | +const ipcRenderer = window.require('electron').ipcRenderer; |
| 5 | + |
| 6 | +const createFakeStore = fakeData => ({ |
| 7 | + getState() { |
| 8 | + return { |
| 9 | + notifications: {}, |
| 10 | + settings: { |
| 11 | + openAtStartup: false, |
| 12 | + playSound: false, |
| 13 | + showNotifications: false |
| 14 | + } |
| 15 | + }; |
| 16 | + } |
| 17 | +}); |
| 18 | + |
| 19 | +const dispatchWithStoreOf = (storeData, action) => { |
| 20 | + let dispatched = null; |
| 21 | + const dispatch = settingsMiddleware(createFakeStore(storeData))(actionAttempt => dispatched = actionAttempt); |
| 22 | + dispatch(action); |
| 23 | + return dispatched; |
| 24 | +}; |
| 25 | + |
| 26 | +describe('middleware/settings.js', () => { |
| 27 | + |
| 28 | + beforeEach(function() { |
| 29 | + ipcRenderer.send.reset(); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should mark auto-launch setting to true (enable)', () => { |
| 33 | + |
| 34 | + const action = { |
| 35 | + type: actions.UPDATE_SETTING, |
| 36 | + setting: 'openAtStartup', |
| 37 | + value: true |
| 38 | + }; |
| 39 | + |
| 40 | + expect(dispatchWithStoreOf({}, action)).to.eql(action); |
| 41 | + |
| 42 | + expect(ipcRenderer.send).to.have.been.calledOnce; |
| 43 | + expect(ipcRenderer.send).to.have.been.calledWith('startup-enable'); |
| 44 | + |
| 45 | + }); |
| 46 | + |
| 47 | + it('should mark auto-launch setting to false (disable)', () => { |
| 48 | + |
| 49 | + const action = { |
| 50 | + type: actions.UPDATE_SETTING, |
| 51 | + setting: 'openAtStartup', |
| 52 | + value: false |
| 53 | + }; |
| 54 | + |
| 55 | + expect(dispatchWithStoreOf({}, action)).to.eql(action); |
| 56 | + |
| 57 | + expect(ipcRenderer.send).to.have.been.calledOnce; |
| 58 | + expect(ipcRenderer.send).to.have.been.calledWith('startup-disable'); |
| 59 | + |
| 60 | + }); |
| 61 | +}); |
0 commit comments