Skip to content

Commit 43c11f3

Browse files
authored
Merge pull request #134 from CodeYourFuture/692-volunteer-should-identify-which-team-they-want-to-be-part-in
Volunteer-team-preference [Staging]
2 parents 737a4ab + 40ddaff commit 43c11f3

File tree

7 files changed

+204
-5
lines changed

7 files changed

+204
-5
lines changed

e2e/fixtures/teams.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"teams": [
3+
{
4+
"_id": "5e863b833150f6001b34627d",
5+
"global": "false",
6+
"name": "Education",
7+
"cityId": "5cefa67c071d210018e3dccf",
8+
"description": "EDU",
9+
"__v": 0,
10+
"leaderEmail": "[email protected]"
11+
}
12+
]
13+
}

e2e/integration/journey.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ beforeEach(() => {
44
cy.intercept('GET', `${mockServerURL}/cities?visibleIn=VOLUNTEER_FORM`, {
55
fixture: 'cities.json'
66
})
7+
cy.intercept('GET', `${mockServerURL}/teams`, {
8+
fixture: 'teams.json'
9+
})
710
cy.visit('/')
811
})
912

@@ -25,6 +28,9 @@ it('can submit a minimal form', () => {
2528
cy.findByRole('textbox', { name: /first name/i }).type(initialData.firstName)
2629
cy.findByRole('textbox', { name: /last name/i }).type(initialData.lastName)
2730
cy.findByRole('combobox', { name: /city/i }).select('London')
31+
cy.findByRole('combobox', {
32+
name: /select the team you want to volunteer for/i
33+
}).select('Education')
2834
cy.findByRole('textbox', { name: /email/i }).type(initialData.email)
2935
cy.findByRole('textbox', { name: /phone number/i }).type(initialData.tel)
3036
cy.findByRole('textbox', { name: /interested in volunteering/i }).type(
@@ -98,6 +104,9 @@ it('requires employee selection', () => {
98104
cy.findByRole('textbox', { name: /first name/i }).type('Laura')
99105
cy.findByRole('textbox', { name: /last name/i }).type('Olsen')
100106
cy.findByRole('combobox', { name: /city/i }).select('London')
107+
cy.findByRole('combobox', {
108+
name: /select the team you want to volunteer for/i
109+
}).select('5e863b833150f6001b34627d')
101110
cy.findByRole('textbox', { name: /email/i }).type('[email protected]')
102111
cy.findByRole('textbox', { name: /phone number/i }).type('96838503')
103112
cy.findByRole('textbox', { name: /interested in volunteering/i }).type('just')

e2e/integration/withCode.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ beforeEach(() => {
44
cy.intercept('GET', `${mockServerURL}/cities?visibleIn=VOLUNTEER_FORM`, {
55
fixture: 'cities.json'
66
})
7+
cy.intercept('GET', `${mockServerURL}/teams`, {
8+
fixture: 'teams.json'
9+
})
710
})
811

912
it('shows success message', () => {
@@ -25,6 +28,9 @@ it('includes the user ID when resubmitting', () => {
2528
cy.findByRole('textbox', { name: /email/i }).type(
2629
2730
)
31+
cy.findByRole('combobox', {
32+
name: /select the team you want to volunteer for/i
33+
}).select('Education')
2834
cy.findByRole('textbox', { name: /phone number/i }).type('0158-8969905')
2935
cy.findByRole('textbox', { name: /interested in volunteering/i }).type('just')
3036
cy.findByRole('textbox', { name: /interested in code your future/i }).type(

src/Components/forms/helper.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const initialState = {
1010
interestedInCYF: '',
1111
industry: '',
1212
hearAboutCYF: '',
13+
teamId: '',
1314
hearAboutCYFFromEmployer: false,
1415
employer: '',
1516
guidePeople: ListsData.guidePeopleSkillList,
@@ -33,6 +34,7 @@ export const initialState = {
3334
email: false,
3435
city: false,
3536
cityId: false,
37+
teamId: false,
3638
interestedInVolunteer: false,
3739
interestedInCYF: false,
3840
agreeToTOU: false,

src/Components/forms/index.js

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,28 @@ import './index.css'
1111

1212
const path = `${domain()}${appPath}`
1313
class Forms extends Component {
14-
state = initialState
14+
state = {
15+
teamOptions: [],
16+
...initialState
17+
}
18+
19+
componentDidMount() {
20+
this.fetchTeamData()
21+
}
22+
23+
fetchTeamData = async () => {
24+
try {
25+
const response = await axios.get(`${domain()}/teams`)
26+
const teamData = response.data.teams
27+
teamData.sort((a, b) => a.name.localeCompare(b.name))
28+
29+
this.setState({ teamOptions: teamData })
30+
} catch (err) {
31+
return this.setState({
32+
err: 'Sorry, we are currently experiencing technical issues, please try again later.'
33+
})
34+
}
35+
}
1536

1637
handleMagicLinkRequest = async e => {
1738
e.preventDefault()
@@ -88,17 +109,24 @@ class Forms extends Component {
88109
const { name, value, type, checked } = e.target
89110
const { errors } = this.state
90111
errors[name] = false
91-
if (e && e.target) {
112+
113+
// Handle teamId separately
114+
if (name === 'teamId') {
115+
this.setState({ teamId: value })
116+
} else {
117+
// Handle other form fields
92118
this.setState({
93119
[name]: type === 'checkbox' ? checked : value,
94120
submitted: false,
95121
errors,
96122
formInComplete: false,
97123
err: null
98124
})
99-
}
100-
if (name === 'hearAboutCYF') {
101-
this.setState({ hearAboutCYFFromEmployer: value === 'Employer' })
125+
126+
// Check for special case where name is 'hearAboutCYF'
127+
if (name === 'hearAboutCYF') {
128+
this.setState({ hearAboutCYFFromEmployer: value === 'Employer' })
129+
}
102130
}
103131
}
104132

@@ -150,6 +178,7 @@ class Forms extends Component {
150178
email,
151179
tel,
152180
cityId,
181+
teamId,
153182
interestedInVolunteer,
154183
interestedInCYF,
155184
industry,
@@ -169,6 +198,7 @@ class Forms extends Component {
169198
lastName,
170199
email,
171200
cityId,
201+
teamId,
172202
employer: hearAboutCYFFromEmployer ? employer : true,
173203
interestedInVolunteer,
174204
tel,
@@ -190,6 +220,7 @@ class Forms extends Component {
190220
email,
191221
tel,
192222
cityId,
223+
teamId,
193224
interestedInVolunteer,
194225
interestedInCYF,
195226
industry,
@@ -361,6 +392,7 @@ class Forms extends Component {
361392
onChange={this.onChange}
362393
telOnChange={this.telOnChange}
363394
onChangeCheckList={this.onChangeCheckList}
395+
teamOptions={this.state.teamOptions}
364396
{...this.props}
365397
{...this.state}
366398
/>

src/Components/forms/inputs/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export default class VolunteerForm extends Component {
1717
tel,
1818
cities,
1919
cityId,
20+
teamId,
21+
teamOptions,
2022
email,
2123
telOnChange,
2224
errors,
@@ -104,6 +106,27 @@ export default class VolunteerForm extends Component {
104106
placeholder="Just one or two sentences as required..."
105107
type="textarea"
106108
/>
109+
<DropDown
110+
onChange={onChange}
111+
value={teamId}
112+
name="teamId"
113+
arrayList={teamOptions}
114+
isEmpty={errors.teamId}
115+
label={
116+
<span>
117+
Please select the team you want to volunteer for. You can read
118+
about the teams on this
119+
<a
120+
href="https://codeyourfuture.io/volunteers/"
121+
target="_blank"
122+
rel="noopener noreferrer"
123+
>
124+
{' '}
125+
page
126+
</a>
127+
</span>
128+
}
129+
/>
107130
<DropDown
108131
onChange={onChange}
109132
value={industry}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import React from 'react'
2+
import { render, screen, fireEvent } from '@testing-library/react'
3+
import DropDown from './dropDown'
4+
5+
const teamOptions = [
6+
{ _id: 'team0', name: 'Select here' },
7+
{ _id: 'team1', name: 'Education' },
8+
{ _id: 'team2', name: 'Mentorship' },
9+
{ _id: 'team3', name: 'Outreach' },
10+
{ _id: 'team4', name: 'Personal Development' },
11+
{ _id: 'team5', name: 'Tech Project' }
12+
].map(team => ({ ...team, name: team.name.toLowerCase() }))
13+
14+
const errors = {
15+
teamId: false
16+
}
17+
18+
const VolunteerForm = ({ teamOptions }) => {
19+
return (
20+
<form data-testid="testId">
21+
<DropDown
22+
onChange={() => {}}
23+
value=""
24+
name="teamId"
25+
arrayList={teamOptions}
26+
isEmpty={errors.teamId}
27+
label={
28+
<span>
29+
Please select the team you want to volunteer for. You can read about
30+
the teams on this
31+
<a
32+
href="https://codeyourfuture.io/volunteers/"
33+
target="_blank"
34+
rel="noopener noreferrer"
35+
>
36+
{' '}
37+
page
38+
</a>
39+
</span>
40+
}
41+
/>
42+
</form>
43+
)
44+
}
45+
46+
describe('Volunteer-team-preference', () => {
47+
// Testing form content
48+
it('testing form', () => {
49+
render(<VolunteerForm teamOptions={teamOptions} />)
50+
expect(screen.getByTestId('testId')).toHaveTextContent(
51+
'Please select the team you want to volunteer for.'
52+
)
53+
})
54+
55+
// Test to see if we can open a new tab
56+
it('Opening CYF page in a new tab/page', () => {
57+
render(<VolunteerForm teamOptions={teamOptions} />)
58+
const linkElement = screen.getByText('page')
59+
expect(linkElement).toHaveAttribute(
60+
'href',
61+
'https://codeyourfuture.io/volunteers/'
62+
)
63+
expect(linkElement).toHaveAttribute('target', '_blank')
64+
})
65+
66+
it('team options are correctly displayed in the dropdown', () => {
67+
render(<VolunteerForm teamOptions={teamOptions} />)
68+
teamOptions.forEach(option => {
69+
const selectOptions = screen.queryAllByText(option.name)
70+
selectOptions.forEach(selectOption => {
71+
expect(selectOption).toBeInTheDocument()
72+
})
73+
})
74+
})
75+
76+
it('new volunteer cannot skip this question', () => {
77+
render(<VolunteerForm teamOptions={teamOptions} />)
78+
const selectElement = screen.getByLabelText(
79+
/Please select the team you want to volunteer for/i
80+
)
81+
fireEvent.change(selectElement, { target: { value: '' } })
82+
fireEvent.blur(selectElement)
83+
expect(screen.getByTestId('testId')).toHaveTextContent(
84+
'Please select the team you want to volunteer for.'
85+
)
86+
})
87+
88+
// Check if the teams are in alphabetical order
89+
it('form updates with new team', () => {
90+
const newTeam = { _id: 'team6', name: 'New Team' }
91+
const updatedTeamOptions = [...teamOptions, newTeam]
92+
render(<VolunteerForm teamOptions={updatedTeamOptions} />)
93+
const selectElement = screen.getByLabelText(
94+
/Please select the team you want to volunteer for/i
95+
)
96+
expect(selectElement).toContainHTML(
97+
'<option value="team6">New Team</option>'
98+
)
99+
})
100+
101+
it('form updates with deleted team', () => {
102+
const deletedTeam = { _id: 'team1', name: 'Education' }
103+
const updatedTeamOptions = teamOptions.filter(
104+
team => team._id !== deletedTeam._id
105+
)
106+
render(<VolunteerForm teamOptions={updatedTeamOptions} />)
107+
const selectElement = screen.getByLabelText(
108+
/Please select the team you want to volunteer for/i
109+
)
110+
expect(selectElement).not.toContainHTML(
111+
'<option value="team1">Education</option>'
112+
)
113+
})
114+
})

0 commit comments

Comments
 (0)