diff --git a/test/unit/app/browser/reducers/siteSettingsReducerTest.js b/test/unit/app/browser/reducers/siteSettingsReducerTest.js new file mode 100644 index 00000000000..72fc2a6f5c3 --- /dev/null +++ b/test/unit/app/browser/reducers/siteSettingsReducerTest.js @@ -0,0 +1,83 @@ +/* global describe, it, before, after */ +const mockery = require('mockery') +const sinon = require('sinon') +const Immutable = require('immutable') +const assert = require('assert') +const fakeElectron = require('../../../lib/fakeElectron') + +const appConstants = require('../../../../../js/constants/appConstants') +require('../../../braveUnit') + +describe('siteSettingsReducer unit tests', function () { + let siteSettingsReducer + let siteSettings + + before(function () { + mockery.enable({ + warnOnReplace: false, + warnOnUnregistered: false, + useCleanCache: true + }) + + mockery.registerMock('electron', fakeElectron) + siteSettings = require('../../../../../js/state/siteSettings') + mockery.registerMock('../../../js/state/siteSettings', siteSettings) + + siteSettingsReducer = require('../../../../../app/browser/reducers/siteSettingsReducer') + }) + + after(function () { + mockery.disable() + }) + + describe('APP_ALLOW_FLASH_ONCE', function () { + let fakeAppState + let mergeSiteSettingSpy + + before(function () { + mergeSiteSettingSpy = sinon.spy(siteSettings, 'mergeSiteSetting') + fakeAppState = Immutable.fromJS({ + siteSettings: { + regularTabSetting: '' + }, + temporarySiteSettings: { + privateTabSetting: '' + } + }) + }) + after(function () { + mergeSiteSettingSpy.restore() + }) + it('merges setting into siteSettings if regular tab', function () { + siteSettingsReducer(fakeAppState, Immutable.fromJS({ + actionType: appConstants.APP_ALLOW_FLASH_ONCE, + isPrivate: false, + url: 'https://example.com/test/page.html' + })) + assert(mergeSiteSettingSpy.withArgs(fakeAppState.get('siteSettings'), 'https://example.com', 'flash', 1).calledOnce) + }) + it('merges setting into siteSettings if private tab', function () { + siteSettingsReducer(fakeAppState, Immutable.fromJS({ + actionType: appConstants.APP_ALLOW_FLASH_ONCE, + isPrivate: true, + url: 'https://example.com/test/page.html' + })) + assert(mergeSiteSettingSpy.withArgs(fakeAppState.get('temporarySiteSettings'), 'https://example.com', 'flash', 1).calledOnce) + }) + }) + + describe('APP_ALLOW_FLASH_ALWAYS', function () { + }) + + describe('APP_CHANGE_SITE_SETTING', function () { + }) + + describe('APP_REMOVE_SITE_SETTING', function () { + }) + + describe('APP_CLEAR_SITE_SETTINGS', function () { + }) + + describe('APP_ADD_NOSCRIPT_EXCEPTIONS', function () { + }) +})