Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-2244: Unit tests for Ghostery Dawn Intro Hub #657

Merged
merged 24 commits into from Jan 19, 2021
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6d510c2
Add tests for Welcome and success viwe
benstrumeyer Jan 6, 2021
b2d8d86
Merge branch 'ghostery-browser-intro-hub' into ghostery-browser-intro…
benstrumeyer Jan 9, 2021
bcd6150
Add tests for Welcome, Success, BlockSettingsView and ChoosePlanView
benstrumeyer Jan 10, 2021
6960ff4
Add tests for Step1_CreateAccountForm
benstrumeyer Jan 10, 2021
0872b0d
Add tests for Step1_LoginForm
benstrumeyer Jan 10, 2021
8721f8d
Add tests for Step1_CreateAccountView
benstrumeyer Jan 10, 2021
a870aef
Add tests for hub reducers
benstrumeyer Jan 11, 2021
af71328
Update copyright year
benstrumeyer Jan 11, 2021
6ebf2e5
Add copyright to sass files
benstrumeyer Jan 11, 2021
f8e9899
Add broken AntiSuiteActions test
benstrumeyer Jan 11, 2021
bd79fd6
Add tests for AntiSuiteActions
benstrumeyer Jan 12, 2021
88bdd15
Add test for BlockingPolicyActions
benstrumeyer Jan 12, 2021
4e5f507
Add test for MetricsActions
benstrumeyer Jan 12, 2021
65a1aa0
Add tests for ToastActions
benstrumeyer Jan 12, 2021
622943d
Add tests for SetupLifeCycleActions
benstrumeyer Jan 12, 2021
fbf830d
Add test for StepProgressBar component, fix console errors and use On…
benstrumeyer Jan 12, 2021
8c024f5
Update propTypes
benstrumeyer Jan 12, 2021
f085ef1
Remove console log
benstrumeyer Jan 12, 2021
dbbbaca
Merge branch 'ghostery-browser-intro-hub' into ghostery-browser-intro…
benstrumeyer Jan 12, 2021
3e3c185
Update proptypes
benstrumeyer Jan 12, 2021
22d567f
Update test for ToastReducer
benstrumeyer Jan 12, 2021
f4b4e53
Fix Choose Plan Page screen width
benstrumeyer Jan 12, 2021
3438d55
Add back comment
benstrumeyer Jan 12, 2021
bf3ba73
Cleanup unit tests, move withRouter back to component entry path, fix…
benstrumeyer Jan 14, 2021
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

Add tests for hub reducers

  • Loading branch information
