This repository has been archived by the owner on Jun 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6816ee4
commit 5a43f95
Showing
3 changed files
with
107 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
test/app/components/braveShields/privacyControlsTest.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* global describe, it */ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import 'mocha' | ||
import * as React from 'react' | ||
import * as assert from 'assert' | ||
import ShieldsPrivacyControls, { Props } from '../../../../app/components/braveShields/privacyControls' | ||
import { BlockJSOptions, BlockCookiesOptions, BlockFPOptions } from '../../../../app/types/other/blockTypes' | ||
import * as actionTypes from '../../../../app/constants/shieldsPanelTypes' | ||
import { shallow } from 'enzyme' | ||
import * as sinon from 'sinon' | ||
|
||
const fakeProps: Props = { | ||
url: 'https://brave.com/jobs', | ||
hostname: 'brave.com', | ||
origin: 'https://brave.com', | ||
braveShields: 'allow', | ||
javascript: 'block', | ||
javascriptBlocked: 0, | ||
blockJavaScript: (setting: BlockJSOptions) => ({ type: actionTypes.JAVASCRIPT_TOGGLED, setting }), | ||
javascriptBlockedResources: [], | ||
noScriptInfo: {}, | ||
allowScriptOriginsOnce: (origins: Array<string>) => ({ type: actionTypes.ALLOW_SCRIPT_ORIGINS_ONCE, origins }), | ||
changeNoScriptSettings: (origin: string) => ({ type: actionTypes.CHANGE_NO_SCRIPT_SETTINGS, origin }), | ||
changeAllNoScriptSettings: (origin: string, shouldBlock: boolean) => ({ type: actionTypes.CHANGE_ALL_NO_SCRIPT_SETTINGS, origin, shouldBlock }), | ||
fingerprinting: 'block', | ||
fingerprintingBlocked: 0, | ||
blockFingerprinting: (setting: BlockFPOptions) => ({ type: actionTypes.BLOCK_FINGERPRINTING, setting }), | ||
fingerprintingBlockedResources: [], | ||
cookies: 'block', | ||
blockCookies: (setting: BlockCookiesOptions) => ({ type: actionTypes.BLOCK_COOKIES, setting }) | ||
} | ||
|
||
describe('PrivacyControls component', () => { | ||
const baseComponent = (props: Props) => | ||
<ShieldsPrivacyControls {...props} /> | ||
|
||
it('renders the component', () => { | ||
const wrapper = shallow(baseComponent(fakeProps)) | ||
const assertion = wrapper.find('#braveShieldsPrivacyControls').length === 1 | ||
assert.equal(assertion, true) | ||
}) | ||
|
||
describe('cookie control', () => { | ||
it('responds to the onChange event', () => { | ||
const value = { target: { value: true } } | ||
const onChangeCookiesControlSelectOptions = sinon.spy() | ||
const newProps = Object.assign(fakeProps, { | ||
blockCookies: onChangeCookiesControlSelectOptions | ||
}) | ||
|
||
const wrapper = shallow(baseComponent(newProps)) | ||
wrapper.find('#blockCookies').simulate('change', value) | ||
assert.equal(onChangeCookiesControlSelectOptions.calledOnce, true) | ||
}) | ||
}) | ||
|
||
describe('scripts control', () => { | ||
it('responds to the onChange event', () => { | ||
const value = { target: { value: true } } | ||
const onChangeScriptControlSelectOptions = sinon.spy() | ||
const newProps = Object.assign(fakeProps, { | ||
blockJavaScript: onChangeScriptControlSelectOptions | ||
}) | ||
|
||
const wrapper = shallow(baseComponent(newProps)) | ||
wrapper.find('#blockScripts').simulate('change', value) | ||
assert.equal(onChangeScriptControlSelectOptions.calledOnce, true) | ||
}) | ||
|
||
it('shows number of scripts blocked', () => { | ||
const newProps = Object.assign(fakeProps, { javascriptBlocked: 1337 }) | ||
const wrapper = shallow(baseComponent(newProps)) | ||
const assertion = wrapper.find('#blockScriptsStat').props().children | ||
assert.equal(assertion, 1337) | ||
}) | ||
}) | ||
|
||
describe('fingerprinting control', () => { | ||
it('responds to the onChange event', () => { | ||
const value = { target: { value: true } } | ||
const onChangeFingerprintingProtectionSelectOptions = sinon.spy() | ||
const newProps = Object.assign(fakeProps, { | ||
blockFingerprinting: onChangeFingerprintingProtectionSelectOptions | ||
}) | ||
|
||
const wrapper = shallow(baseComponent(newProps)) | ||
wrapper.find('#blockFingerprinting').simulate('change', value) | ||
assert.equal(onChangeFingerprintingProtectionSelectOptions.calledOnce, true) | ||
}) | ||
|
||
it('shows number of fingerprinting attempts blocked', () => { | ||
const newProps = Object.assign(fakeProps, { fingerprintingBlocked: 1337 }) | ||
const wrapper = shallow(baseComponent(newProps)) | ||
const assertion = wrapper.find('#blockFingerprintingStat').props().children | ||
assert.equal(assertion, 1337) | ||
}) | ||
}) | ||
}) |