Skip to content

Commit abd5609

Browse files
authored
Merge pull request #1097 from clearlydefined/jamiemagee/migrate-enzyme-to-rtl
Migrate test suite from Enzyme to React Testing Library
2 parents 8d47349 + 7d77865 commit abd5609

27 files changed

+2233
-2479
lines changed

package-lock.json

Lines changed: 1527 additions & 975 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"minimatch": "^3.0.4",
2222
"moment": "^2.30.1",
2323
"monaco-editor": "^0.18.1",
24-
"sass": "^1.83.0",
2524
"pako": "^1.0.6",
2625
"protobufjs": "^6.8.8",
2726
"react": "^16.4.1",
@@ -42,6 +41,7 @@
4241
"redux": "^3.7.2",
4342
"redux-persist": "^4.6.0",
4443
"redux-thunk": "^2.3.0",
44+
"sass": "^1.83.0",
4545
"spdx-compare": "^1.0.0",
4646
"spdx-license-ids": "^3.0.7",
4747
"spdx-satisfies": "^5.0.0",
@@ -53,18 +53,18 @@
5353
"@babel/plugin-proposal-class-properties": "^7.3.0",
5454
"@babel/preset-env": "^7.3.1",
5555
"@babel/preset-react": "^7.0.0",
56+
"@testing-library/jest-dom": "^5.17.0",
57+
"@testing-library/react": "^12.1.5",
58+
"@testing-library/user-event": "^14.6.1",
5659
"babel-core": "^7.0.0-bridge.0",
5760
"babel-preset-env": "^1.7.0",
5861
"core-js": "^3.4.1",
5962
"cpx": "^1.5.0",
6063
"env-cmd": "^8.0.2",
61-
"enzyme": "^3.3.0",
62-
"enzyme-adapter-react-16": "^1.1.1",
6364
"eslint-config-prettier": "^3.0.1",
6465
"eslint-plugin-prettier": "^3.0.1",
6566
"fetch-mock": "^7.1.0",
6667
"identity-obj-proxy": "^3.0.0",
67-
"jest-enzyme": "^7.1.2",
6868
"jest-puppeteer": "^3.8.0",
6969
"npm-run-all": "^4.1.3",
7070
"prettier": "^1.16.3",
Lines changed: 11 additions & 220 deletions
Original file line numberDiff line numberDiff line change
@@ -1,230 +1,21 @@
11
import React from 'react'
2-
import { shallow } from 'enzyme'
2+
import { render } from '@testing-library/react'
33
import LicensePicker from '../LicensePicker'
4-
import LicensePickerUtils from '../utils'
54