benstrumeyer committed Jan 11, 2021
commit a870aef051159f03f8da2d74add730445618adcf
@@ -0,0 +1,69 @@
/**
* AntiSuite Test Reducer
*
* Ghostery Browser Extension
* https://www.ghostery.com/
*
* Copyright 2021 Ghostery, Inc. All rights reserved.
*
* 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 Immutable from 'seamless-immutable';
import AntiSuiteReducer from '../AntiSuiteReducer';
import { SET_AD_BLOCK, SET_ANTI_TRACKING, SET_SMART_BLOCK } from '../../constants/AntiSuiteConstants';

const initialState = Immutable({
setup: {
enable_ad_block: true,
enable_anti_tracking: true,
enable_smart_block: true
}
});

describe('app/shared-hub/reducers/AntiSuiteReducer', () => {
test('initial state is correct', () => {
expect(AntiSuiteReducer(undefined, {})).toEqual({});
});

test('reducer correctly handles SET_AD_BLOCK', () => {
const data = {
enable_ad_block: true,
};
const action = { data, type: SET_AD_BLOCK };

const updatedAntiSuiteState = Immutable.merge(initialState.setup, data);

expect(AntiSuiteReducer(initialState, action)).toEqual({
setup: updatedAntiSuiteState
});
});
This conversation was marked as resolved by wlycdgr
Comment on lines +32 to +42

This comment has been minimized.

@wlycdgr

wlycdgr Jan 13, 2021
Member

Since enable_ad_block is already true in the original initialState, could this test pass even though the SET_AD_BLOCK handler does (for example) nothing?

This comment has been minimized.

@wlycdgr

wlycdgr Jan 13, 2021
Member

(Same question for the anti tracking and smart block tests that follow)

This comment has been minimized.

@benstrumeyer

benstrumeyer Jan 14, 2021
Author Contributor

Good idea, I set the initial bools to false so we can assert that it changes to true


test('reducer correctly handles SET_ANTI_TRACKING', () => {
const data = {
enable_anti_tracking: true,
};
const action = { data, type: SET_ANTI_TRACKING };

const updatedAntiSuiteState = Immutable.merge(initialState.setup, data);

expect(AntiSuiteReducer(initialState, action)).toEqual({
setup: updatedAntiSuiteState
});
});

test('reducer correctly handles SET_SMART_BLOCK', () => {
const data = {
enable_smart_block: true,
};
const action = { data, type: SET_SMART_BLOCK };

const updatedAntiSuiteState = Immutable.merge(initialState.setup, data);

expect(AntiSuiteReducer(initialState, action)).toEqual({
setup: updatedAntiSuiteState
});
});
});
@@ -0,0 +1,41 @@
/**
* BlockingPolicy Test Reducer
*
* Ghostery Browser Extension
* https://www.ghostery.com/
*
* Copyright 2021 Ghostery, Inc. All rights reserved.
*
* 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 Immutable from 'seamless-immutable';
import BlockingPolicyReducer from '../BlockingPolicyReducer';
import { SET_BLOCKING_POLICY } from '../../constants/BlockingPolicyConstants';

const initialState = Immutable({
setup: {
blockingPolicy: true
}
});

describe('app/shared-hub/reducers/BlockingPolicy', () => {
test('initial state is correct', () => {
expect(BlockingPolicyReducer(undefined, {})).toEqual({});
});

test('reducer correctly handles SET_BLOCKING_POLICY', () => {
const data = {
blockingPolicy: true,
};
const action = { data, type: SET_BLOCKING_POLICY };

const updatedBlockingPolicyState = Immutable.merge(initialState.setup, data);

expect(BlockingPolicyReducer(initialState, action)).toEqual({
setup: updatedBlockingPolicyState
});
This conversation was marked as resolved by wlycdgr
Comment on lines +29 to +39

This comment has been minimized.

@wlycdgr

wlycdgr Jan 13, 2021
Member

Same question here as in the AntiSuiteReducer tests - could this pass even if the SET_BLOCKING_POLICY action handler does nothing?

This comment has been minimized.

@benstrumeyer

benstrumeyer Jan 14, 2021
Author Contributor

See comment above, updated initial bools to false

});
});
@@ -0,0 +1,42 @@
/**
* SetupLifecycle Test Reducer
*
* Ghostery Browser Extension
* https://www.ghostery.com/
*
* Copyright 2021 Ghostery, Inc. All rights reserved.
*
* 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 Immutable from 'seamless-immutable';
import SetupLifecycleReducer from '../SetupLifecycleReducer';
import { INIT_SETUP_PROPS } from '../../constants/SetupLifecycleConstants';

const initialState = Immutable({
setup: {}
});

describe('app/shared-hub/reducers/SetupLifecycleReducer', () => {
test('initial state is correct', () => {
expect(SetupLifecycleReducer(undefined, {})).toEqual({});
});

test('reducer correctly handles INIT_SETUP_PROPS', () => {
const data = {
blockingPolicy: true,
enable_anti_tracking: true,
enable_ad_block: true,
enable_smart_block: true,
};
const action = { data, type: INIT_SETUP_PROPS };

const updatedSetupLifecycleState = Immutable.merge(initialState.setup, data);

expect(SetupLifecycleReducer(initialState, action)).toEqual({
setup: updatedSetupLifecycleState
});
});
});
@@ -0,0 +1,41 @@
/**
* Toast Test Reducer
*
* Ghostery Browser Extension
* https://www.ghostery.com/
*
* Copyright 2021 Ghostery, Inc. All rights reserved.
*
* 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 Immutable from 'seamless-immutable';
import ToastReducer from '../ToastReducer';
import SET_TOAST from '../../constants/ToastConstants';

const initialState = Immutable({
app: {}
});

describe('app/shared-hub/reducers/ToastReducer', () => {
test('initial state is correct', () => {
expect(ToastReducer(undefined, {})).toEqual({});
});

test('reducer correctly handles SET_TOAST', () => {
const data = {
toastMessage: 'hey',
toastClass: 'danger'
};
const action = { data, type: SET_TOAST };

const updatedToastReducerState = Immutable.merge(initialState.app, data);
console.log(ToastReducer(initialState, action));

expect(ToastReducer(initialState, action)).toEqual({
app: updatedToastReducerState
});
});
});
ProTip! Use n and p to navigate between commits in a pull request.