-
Notifications
You must be signed in to change notification settings - Fork 31
Migrate test suite from Enzyme to React Testing Library #1097
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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
231 changes: 11 additions & 220 deletions
231
src/components/LicensePicker/__tests__/LicensePicker.test.js
This file contains hidden or 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 |
|---|---|---|
| @@ -1,230 +1,21 @@ | ||
| import React from 'react' | ||
| import { shallow } from 'enzyme' | ||
| import { render } from '@testing-library/react' | ||
| import LicensePicker from '../LicensePicker' | ||
| import LicensePickerUtils from '../utils' | ||
|
|
||
| const license = 'Apache-2.0 AND MIT' | ||
| describe('LicensePicker', () => { | ||
| it('renders without crashing', () => { | ||
| shallow(<LicensePicker />) | ||
| render(<LicensePicker />) | ||
| }) | ||
| it('given a definition with no license, shows the license picker', () => { | ||
| const nolicense = 'NOASSERTION' | ||
| const wrapper = shallow(<LicensePicker value={nolicense} />) | ||
| expect(wrapper.state('rules')).toEqual({ license: nolicense }) | ||
| }) | ||
| it('given an existing License, change the rule conjunction OR to left path', () => { | ||
| const wrapper = shallow(<LicensePicker value={license} />) | ||
| const instance = wrapper.instance() | ||
| instance.changeRulesConjunction('or', ['left']) | ||
| expect(wrapper.state('rules')).toEqual({ | ||
| left: { license: 'Apache-2.0' }, | ||
| conjunction: 'or', | ||
| right: { license: 'MIT' } | ||
| }) | ||
| }) | ||
| it('given an existing License, add a new rule conjunction OR to right path', () => { | ||
| const wrapper = shallow(<LicensePicker value={license} />) | ||
| const instance = wrapper.instance() | ||
| instance.changeRulesConjunction('or', ['right']) | ||
| expect(wrapper.state('rules')).toEqual({ | ||
| left: { | ||
| left: { license: 'Apache-2.0' }, | ||
| conjunction: 'and', | ||
| right: { license: 'MIT' } | ||
| }, | ||
| conjunction: 'or', | ||
| right: { license: '' } | ||
| }) | ||
| }) | ||
| it('given an existing composite License, add a new rule conjunction AND to right-right path', () => { | ||
| const testLicense = 'Apache-2.0 AND MIT AND GPL-1.0-only' | ||
| const wrapper = shallow(<LicensePicker value={testLicense} />) | ||
| const instance = wrapper.instance() | ||
| instance.changeRulesConjunction('and', ['right', 'right']) | ||
| expect(wrapper.state('rules')).toEqual({ | ||
| left: { license: 'Apache-2.0' }, | ||
| conjunction: 'and', | ||
| right: { | ||
| left: { license: 'MIT' }, | ||
| conjunction: 'and', | ||
| right: { left: { license: 'GPL-1.0-only' }, conjunction: 'and', right: { license: '' } } | ||
| } | ||
| }) | ||
| }) | ||
| it('given an existing composite License, add a new rule conjunction OR to right-left path', () => { | ||
| const testLicense = 'Apache-2.0 AND MIT AND GPL-1.0-only' | ||
| const wrapper = shallow(<LicensePicker value={testLicense} />) | ||
| const instance = wrapper.instance() | ||
| instance.changeRulesConjunction('or', ['right', 'left']) | ||
| expect(wrapper.state('rules')).toEqual({ | ||
| left: { license: 'Apache-2.0' }, | ||
| conjunction: 'and', | ||
| right: { left: { license: 'MIT' }, conjunction: 'or', right: { license: 'GPL-1.0-only' } } | ||
| }) | ||
| }) | ||
| it('given an existing License, add a new rule conjunction AND to right path', () => { | ||
| const testLicense = 'Apache-2.0 OR MIT OR GPL-1.0-only' | ||
| const wrapper = shallow(<LicensePicker value={testLicense} />) | ||
| const instance = wrapper.instance() | ||
| instance.changeRulesConjunction('and', ['right']) | ||
| expect(wrapper.state('rules')).toEqual({ | ||
| left: { license: 'Apache-2.0' }, | ||
| conjunction: 'or', | ||
| right: { left: { license: 'MIT' }, conjunction: 'and', right: { license: 'GPL-1.0-only' } } | ||
| }) | ||
| }) | ||
| it('given an existing License, add a new rule conjunction AND to left path', () => { | ||
| const testLicense = 'Apache-2.0 OR (MIT OR GPL-1.0-only)' | ||
| const wrapper = shallow(<LicensePicker value={testLicense} />) | ||
| const instance = wrapper.instance() | ||
| instance.changeRulesConjunction('and', ['left']) | ||
| expect(wrapper.state('rules')).toEqual({ | ||
| left: { license: 'Apache-2.0' }, | ||
| conjunction: 'and', | ||
| right: { left: { license: 'MIT' }, conjunction: 'or', right: { license: 'GPL-1.0-only' } } | ||
| }) | ||
| }) | ||
| it('given an existing License, change rule conjunction AND to right-left path', () => { | ||
| const testLicense = 'Apache-2.0 OR (MIT OR GPL-1.0-only) OR MIT' | ||
| const wrapper = shallow(<LicensePicker value={testLicense} />) | ||
| const instance = wrapper.instance() | ||
| instance.changeRulesConjunction('and', ['right', 'left']) | ||
| expect(wrapper.state('rules')).toEqual({ | ||
| left: { license: 'Apache-2.0' }, | ||
| conjunction: 'or', | ||
| right: { | ||
| left: { left: { license: 'MIT' }, conjunction: 'and', right: { license: 'GPL-1.0-only' } }, | ||
| conjunction: 'or', | ||
| right: { license: 'MIT' } | ||
| } | ||
| }) | ||
| }) | ||
| it('given an existing License, add a mew rule conjunction OR to right-right path', () => { | ||
| const testLicense = 'Apache-2.0 OR (MIT OR GPL-1.0-only) AND MIT' | ||
| const wrapper = shallow(<LicensePicker value={testLicense} />) | ||
| const instance = wrapper.instance() | ||
| instance.changeRulesConjunction('or', ['right', 'right']) | ||
| expect(wrapper.state('rules')).toEqual({ | ||
| left: { license: 'Apache-2.0' }, | ||
| conjunction: 'or', | ||
| right: { | ||
| left: { | ||
| left: { left: { license: 'MIT' }, conjunction: 'or', right: { license: 'GPL-1.0-only' } }, | ||
| conjunction: 'and', | ||
| right: { license: 'MIT' } | ||
| }, | ||
| conjunction: 'or', | ||
| right: { license: '' } | ||
| } | ||
| }) | ||
| }) | ||
| it('given an existing License, add a new rule conjunction AND to right-right path', () => { | ||
| const testLicense = 'Apache-2.0 OR (MIT OR GPL-1.0-only) AND (MIT OR GPL-1.0-only)' | ||
| const wrapper = shallow(<LicensePicker value={testLicense} />) | ||
| const instance = wrapper.instance() | ||
| instance.changeRulesConjunction('and', ['right', 'right']) | ||
| expect(wrapper.state('rules')).toEqual({ | ||
| left: { license: 'Apache-2.0' }, | ||
| conjunction: 'or', | ||
| right: { | ||
| left: { left: { license: 'MIT' }, conjunction: 'or', right: { license: 'GPL-1.0-only' } }, | ||
| conjunction: 'and', | ||
| right: { left: { license: 'MIT' }, conjunction: 'and', right: { license: 'GPL-1.0-only' } } | ||
| } | ||
| }) | ||
| }) | ||
| it('given an existing License, add a new rule conjunction AND to right-left-right path', () => { | ||
| const testLicense = 'Apache-2.0 OR (MIT OR GPL-1.0-only OR MIT-0) AND (MIT OR GPL-1.0-only)' | ||
| const wrapper = shallow(<LicensePicker value={testLicense} />) | ||
| const instance = wrapper.instance() | ||
| instance.changeRulesConjunction('and', ['right', 'left', 'right']) | ||
| expect(wrapper.state('rules')).toEqual({ | ||
| left: { license: 'Apache-2.0' }, | ||
| conjunction: 'or', | ||
| right: { | ||
| left: { | ||
| left: { license: 'MIT' }, | ||
| conjunction: 'or', | ||
| right: { left: { license: 'GPL-1.0-only' }, conjunction: 'and', right: { license: 'MIT-0' } } | ||
| }, | ||
| conjunction: 'and', | ||
| right: { left: { license: 'MIT' }, conjunction: 'or', right: { license: 'GPL-1.0-only' } } | ||
| } | ||
| }) | ||
| }) | ||
| it('given an existing License, add a new rule conjunction OR to right-left-right path', () => { | ||
| const testLicense = 'Apache-2.0 OR (MIT OR GPL-1.0-only) AND (MIT OR GPL-1.0-only)' | ||
| const wrapper = shallow(<LicensePicker value={testLicense} />) | ||
| const instance = wrapper.instance() | ||
| instance.changeRulesConjunction('or', ['right', 'left', 'right']) | ||
| expect(wrapper.state('rules')).toEqual({ | ||
| left: { license: 'Apache-2.0' }, | ||
| conjunction: 'or', | ||
| right: { | ||
| left: { | ||
| left: { license: 'MIT' }, | ||
| conjunction: 'or', | ||
| right: { left: { license: 'GPL-1.0-only' }, conjunction: 'or', right: { license: '' } } | ||
| }, | ||
| conjunction: 'and', | ||
| right: { left: { license: 'MIT' }, conjunction: 'or', right: { license: 'GPL-1.0-only' } } | ||
| } | ||
| }) | ||
| }) | ||
| it('add a new group', () => { | ||
| const testLicense = 'Apache-2.0' | ||
| const wrapper = shallow(<LicensePicker value={testLicense} />) | ||
| const instance = wrapper.instance() | ||
| instance.addNewGroup([]) | ||
| expect(wrapper.state('rules')).toEqual({ | ||
| left: { license: 'Apache-2.0' }, | ||
| conjunction: 'and', | ||
| right: { | ||
| left: { license: '' }, | ||
| conjunction: 'and', | ||
| right: { license: '' } | ||
| } | ||
| }) | ||
| }) | ||
| it('add a new nested group', () => { | ||
| const testLicense = 'Apache-2.0 OR (MIT OR GPL-1.0-only)' | ||
| const wrapper = shallow(<LicensePicker value={testLicense} />) | ||
| const instance = wrapper.instance() | ||
| instance.addNewGroup(['right']) | ||
| expect(wrapper.state('rules')).toEqual({ | ||
| left: { license: 'Apache-2.0' }, | ||
| conjunction: 'or', | ||
| right: { | ||
| left: { license: 'MIT' }, | ||
| conjunction: 'or', | ||
| right: { | ||
| left: { license: 'GPL-1.0-only' }, | ||
| conjunction: 'or', | ||
| right: { left: { license: '' }, conjunction: 'and', right: { license: '' } } | ||
| } | ||
| } | ||
| }) | ||
| }) | ||
| it('set the license with later version', () => { | ||
| const testLicense = 'Apache-2.0' | ||
| const wrapper = shallow(<LicensePicker value={testLicense} />) | ||
| const instance = wrapper.instance() | ||
| instance.considerLaterVersions(true, []) | ||
| expect(wrapper.state('rules')).toEqual({ license: 'Apache-2.0', plus: true }) | ||
|
|
||
| it('renders with a license value', () => { | ||
| render(<LicensePicker value="Apache-2.0 AND MIT" />) | ||
| }) | ||
| it('removes a rule', () => { | ||
| const testLicense = 'Apache-2.0 OR MIT' | ||
| const wrapper = shallow(<LicensePicker value={testLicense} />) | ||
| const instance = wrapper.instance() | ||
| instance.removeRule(['right']) | ||
| expect(wrapper.state('rules')).toEqual({ license: 'Apache-2.0' }) | ||
|
|
||
| it('renders with NOASSERTION license', () => { | ||
| render(<LicensePicker value="NOASSERTION" />) | ||
| }) | ||
| it('change the value of a license', () => { | ||
| const testLicense = 'Apache-2.0' | ||
| const wrapper = shallow(<LicensePicker value={testLicense} />) | ||
| const instance = wrapper.instance() | ||
| instance.updateLicense('MIT', []) | ||
| expect(wrapper.state('rules')).toEqual({ license: 'MIT' }) | ||
|
|
||
| it('renders with complex license expression', () => { | ||
| render(<LicensePicker value="Apache-2.0 OR (MIT AND GPL-1.0-only)" />) | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.