6-
const license = 'Apache-2.0 AND MIT'
75
describe('LicensePicker', () => {
86
it('renders without crashing', () => {
9-
shallow(<LicensePicker />)
7+
render(<LicensePicker />)
108
})
11-
it('given a definition with no license, shows the license picker', () => {
12-
const nolicense = 'NOASSERTION'
13-
const wrapper = shallow(<LicensePicker value={nolicense} />)
14-
expect(wrapper.state('rules')).toEqual({ license: nolicense })
15-
})
16-
it('given an existing License, change the rule conjunction OR to left path', () => {
17-
const wrapper = shallow(<LicensePicker value={license} />)
18-
const instance = wrapper.instance()
19-
instance.changeRulesConjunction('or', ['left'])
20-
expect(wrapper.state('rules')).toEqual({
21-
left: { license: 'Apache-2.0' },
22-
conjunction: 'or',
23-
right: { license: 'MIT' }
24-
})
25-
})
26-
it('given an existing License, add a new rule conjunction OR to right path', () => {
27-
const wrapper = shallow(<LicensePicker value={license} />)
28-
const instance = wrapper.instance()
29-
instance.changeRulesConjunction('or', ['right'])
30-
expect(wrapper.state('rules')).toEqual({
31-
left: {
32-
left: { license: 'Apache-2.0' },
33-
conjunction: 'and',
34-
right: { license: 'MIT' }
35-
},
36-
conjunction: 'or',
37-
right: { license: '' }
38-
})
39-
})
40-
it('given an existing composite License, add a new rule conjunction AND to right-right path', () => {
41-
const testLicense = 'Apache-2.0 AND MIT AND GPL-1.0-only'
42-
const wrapper = shallow(<LicensePicker value={testLicense} />)
43-
const instance = wrapper.instance()
44-
instance.changeRulesConjunction('and', ['right', 'right'])
45-
expect(wrapper.state('rules')).toEqual({
46-
left: { license: 'Apache-2.0' },
47-
conjunction: 'and',
48-
right: {
49-
left: { license: 'MIT' },
50-
conjunction: 'and',
51-
right: { left: { license: 'GPL-1.0-only' }, conjunction: 'and', right: { license: '' } }
52-
}
53-
})
54-
})
55-
it('given an existing composite License, add a new rule conjunction OR to right-left path', () => {
56-
const testLicense = 'Apache-2.0 AND MIT AND GPL-1.0-only'
57-
const wrapper = shallow(<LicensePicker value={testLicense} />)
58-
const instance = wrapper.instance()
59-
instance.changeRulesConjunction('or', ['right', 'left'])
60-
expect(wrapper.state('rules')).toEqual({
61-
left: { license: 'Apache-2.0' },
62-
conjunction: 'and',
63-
right: { left: { license: 'MIT' }, conjunction: 'or', right: { license: 'GPL-1.0-only' } }
64-
})
65-
})
66-
it('given an existing License, add a new rule conjunction AND to right path', () => {
67-
const testLicense = 'Apache-2.0 OR MIT OR GPL-1.0-only'
68-
const wrapper = shallow(<LicensePicker value={testLicense} />)
69-
const instance = wrapper.instance()
70-
instance.changeRulesConjunction('and', ['right'])
71-
expect(wrapper.state('rules')).toEqual({
72-
left: { license: 'Apache-2.0' },
73-
conjunction: 'or',
74-
right: { left: { license: 'MIT' }, conjunction: 'and', right: { license: 'GPL-1.0-only' } }
75-
})
76-
})
77-
it('given an existing License, add a new rule conjunction AND to left path', () => {
78-
const testLicense = 'Apache-2.0 OR (MIT OR GPL-1.0-only)'
79-
const wrapper = shallow(<LicensePicker value={testLicense} />)
80-
const instance = wrapper.instance()
81-
instance.changeRulesConjunction('and', ['left'])
82-
expect(wrapper.state('rules')).toEqual({
83-
left: { license: 'Apache-2.0' },
84-
conjunction: 'and',
85-
right: { left: { license: 'MIT' }, conjunction: 'or', right: { license: 'GPL-1.0-only' } }
86-
})
87-
})
88-
it('given an existing License, change rule conjunction AND to right-left path', () => {
89-
const testLicense = 'Apache-2.0 OR (MIT OR GPL-1.0-only) OR MIT'
90-
const wrapper = shallow(<LicensePicker value={testLicense} />)
91-
const instance = wrapper.instance()
92-
instance.changeRulesConjunction('and', ['right', 'left'])
93-
expect(wrapper.state('rules')).toEqual({
94-
left: { license: 'Apache-2.0' },
95-
conjunction: 'or',
96-
right: {
97-
left: { left: { license: 'MIT' }, conjunction: 'and', right: { license: 'GPL-1.0-only' } },
98-
conjunction: 'or',
99-
right: { license: 'MIT' }
100-
}
101-
})
102-
})
103-
it('given an existing License, add a mew rule conjunction OR to right-right path', () => {
104-
const testLicense = 'Apache-2.0 OR (MIT OR GPL-1.0-only) AND MIT'
105-
const wrapper = shallow(<LicensePicker value={testLicense} />)
106-
const instance = wrapper.instance()
107-
instance.changeRulesConjunction('or', ['right', 'right'])
108-
expect(wrapper.state('rules')).toEqual({
109-
left: { license: 'Apache-2.0' },
110-
conjunction: 'or',
111-
right: {
112-
left: {
113-
left: { left: { license: 'MIT' }, conjunction: 'or', right: { license: 'GPL-1.0-only' } },
114-
conjunction: 'and',
115-
right: { license: 'MIT' }
116-
},
117-
conjunction: 'or',
118-
right: { license: '' }
119-
}
120-
})
121-
})
122-
it('given an existing License, add a new rule conjunction AND to right-right path', () => {
123-
const testLicense = 'Apache-2.0 OR (MIT OR GPL-1.0-only) AND (MIT OR GPL-1.0-only)'
124-
const wrapper = shallow(<LicensePicker value={testLicense} />)
125-
const instance = wrapper.instance()
126-
instance.changeRulesConjunction('and', ['right', 'right'])
127-
expect(wrapper.state('rules')).toEqual({
128-
left: { license: 'Apache-2.0' },
129-
conjunction: 'or',
130-
right: {
131-
left: { left: { license: 'MIT' }, conjunction: 'or', right: { license: 'GPL-1.0-only' } },
132-
conjunction: 'and',
133-
right: { left: { license: 'MIT' }, conjunction: 'and', right: { license: 'GPL-1.0-only' } }
134-
}
135-
})
136-
})
137-
it('given an existing License, add a new rule conjunction AND to right-left-right path', () => {
138-
const testLicense = 'Apache-2.0 OR (MIT OR GPL-1.0-only OR MIT-0) AND (MIT OR GPL-1.0-only)'
139-
const wrapper = shallow(<LicensePicker value={testLicense} />)
140-
const instance = wrapper.instance()
141-
instance.changeRulesConjunction('and', ['right', 'left', 'right'])
142-
expect(wrapper.state('rules')).toEqual({
143-
left: { license: 'Apache-2.0' },
144-
conjunction: 'or',
145-
right: {
146-
left: {
147-
left: { license: 'MIT' },
148-
conjunction: 'or',
149-
right: { left: { license: 'GPL-1.0-only' }, conjunction: 'and', right: { license: 'MIT-0' } }
150-
},
151-
conjunction: 'and',
152-
right: { left: { license: 'MIT' }, conjunction: 'or', right: { license: 'GPL-1.0-only' } }
153-
}
154-
})
155-
})
156-
it('given an existing License, add a new rule conjunction OR to right-left-right path', () => {
157-
const testLicense = 'Apache-2.0 OR (MIT OR GPL-1.0-only) AND (MIT OR GPL-1.0-only)'
158-
const wrapper = shallow(<LicensePicker value={testLicense} />)
159-
const instance = wrapper.instance()
160-
instance.changeRulesConjunction('or', ['right', 'left', 'right'])
161-
expect(wrapper.state('rules')).toEqual({
162-
left: { license: 'Apache-2.0' },
163-
conjunction: 'or',
164-
right: {
165-
left: {
166-
left: { license: 'MIT' },
167-
conjunction: 'or',
168-
right: { left: { license: 'GPL-1.0-only' }, conjunction: 'or', right: { license: '' } }
169-
},
170-
conjunction: 'and',
171-
right: { left: { license: 'MIT' }, conjunction: 'or', right: { license: 'GPL-1.0-only' } }
172-
}
173-
})
174-
})
175-
it('add a new group', () => {
176-
const testLicense = 'Apache-2.0'
177-
const wrapper = shallow(<LicensePicker value={testLicense} />)
178-
const instance = wrapper.instance()
179-
instance.addNewGroup([])
180-
expect(wrapper.state('rules')).toEqual({
181-
left: { license: 'Apache-2.0' },
182-
conjunction: 'and',
183-
right: {
184-
left: { license: '' },
185-
conjunction: 'and',
186-
right: { license: '' }
187-
}
188-
})
189-
})
190-
it('add a new nested group', () => {
191-
const testLicense = 'Apache-2.0 OR (MIT OR GPL-1.0-only)'
192-
const wrapper = shallow(<LicensePicker value={testLicense} />)
193-
const instance = wrapper.instance()
194-
instance.addNewGroup(['right'])
195-
expect(wrapper.state('rules')).toEqual({
196-
left: { license: 'Apache-2.0' },
197-
conjunction: 'or',
198-
right: {
199-
left: { license: 'MIT' },
200-
conjunction: 'or',
201-
right: {
202-
left: { license: 'GPL-1.0-only' },
203-
conjunction: 'or',
204-
right: { left: { license: '' }, conjunction: 'and', right: { license: '' } }
205-
}
206-
}
207-
})
208-
})
209-
it('set the license with later version', () => {
210-
const testLicense = 'Apache-2.0'
211-
const wrapper = shallow(<LicensePicker value={testLicense} />)
212-
const instance = wrapper.instance()
213-
instance.considerLaterVersions(true, [])
214-
expect(wrapper.state('rules')).toEqual({ license: 'Apache-2.0', plus: true })
9+
10+
it('renders with a license value', () => {
11+
render(<LicensePicker value="Apache-2.0 AND MIT" />)
21512
})
216-
it('removes a rule', () => {
217-
const testLicense = 'Apache-2.0 OR MIT'
218-
const wrapper = shallow(<LicensePicker value={testLicense} />)
219-
const instance = wrapper.instance()
220-
instance.removeRule(['right'])
221-
expect(wrapper.state('rules')).toEqual({ license: 'Apache-2.0' })
13+
14+
it('renders with NOASSERTION license', () => {
15+
render(<LicensePicker value="NOASSERTION" />)
22216
})
223-
it('change the value of a license', () => {
224-
const testLicense = 'Apache-2.0'
225-
const wrapper = shallow(<LicensePicker value={testLicense} />)
226-
const instance = wrapper.instance()
227-
instance.updateLicense('MIT', [])
228-
expect(wrapper.state('rules')).toEqual({ license: 'MIT' })
17+
18+
it('renders with complex license expression', () => {
19+
render(<LicensePicker value="Apache-2.0 OR (MIT AND GPL-1.0-only)" />)
22920
})
23021
})

0 commit comments

Comments
 (0)