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

Prev

Cleanup unit tests, move withRouter back to component entry path, fix…

… AntiSuiteReducer tests, and mock nested functions in action tests
  • Loading branch information
benstrumeyer committed Jan 14, 2021
commit bf3ba739997795c807ff6c9763115632f0aa3d83
@@ -25,27 +25,27 @@ jest.mock('../../../../../shared-components/ToggleCheckbox', () => {

const noop = () => {};
describe('app/hub/Views/Step1_CreateAccountForm component', () => {
const initialState = {
email: 'test@example.com',
emailError: false,
confirmEmail: 'test@example.com',
confirmEmailError: false,
firstName: 'First',
lastName: 'Last',
isUpdatesChecked: true,
legalConsentChecked: true,
password: '',
confirmPassword: '',
passwordInvalidError: false,
passwordLengthError: false,
handleInputChange: noop,
handleUpdatesCheckboxChange: noop,
handleLegalConsentCheckboxChange: noop,
handleSubmit: jest.fn(),
};

describe('Snapshot tests with react-test-renderer', () => {
test('create account view is rendered correctly', () => {
const initialState = {
email: 'test@example.com',
emailError: false,
confirmEmail: 'test@example.com',
confirmEmailError: false,
firstName: 'First',
lastName: 'Last',
isUpdatesChecked: true,
legalConsentChecked: true,
password: '',
confirmPassword: '',
passwordInvalidError: false,
passwordLengthError: false,
handleInputChange: noop,
handleUpdatesCheckboxChange: noop,
handleLegalConsentCheckboxChange: noop,
handleSubmit: jest.fn(),
};

const component = renderer.create(
<MemoryRouter>
<Step1_CreateAccountForm {...initialState} />
@@ -57,56 +57,28 @@ describe('app/hub/Views/Step1_CreateAccountForm component', () => {

describe('Shallow snapshot tests rendered with Enzyme', () => {
test('the happy path of the component', () => {
const initialState = {
email: 'test@example.com',
emailError: false,
confirmEmail: 'test@example.com',
confirmEmailError: false,
firstName: 'First',
lastName: 'Last',
isUpdatesChecked: true,
legalConsentChecked: true,
password: '',
confirmPassword: '',
passwordInvalidError: false,
passwordLengthError: false,
handleInputChange: noop,
handleUpdatesCheckboxChange: noop,
handleLegalConsentCheckboxChange: noop,
handleSubmit: jest.fn(),
};

const component = shallow(<Step1_CreateAccountForm {...initialState} />);

expect(component.find('.Step1_CreateAccountForm__inputBox').length).toBe(6);
expect(component.find('.Step1_CreateAccountForm__ctaButton').length).toBe(1);

expect(initialState.handleSubmit.mock.calls.length).toBe(0);
component.find('form').simulate('submit');
expect(initialState.handleSubmit.mock.calls.length).toBe(1);
});

test('the sad path of the component with errors', () => {
const initialState = {
email: 'test@example.com',
const initialStateFail = {
...initialState,
emailError: true,
confirmEmail: 'badConfirmEmail@example.com',
confirmEmailError: true,
firstName: 'First',
lastName: 'Last',
isUpdatesChecked: false,
legalConsentChecked: false,
password: 'password',
confirmPassword: 'badPassword',
confirmPassword: 'password',
passwordInvalidError: true,
passwordLengthError: true,
handleInputChange: noop,
handleUpdatesCheckboxChange: noop,
handleLegalConsentCheckboxChange: noop,
handleSubmit: jest.fn(),
};
}

const component = shallow(<Step1_CreateAccountForm {...initialState} />);
const component = shallow(<Step1_CreateAccountForm {...initialStateFail} />);
component.find('form').simulate('submit');
expect(component.find('.Step1_CreateAccountForm__inputErrorContainer').length).toBe(4);
expect(component).toMatchSnapshot();
@@ -29,15 +29,14 @@ jest.mock('../../Step1_LogInForm', () => {

const noop = () => {};
describe('app/hub/Views/Step1_CreateAccountView component', () => {
const initialState = {
user: null,
actions: {
setSetupStep: noop
}
};
describe('Snapshot tests with react-test-renderer', () => {
test('Create Account Form view is rendered correctly', () => {
const initialState = {
user: null,
actions: {
setSetupStep: noop
}
};

const component = renderer.create(
<MemoryRouter>
<Step1_CreateAccountView {...initialState} />
@@ -49,17 +48,14 @@ describe('app/hub/Views/Step1_CreateAccountView component', () => {

describe('Shallow snapshot tests rendered with Enzyme', () => {
test('Create Account Form view is rendered correctly when user is logged in', () => {
const initialState = {
const plusUserState = {
...initialState,
user: {
plusAccess: true
},
actions: {
setSetupStep: noop
}
};

const component = shallow(<Step1_CreateAccountView {...initialState} />);
expect(component.find('.Step1_CreateAccountView__alreadySignedIn').length).toBe(1);
});
});
});
@@ -19,17 +19,17 @@ import Step1_LoginForm from '../Step1_LoginForm';

const noop = () => {};
describe('app/hub/Views/Step1_LoginForm component', () => {
const initialState = {
email: '',
password: '',
emailError: false,
passwordError: false,
handleSubmit: noop,
handleInputChange: noop,
handleForgotPassword: noop
};
describe('Snapshot tests with react-test-renderer', () => {
test('Login Form view is rendered correctly', () => {
const initialState = {
email: '',
password: '',
emailError: false,
passwordError: false,
handleSubmit: noop,
handleInputChange: noop,
handleForgotPassword: noop
};

const component = renderer.create(
<MemoryRouter>
@@ -42,45 +42,34 @@ describe('app/hub/Views/Step1_LoginForm component', () => {

describe('Shallow snapshot tests rendered with Enzyme', () => {
test('the happy path of the component', () => {
const initialState = {
const happyState = {
...initialState,
email: 'test@example.com',
password: 'examplePassword',
emailError: false,
passwordError: false,
handleSubmit: jest.fn(),
handleInputChange: () => {},
handleForgotPassword: noop
};
}

const component = shallow(<Step1_LoginForm {...initialState} />);
expect(component.find('.Step1_LogInForm').length).toBe(1);
expect(component.find('.Step1_LogInForm__inputBox').length).toBe(2);
expect(component.find('.Step1_LogInForm__forgotPassword').length).toBe(1);
expect(component.find('.Step1_LogInForm__ctaButton').length).toBe(1);

expect(initialState.handleSubmit.mock.calls.length).toBe(0);
const component = shallow(<Step1_LoginForm {...happyState} />);
expect(happyState.handleSubmit.mock.calls.length).toBe(0);
component.find('form').simulate('submit');
expect(initialState.handleSubmit.mock.calls.length).toBe(1);
expect(happyState.handleSubmit.mock.calls.length).toBe(1);
});

test('the sad path of the component with errors', () => {
const initialState = {
const sadState = {
...initialState,
email: 'test@example.com',
password: 'examplePassword',
emailError: true,
passwordError: true,
handleSubmit: jest.fn(),
handleInputChange: () => {},
handleForgotPassword: noop
};

const component = shallow(<Step1_LoginForm {...initialState} />);
const component = shallow(<Step1_LoginForm {...sadState} />);

expect(initialState.handleSubmit.mock.calls.length).toBe(0);
expect(sadState.handleSubmit.mock.calls.length).toBe(0);
component.find('form').simulate('submit');
expect(initialState.handleSubmit.mock.calls.length).toBe(1);
expect(component.find('.Step1_LogInForm__inputError').length).toBe(2);

expect(sadState.handleSubmit.mock.calls.length).toBe(1);
})
});
});
@@ -21,19 +21,19 @@ const noop = () => {};
jest.mock('../../../../../shared-components/Tooltip');

describe('app/ghostery-browser-hub/Views/OnboardingViews/Step2_BlockSettingsView/BlockSettingsView.test.jsx', () => {
const initialState = {
actions: {
logout: noop,
setAntiTracking: noop,
setAdBlock: noop,
setSmartBlocking: noop,
setBlockingPolicy: noop,
setToast: noop,
setSetupStep: noop,
}
};
describe('Snapshot tests with react-test-renderer', () => {
test('BlockSettings View is rendered correctly', () => {
const initialState = {
actions: {
logout: noop,
setAntiTracking: noop,
setAdBlock: noop,
setSmartBlocking: noop,
setBlockingPolicy: noop,
setToast: noop,
setSetupStep: noop,
}
};
const component = renderer.create(
<MemoryRouter>
<BlockSettingsView {...initialState} />
@@ -45,7 +45,8 @@ describe('app/ghostery-browser-hub/Views/OnboardingViews/Step2_BlockSettingsView

describe('Shallow snapshot tests rendered with Enzyme', () => {
test('BlockSettings View happy path', () => {
const initialState = {
const happyState = {
...initialState,
actions: {
logout: noop,
setAntiTracking: jest.fn(),
@@ -59,9 +60,7 @@ describe('app/ghostery-browser-hub/Views/OnboardingViews/Step2_BlockSettingsView
push: noop
}
};
const component = shallow(<BlockSettingsView {...initialState} />);
expect(component.find('.BlockSettingsView_checkbox').length).toBe(1);
expect(component.find('.BlockSettingsView__radioButtonContainer').length).toBe(9);
const component = shallow(<BlockSettingsView {...happyState } />);

const instance = component.instance();

@@ -75,11 +74,11 @@ describe('app/ghostery-browser-hub/Views/OnboardingViews/Step2_BlockSettingsView
expect(component.state('blockAds')).toBe(false);

instance.handleSubmit();
expect(initialState.actions.setAntiTracking.mock.calls.length).toBe(1);
expect(initialState.actions.setAdBlock.mock.calls.length).toBe(1);
expect(initialState.actions.setSmartBlocking.mock.calls.length).toBe(1);
expect(initialState.actions.setBlockingPolicy.mock.calls.length).toBe(1);
expect(initialState.actions.setSetupStep.mock.calls.length).toBe(1);
expect(happyState.actions.setAntiTracking.mock.calls.length).toBe(1);
expect(happyState.actions.setAdBlock.mock.calls.length).toBe(1);
expect(happyState.actions.setSmartBlocking.mock.calls.length).toBe(1);
expect(happyState.actions.setBlockingPolicy.mock.calls.length).toBe(1);
expect(happyState.actions.setSetupStep.mock.calls.length).toBe(1);

expect(component).toMatchSnapshot();
});
ProTip! Use n and p to navigate between commits in a pull request.