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 AntiSuiteActions

  • Loading branch information
benstrumeyer committed Jan 12, 2021
commit bd79fd6aaadd45c00a967f2cdccd1b614b045bfb
@@ -15,33 +15,33 @@ import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import * as utils from '../../utils';
import * as AntiSuiteActions from '../AntiSuiteActions';
import { SET_ANTI_TRACKING, SET_AD_BLOCK, SET_SMART_BLOCK } from '../../constants/AntiSuiteConstants';
import { SET_AD_BLOCK, SET_ANTI_TRACKING, SET_SMART_BLOCK } from '../../constants/AntiSuiteConstants';

const middlewares = [thunk];
const mockStore = configureStore(middlewares);

const testData = { test: true };

utils.sendMessageInPromise = jest.fn((name, message) => new Promise((resolve, reject) => {
switch (name) {
case SET_ANTI_TRACKING: {
case 'SET_ANTI_TRACKING': {
resolve(testData);
break;
}
case SET_AD_BLOCK: {
console.log('going in send Message')
resolve(message);
case 'SET_AD_BLOCK': {
resolve(testData);
break;
}
case SET_SMART_BLOCK: {
case 'SET_SMART_BLOCK': {
resolve(testData);
break;
}
default: resolve(message);
default: resolve(testData);
}
}));

describe('app/hub/Views/OnboardingView/ actions', () => {
test('getHomeProps action should return correctly', () => {
describe('app/shared-hub/actions/AntiSuiteActions', () => {
test('setAdBlock action should return correctly', () => {
const initialState = {};
const store = mockStore(initialState);

@@ -52,4 +52,28 @@ describe('app/hub/Views/OnboardingView/ actions', () => {
expect(actions).toEqual([expectedPayload]);
});
});

test('setAntiTracking action should return correctly', () => {
const initialState = {};
const store = mockStore(initialState);

const data = testData;
const expectedPayload = { data, type: SET_ANTI_TRACKING };
return store.dispatch(AntiSuiteActions.setAntiTracking()).then(() => {
const actions = store.getActions();
expect(actions).toEqual([expectedPayload]);
});
});

test('setSmartBlock action should return correctly', () => {
const initialState = {};
const store = mockStore(initialState);

const data = testData;
const expectedPayload = { data, type: SET_SMART_BLOCK };
return store.dispatch(AntiSuiteActions.setSmartBlocking()).then(() => {
const actions = store.getActions();
expect(actions).toEqual([expectedPayload]);
});
});
});
@@ -26,6 +26,10 @@ import { withRouter } from 'react-router-dom';
import { log } from '../../../src/utils/common';
import { sendMessage as importedSM, sendMessageInPromise as importedSMIP } from '../../panel/utils/msg';

// Self import this file so makeDeferredDispatcher can mock the sendMessageInPromise function within the same class
// eslint-disable-next-line import/no-self-import
import * as utils from './index';

This conversation was marked as resolved by wlycdgr
Comment on lines +29 to +32

This comment has been minimized.

@wlycdgr

wlycdgr Jan 13, 2021
Member

Is there a way to do this that avoids overriding a linter rule? Maybe by mocking makeDeferredDispatcher in the test files that need it using the sendMessageInPromise mock created there?

This comment has been minimized.

@benstrumeyer

benstrumeyer Jan 14, 2021
Author Contributor

Ah, so that's the way to do it. I mocked both makeDeferredDispatcher and sendMessageInPromise inside the files that need it. Thanks for the help, it was a very tricky bug

const sendMessageInPromise = function(name, message) {
return importedSMIP(name, message, 'ghostery-hub');
};
@@ -72,7 +76,7 @@ const makeStoreCreator = function(reducers, middlewares) {
*/
function makeDeferredDispatcher(action, actionData) {
return function(dispatch) {
return sendMessageInPromise(action, actionData).then((data) => {
return utils.sendMessageInPromise(action, actionData).then((data) => {
dispatch({
type: action,
data,
@@ -113,8 +117,8 @@ function buildReduxHOC(stateKeys, actionCreators, baseComponent) {
export {
buildReduxHOC,
makeStoreCreator,
makeDeferredDispatcher,
log,
sendMessage,
sendMessageInPromise
sendMessageInPromise,
makeDeferredDispatcher
};
ProTip! Use n and p to navigate between commits in a pull request.