Skip to content

Commit 3f5b51c

Browse files
authored
Merge pull request #112 from CodeYourFuture/feature/Change-searching-of-employer-names-on-Volunteer-form-to-auto-fill#595
Feature/change searching of employer names on volunteer form to auto fill#595 [STAGING]
2 parents 1336a10 + c9f3c78 commit 3f5b51c

File tree

9 files changed

+1779
-1057
lines changed

9 files changed

+1779
-1057
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jobs:
4343
- ~/.cache
4444
- run: yarn lint
4545
- run: yarn e2e:prod
46+
- run: yarn test
4647
build:
4748
docker:
4849
- image: cimg/node:16.17.1

e2e/integration/journey.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ it('requires employee selection', () => {
112112
)
113113
cy.findByRole('button', { name: /submit/i }).click()
114114
cy.findByText(/form is incomplete/i).should('exist')
115-
116-
cy.findByRole('combobox', { name: /who is your employer/i }).select(
117-
'Capgemini'
115+
cy.findByRole('combobox', { name: /who is your employer/i }).type(
116+
'Cap{enter}'
118117
)
119118
cy.findByRole('button', { name: /submit/i }).click()
120119

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"react-redux": "^8.0.4",
1313
"react-router-dom": "^6.4.2",
1414
"react-scripts": "5.0.1",
15+
"react-select": "^5.7.0",
1516
"reactstrap": "^8.0.1",
1617
"redux": "^4.0.4",
1718
"redux-thunk": "^2.3.0"
@@ -61,6 +62,9 @@
6162
},
6263
"devDependencies": {
6364
"@testing-library/cypress": "^8.0.3",
65+
"@testing-library/jest-dom": "^5.16.5",
66+
"@testing-library/react": "^13.4.0",
67+
"@testing-library/user-event": "^14.4.3",
6468
"concurrently": "^7.4.0",
6569
"cypress": "^10.9.0",
6670
"eslint-config-prettier": "^8.5.0",
@@ -70,6 +74,7 @@
7074
"lint-staged": "^13.0.3",
7175
"prettier": "^2.7.1",
7276
"pretty-quick": "^3.1.3",
77+
"react-select-event": "^5.5.1",
7378
"serve": "^14.0.1",
7479
"wait-on": "^6.0.1"
7580
},

src/Components/forms/data.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
{ "name": "And Digital", "_id": "And Digital" },
5454
{ "name": "Apolitical", "_id": "Apolitical" },
5555
{ "name": "Arnold Clark", "_id": "Arnold Clark" },
56+
{ "name": "Avaloq", "_id": "Avaloq" },
5657
{ "name": "Avanade", "_id": "Avanade" },
5758
{ "name": "Bankifi", "_id": "Bankifi" },
5859
{ "name": "BJSS", "_id": "BJSS" },
@@ -66,7 +67,9 @@
6667
{ "name": "Cord", "_id": "Cord" },
6768
{ "name": "Covatic", "_id": "Covatic" },
6869
{ "name": "DAI", "_id": "DAI" },
70+
{ "name": "Deliveroo", "_id": "Deliveroo" },
6971
{ "name": "Deloitte", "_id": "Deloitte" },
72+
{ "name": "DF Capital", "_id": "DF Capital" },
7073
{ "name": "Digital Cabinet Office", "_id": "Digital Cabinet Office" },
7174
{ "name": "EDF", "_id": "EDF" },
7275
{ "name": "EY (SA)", "_id": "EY (SA)" },
@@ -75,17 +78,23 @@
7578
{ "name": "FourKites", "_id": "FourKites" },
7679
{ "name": "Free Agent", "_id": "Free Agent" },
7780
{ "name": "G-Research", "_id": "G-Research" },
81+
{ "name": "Google", "_id": "Google" },
7882
{ "name": "Hackajob", "_id": "Hackajob" },
83+
{ "name": "Hippo Digital", "_id": "Hippo Digital" },
7984
{ "name": "Hired", "_id": "Hired" },
8085
{ "name": "Holoxica", "_id": "Holoxica" },
86+
{ "name": "Hudson River Trading", "_id": "Hudson River Trading" },
8187
{ "name": "Infinity Works", "_id": "Infinity Works" },
8288
{ "name": "Jaguar LandRover", "_id": "Jaguar LandRover" },
8389
{ "name": "K+C", "_id": "K+C" },
8490
{ "name": "KrakenFlex", "_id": "KrakenFlex" },
8591
{ "name": "Lush", "_id": "Lush" },
8692
{ "name": "LVNDR", "_id": "LVNDR" },
93+
{ "name": "Made", "_id": "Made" },
8794
{ "name": "MadeTech", "_id": "MadeTech" },
8895
{ "name": "Makers", "_id": "Makers" },
96+
{ "name": "Meta", "_id": "Meta" },
97+
{ "name": "Microsoft", "_id": "Microsoft" },
8998
{ "name": "Multitudes", "_id": "Multitudes" },
9099
{ "name": "Multiverse", "_id": "Multiverse" },
91100
{ "name": "MVF", "_id": "MVF" },
@@ -103,6 +112,7 @@
103112
{ "name": "RoundCorp", "_id": "RoundCorp" },
104113
{ "name": "Scottish Power", "_id": "Scottish Power" },
105114
{ "name": "Shopify", "_id": "Shopify" },
115+
{ "name": "Slack", "_id": "Slack" },
106116
{ "name": "Sopra Steria", "_id": "Sopra Steria" },
107117
{ "name": "Stitch", "_id": "Stitch" },
108118
{ "name": "Substakt", "_id": "Substakt" },
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from 'react'
2+
import { Label } from 'reactstrap'
3+
import Select from 'react-select'
4+
5+
const EmployerDropDown = ({ onChange, isEmpty, arrayList }) => {
6+
const employersList = arrayList.map(({ _id, name }) => ({
7+
value: _id,
8+
label: name
9+
}))
10+
return (
11+
<div className="form-group">
12+
<Label htmlFor="employer">Who is your employer? *</Label>
13+
<Select
14+
className={isEmpty ? 'is-empty' : ''}
15+
noOptionsMessage={() => 'Employer not found? Please select "Other".'}
16+
inputId="employer"
17+
isSearchable
18+
options={employersList}
19+
onChange={e =>
20+
onChange({
21+
target: { name: 'employer', type: 'text', value: e.value }
22+
})
23+
}
24+
name="employer"
25+
placeholder="Type your employer name here"
26+
/>
27+
</div>
28+
)
29+
}
30+
31+
export default EmployerDropDown
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import React from 'react'
2+
import { render, screen } from '@testing-library/react'
3+
import selectEvent from 'react-select-event'
4+
import '@testing-library/jest-dom'
5+
import userEvent from '@testing-library/user-event'
6+
import EmployerDropDown from './EmployerDropDown'
7+
8+
describe('EmployerDropDown', () => {
9+
it('shows the label value and place holder value', async () => {
10+
renderInForm({ employers: ['Arnold Clark'] })
11+
expect(screen.getByTestId('form')).toHaveTextContent(
12+
'Who is your employer? *'
13+
)
14+
expect(screen.getByTestId('form')).toHaveTextContent(
15+
'Type your employer name here'
16+
)
17+
})
18+
it('renders an input', async () => {
19+
renderInForm({ employers: ['Arnold Clark', 'Bankifi', 'Capgemini'] })
20+
await selectEvent.select(
21+
screen.getByLabelText(/who is your employer/i),
22+
'Capgemini'
23+
)
24+
expect(screen.getByTestId('form')).toHaveFormValues({
25+
employer: 'Capgemini'
26+
})
27+
})
28+
29+
it('updates the rest of the form', async () => {
30+
const onChange = jest.fn()
31+
renderInForm({ employers: ['Deloitte', 'EDF', 'FlexJobs'], onChange })
32+
await selectEvent.select(
33+
screen.getByLabelText(/who is your employer/i),
34+
'EDF'
35+
)
36+
expect(onChange).toHaveBeenCalledWith({
37+
target: expect.objectContaining({
38+
name: 'employer',
39+
type: 'text',
40+
value: 'EDF'
41+
})
42+
})
43+
})
44+
45+
it('applies the right class when empty', async () => {
46+
const { container } = renderInForm({ isEmpty: true })
47+
expect(container.getElementsByClassName('is-empty')).toHaveLength(1)
48+
})
49+
50+
it('asks user to select "Other" if no matches', async () => {
51+
const { user } = renderInForm({ employers: ['G-Research'] })
52+
await user.type(screen.getByRole('combobox', { name: /employer/i }), 'cap')
53+
expect(
54+
screen.getByText('Employer not found? Please select "Other".')
55+
).toBeInTheDocument()
56+
})
57+
58+
it('shows the expected values in AC', async () => {
59+
const { user } = renderInForm({
60+
employers: [
61+
'BBC',
62+
'Bet365',
63+
'Blue Frontier',
64+
'EngineerBetter',
65+
'Brandwatch',
66+
'Equal Experts',
67+
'Infobip',
68+
'Synaptik Digital',
69+
'Tata Consultancy services',
70+
'Tamarix Tech',
71+
'Inspired Gaming Group',
72+
'EPAM System',
73+
'Blueprint Gaming',
74+
'Beamery',
75+
'American Express ',
76+
'Capgemini',
77+
'Amazon Web Services (AWS)',
78+
'Alpha FX Group',
79+
'Amazon',
80+
'Anaplan'
81+
]
82+
})
83+
await user.type(screen.getByRole('combobox', { name: /employer/i }), 'am')
84+
const appearingEmployers = [
85+
'Amazon',
86+
'Amazon Web Services (AWS)',
87+
'American Express',
88+
'Beamery',
89+
'Blueprint Gaming',
90+
'EPAM System',
91+
'Inspired Gaming Group',
92+
'Tamarix Tech'
93+
]
94+
95+
appearingEmployers.forEach(employer =>
96+
expect(screen.getByText(employer)).toBeInTheDocument()
97+
)
98+
})
99+
})
100+
const renderInForm = ({
101+
employers = [],
102+
isEmpty = false,
103+
onChange = () => {}
104+
}) => {
105+
const user = userEvent.setup()
106+
const wrapper = render(
107+
<form data-testid="form">
108+
<EmployerDropDown
109+
arrayList={employers.map(name => ({ _id: name, name }))}
110+
isEmpty={isEmpty}
111+
name="employer"
112+
onChange={onChange}
113+
/>
114+
</form>
115+
)
116+
return { user, ...wrapper }
117+
}

src/Components/forms/inputs/index.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import TextInput from './textInput'
66
import TextArea from './textArea'
77
import CheckListB from './checkListB'
88
import CheckListH from './checkListH'
9+
import EmployerDropDown from './EmployerDropDown'
910

1011
export default class VolunteerForm extends Component {
1112
render() {
@@ -28,8 +29,7 @@ export default class VolunteerForm extends Component {
2829
onChangeCheckList,
2930
guidePeople,
3031
techSkill,
31-
otherSkill,
32-
employer
32+
otherSkill
3333
} = this.props
3434

3535
return (
@@ -121,13 +121,10 @@ export default class VolunteerForm extends Component {
121121
label="Where did you hear about Code Your Future?"
122122
/>
123123
{hearAboutCYFFromEmployer && (
124-
<DropDown
124+
<EmployerDropDown
125125
onChange={onChange}
126-
value={employer}
127-
name="employer"
128126
arrayList={ListsData.employerList}
129127
isEmpty={errors.employer}
130-
label="Who is your employer? *"
131128
/>
132129
)}
133130
<span className="contact-interested">

src/setupTests.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/jest-dom'

0 commit comments

Comments
 (0)