-
Notifications
You must be signed in to change notification settings - Fork 816
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Add unit tests; close brave/brave-browser#1530
- Loading branch information
Showing
11 changed files
with
245 additions
and
39 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
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
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
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
93 changes: 93 additions & 0 deletions
93
components/test/brave_welcome_ui/components/importBox_test.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,93 @@ | ||
/* 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 * as React from 'react' | ||
import { shallow } from 'enzyme' | ||
import { Content, PrimaryButton } from 'brave-ui/features/welcome' | ||
import { WelcomeImportImage } from 'brave-ui/features/welcome/images' | ||
import ImportBox, { Props } from '../../../../components/brave_welcome_ui/components/screens/importBox' | ||
import { mockImportSources } from '../../testData' | ||
|
||
describe('ImportBox component tests', () => { | ||
|
||
const mockProps: Props = { | ||
index: 2, | ||
currentScreen: 2, | ||
onClick: () => null, | ||
browserProfiles: mockImportSources | ||
} | ||
|
||
describe('ImportBox render tests', () => { | ||
it('renders the component DOM without crashing', () => { | ||
const wrapper = shallow( | ||
<ImportBox | ||
index={mockProps.index} | ||
currentScreen={mockProps.currentScreen} | ||
onClick={mockProps.onClick} | ||
browserProfiles={mockProps.browserProfiles} | ||
/>) | ||
|
||
expect(wrapper.find(Content)).toHaveLength(1) | ||
expect(wrapper.contains(<WelcomeImportImage />)) | ||
}) | ||
}) | ||
|
||
describe('ImportBox interaction tests', () => { | ||
it('should call the import API on button click', () => { | ||
const mockAction = jest.fn() | ||
const wrapper = shallow( | ||
<ImportBox | ||
index={mockProps.index} | ||
currentScreen={mockProps.currentScreen} | ||
onClick={mockAction} | ||
browserProfiles={mockProps.browserProfiles} | ||
/>) | ||
const button = wrapper.find(PrimaryButton) | ||
expect(button).toHaveLength(1) | ||
button.simulate('click') | ||
expect(mockAction.mock.calls.length).toBe(1) | ||
}) | ||
}) | ||
|
||
describe('onChangeImportSource', () => { | ||
it('should set selectedBrowserProfile to null if non-valid option is selected', () => { | ||
const mockEvent = { | ||
target: { | ||
value: '' | ||
} | ||
} | ||
const wrapper = shallow( | ||
<ImportBox | ||
index={mockProps.index} | ||
currentScreen={mockProps.currentScreen} | ||
onClick={mockProps.onClick} | ||
browserProfiles={mockProps.browserProfiles} | ||
/>) | ||
|
||
const expected = null | ||
wrapper.instance().onChangeImportSource(mockEvent) | ||
expect(wrapper.state().selectedBrowserProfile).toEqual(expected) | ||
}) | ||
|
||
it('should set selectedBrowserProfile to profile if valid option selected', () => { | ||
const mockEvent = { | ||
target: { | ||
value: '1' | ||
} | ||
} | ||
const wrapper = shallow( | ||
<ImportBox | ||
index={mockProps.index} | ||
currentScreen={mockProps.currentScreen} | ||
onClick={mockProps.onClick} | ||
browserProfiles={mockImportSources} | ||
/>) | ||
|
||
// Chrome profile which has browser index of 1 | ||
const expected = mockImportSources[0] | ||
wrapper.instance().onChangeImportSource(mockEvent) | ||
expect(wrapper.state().selectedBrowserProfile).toEqual(expected) | ||
}) | ||
}) | ||
}) |
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
18 changes: 18 additions & 0 deletions
18
components/test/brave_welcome_ui/utils/welcomeUtils_test.ts
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,18 @@ | ||
/* Copyright (c) 2019 The Brave Authors. 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 { getValidBrowserProfiles } from '../../../brave_welcome_ui/welcomeUtils' | ||
import { mockImportSources } from '../../testData' | ||
|
||
describe('welcome utils tests', () => { | ||
describe('getfilterBrowserProfiles tests', () => { | ||
it('should filter out profiles with "safari" and "Bookmarks HTML File" as names', () => { | ||
const result = getValidBrowserProfiles(mockImportSources) | ||
// Chrome browser profile object | ||
const expected = [mockImportSources[0]] | ||
expect(result).toEqual(expected) | ||
}) | ||
}) | ||
}) |
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