Skip to content
This repository has been archived by the owner on Jun 6, 2019. It is now read-only.

Commit

Permalink
add header test
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Oct 29, 2018
1 parent af56787 commit afb6950
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/components/braveShields/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default class ShieldsHeader extends React.PureComponent<Props, {}> {
<SiteInfoCard>
<MainSiteInfoGrid>
<img src={getFavicon(url)} />
<Label size='large'>{hostname}</Label>
<Label id='hostname' size='large'>{hostname}</Label>
</MainSiteInfoGrid>
{enabled ? this.renderEnabledContent() : this.renderDisabledContent()}
</SiteInfoCard>
Expand Down
95 changes: 95 additions & 0 deletions test/app/components/braveShields/headerTest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/* 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 ShieldsHeader, { Props } from '../../../../app/components/braveShields/header'
import { BlockOptions } from '../../../../app/types/other/blockTypes'
import * as actionTypes from '../../../../app/constants/shieldsPanelTypes'
import { shallow } from 'enzyme'
import * as sinon from 'sinon'

const fakeProps: Props = {
tabData: {
hostname: 'brave.com',
origin: 'https://brave.com',
url: 'https://brave.com',
braveShields: 'allow',
adsBlocked: 0,
ads: 'block',
adsBlockedResources: [],
httpsRedirected: 0,
httpUpgradableResources: 'block',
httpsRedirectedResources: [],
id: 0,
javascript: 'block',
javascriptBlocked: 0,
javascriptBlockedResources: [],
trackers: 'block',
trackersBlocked: 0,
trackersBlockedResources: [],
fingerprinting: 'block',
fingerprintingBlocked: 0,
fingerprintingBlockedResources: [],
cookies: 'block',
noScriptInfo: {},
controlsOpen: false
},
shieldsToggled: (setting: BlockOptions) => {
return { type: actionTypes.SHIELDS_TOGGLED, setting }
},
}

describe('ShieldsHeader component', () => {
const baseComponent = (props: Props) =>
<ShieldsHeader {...props} />

it('renders the component', () => {
const wrapper = shallow(baseComponent(fakeProps))
const assertion = wrapper.find('#braveShieldsHeader').length === 1
assert.equal(assertion, true)
})

it('shields toggle responds to the onChange event', () => {
const value = { target: { checked: true } }
const onToggleShields = sinon.spy()
const newProps = Object.assign(fakeProps, {
shieldsToggled: onToggleShields
})
const wrapper = shallow(baseComponent(newProps))
wrapper.find('#mainToggle').simulate('change', value)
assert.equal(onToggleShields.calledOnce, true)
})

it('can toggle shields off', () => {
const newProps = Object.assign(fakeProps, { tabData: { braveShields: 'block' } })
const wrapper = shallow(baseComponent(newProps))
const assertion = wrapper.find('#mainToggle').prop('checked')
assert.equal(assertion, false)
})

it('can toggle shields on', () => {
// start with shields off
const newProps1 = Object.assign(fakeProps, { tabData: { braveShields: 'block' } })
const wrapper = shallow(baseComponent(newProps1))
const assertion1 = wrapper.find('#mainToggle').prop('checked')
assert.equal(assertion1, false)
// then turn it on
const newProps2 = Object.assign(fakeProps, { tabData: { braveShields: 'allow' } })
const wrapper2 = shallow(baseComponent(newProps2))
const assertion2 = wrapper2.find('#mainToggle').prop('checked')
assert.equal(assertion2, true)
})

it('displays the hostname', () => {
const newProps = Object.assign(fakeProps, {
tabData: { hostname: 'https://brian-bondy-canada-do-te-karate.com' }
})
const wrapper = shallow(baseComponent(newProps))
const assertion = wrapper.find('#hostname').props().children
assert.equal(assertion, 'https://brian-bondy-canada-do-te-karate.com')
})
})

0 comments on commit afb6950

Please sign in to comment.