Skip to content

Commit 1329953

Browse files
authored
Merge pull request #133 from CodeYourFuture/692-volunteer-should-identify-which-team-they-want-to-be-part-in
Volunteer-team-preference
2 parents feb0e5c + fc740db commit 1329953

File tree

7 files changed

+205
-5
lines changed

7 files changed

+205
-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: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,29 @@ 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+
this.props.loadCities()
22+
}
23+
24+
fetchTeamData = async () => {
25+
try {
26+
const response = await axios.get(`${domain()}/teams`)
27+
const teamData = response.data.teams
28+
teamData.sort((a, b) => a.name.localeCompare(b.name))
29+
30+
this.setState({ teamOptions: teamData })
31+
} catch (err) {
32+
return this.setState({
33+
err: 'Sorry, we are currently experiencing technical issues, please try again later.'
34+
})
35+
}
36+
}
1537

1638
handleMagicLinkRequest = async e => {
1739
e.preventDefault()
@@ -88,17 +110,24 @@ class Forms extends Component {
88110
const { name, value, type, checked } = e.target
89111
const { errors } = this.state
90112
errors[name] = false
91-
if (e && e.target) {
113+
114+
// Handle teamId separately
115+
if (name === 'teamId') {
116+
this.setState({ teamId: value })
117+
} else {
118+
// Handle other form fields
92119
this.setState({
93120
[name]: type === 'checkbox' ? checked : value,
94121
submitted: false,
95122
errors,
96123
formInComplete: false,
97124
err: null
98125
})
99-
}
100-
if (name === 'hearAboutCYF') {
101-
this.setState({ hearAboutCYFFromEmployer: value === 'Employer' })
126+
127+
// Check for special case where name is 'hearAboutCYF'
128+
if (name === 'hearAboutCYF') {
129+
this.setState({ hearAboutCYFFromEmployer: value === 'Employer' })
130+
}
102131
}
103132
}
104133

@@ -150,6 +179,7 @@ class Forms extends Component {
150179
email,
151180
tel,
152181
cityId,
182+
teamId,
153183
interestedInVolunteer,
154184
interestedInCYF,
155185
industry,
@@ -169,6 +199,7 @@ class Forms extends Component {
169199
lastName,
170200
email,
171201
cityId,
202+
teamId,
172203
employer: hearAboutCYFFromEmployer ? employer : true,
173204
interestedInVolunteer,
174205
tel,
@@ -190,6 +221,7 @@ class Forms extends Component {
190221
email,
191222
tel,
192223
cityId,
224+
teamId,
193225
interestedInVolunteer,
194226
interestedInCYF,
195227
industry,
@@ -361,6 +393,7 @@ class Forms extends Component {
361393
onChange={this.onChange}
362394
telOnChange={this.telOnChange}
363395
onChangeCheckList={this.onChangeCheckList}
396+
teamOptions={this.state.teamOptions}
364397
{...this.props}
365398
{...this.state}
366399
/>

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)