declare const global: any import { expect } from 'chai' import settings from '../../../js/modules/settings/reducer' import * as settingsActions from '../../../js/modules/settings/actions' import { Settings } from '../../../js/modules/settings/interfaces' const createBaseState = (opts?: any): Settings => ({ bccEmailAddress: '', bccStatus: false, inboxesToRunExtensionOn: {}, notificationSentMessage: true, notificationVisitedSite: true, notificationClickedEmailLink: true, notificationOpenedEmail: true, notificationMuteList: [], domainMuteList: [], ...opts, }) describe('reducers', () => { before(() => { global.chrome = chrome }) describe('settings', () => { it('should provide the initial state', () => { expect(settings(undefined, { type: 'unknown' })).to.deep.equal({ bccEmailAddress: '', bccStatus: false, inboxesToRunExtensionOn: {}, notificationSentMessage: true, notificationVisitedSite: true, notificationClickedEmailLink: true, notificationOpenedEmail: true, notificationMuteList: [], domainMuteList: [], }) }) it('should handle setSettingStatus', () => { expect(settings(undefined, settingsActions.setSettingStatus({ notificationSentMessage: false }))).to.deep.equal( createBaseState({ notificationSentMessage: false }) ) expect(settings(undefined, settingsActions.setSettingStatus({ notificationVisitedSite: false }))).to.deep.equal( createBaseState({ notificationVisitedSite: false }) ) expect(settings(undefined, settingsActions.setSettingStatus({ notificationClickedEmailLink: false }))).to.deep.equal( createBaseState({ notificationClickedEmailLink: false }) ) expect(settings(undefined, settingsActions.setSettingStatus({ notificationOpenedEmail: false }))).to.deep.equal( createBaseState({ notificationOpenedEmail: false }) ) expect(settings(undefined, settingsActions.setSettingStatus({ bccEmailAddress: 'test@drift.com' }))).to.deep.equal( createBaseState({ bccEmailAddress: 'test@drift.com' }) ) expect(settings(undefined, settingsActions.setSettingStatus({ bccStatus: true }))).to.deep.equal( createBaseState({ bccStatus: true }) ) }) it('should add the email if it does not exist', () => { expect(settings(undefined, settingsActions.addEmailToMuteList('test@drift.com'))).to.deep.equal( createBaseState({ notificationMuteList: ['test@drift.com'] }) ) expect( settings( createBaseState({ notificationMuteList: ['test1@drift.com'] }), settingsActions.addEmailToMuteList('test2@drift.com') ) ).to.deep.equal({ bccEmailAddress: '', bccStatus: false, inboxesToRunExtensionOn: {}, notificationSentMessage: true, notificationVisitedSite: true, notificationClickedEmailLink: true, notificationOpenedEmail: true, notificationMuteList: ['test1@drift.com', 'test2@drift.com'], domainMuteList: [], }) }) it('should remove the email if it does exist', () => { expect( settings( createBaseState({ notificationMuteList: ['test@drift.com'] }), settingsActions.removeEmailFromMuteList('test@drift.com') ) ).to.deep.equal({ bccEmailAddress: '', bccStatus: false, inboxesToRunExtensionOn: {}, notificationSentMessage: true, notificationVisitedSite: true, notificationClickedEmailLink: true, notificationOpenedEmail: true, notificationMuteList: [], domainMuteList: [], }) expect( settings( createBaseState({ notificationMuteList: ['test1@drift.com', 'test2@drift.com'] }), settingsActions.removeEmailFromMuteList('test1@drift.com') ) ).to.deep.equal({ bccEmailAddress: '', bccStatus: false, inboxesToRunExtensionOn: {}, notificationSentMessage: true, notificationVisitedSite: true, notificationClickedEmailLink: true, notificationOpenedEmail: true, notificationMuteList: ['test2@drift.com'], domainMuteList: [], }) }) it('should set the inbox settings correctly', () => { expect(settings(createBaseState({}), settingsActions.setInboxesToRunExtensionOn({ 'test@drift.com': true }))).to.deep.equal({ bccEmailAddress: '', bccStatus: false, inboxesToRunExtensionOn: { 'test@drift.com': true }, notificationSentMessage: true, notificationVisitedSite: true, notificationClickedEmailLink: true, notificationOpenedEmail: true, notificationMuteList: [], domainMuteList: [], }) expect( settings( createBaseState({ inboxesToRunExtensionOn: { 'test@drift.com': true } }), settingsActions.setInboxesToRunExtensionOn({ 'test@drift.com': false }) ) ).to.deep.equal({ bccEmailAddress: '', bccStatus: false, inboxesToRunExtensionOn: { 'test@drift.com': false }, notificationSentMessage: true, notificationVisitedSite: true, notificationClickedEmailLink: true, notificationOpenedEmail: true, notificationMuteList: [], domainMuteList: [], }) }) }) })