Skip to content

Commit b025e1e

Browse files
committed
Show reminder for custom employers
1 parent 84f7aa5 commit b025e1e

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

e2e/integration/journey.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ it('can create a new employer', () => {
131131
'Weyland Yutani{enter}'
132132
)
133133
cy.findByText('Weyland Yutani').should('exist')
134+
cy.findByText(/Make sure you typed it correctly\./).should('exist')
134135
})
135136

136137
const setExperience = (topic, level) => {

src/Components/forms/index.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@
200200
padding: 10px;
201201
font-size: 20px;
202202
}
203+
.reminder {
204+
color: darkgreen;
205+
font-weight: bold;
206+
}
203207
@media screen and (max-width: 1000px) {
204208
.media {
205209
display: block;

src/Components/forms/inputs/EmployerDropDown.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { Label } from 'reactstrap'
33
import Select from 'react-select/creatable'
44

55
const EmployerDropDown = ({ arrayList, isEmpty, onChange, value }) => {
6+
const [customEntry, setCustomEntry] = useState(false)
67
const [employersList, setEmployersList] = useState([])
8+
79
useEffect(() => {
810
setEmployersList(
911
arrayList.map(({ _id, name }) => ({
@@ -12,10 +14,18 @@ const EmployerDropDown = ({ arrayList, isEmpty, onChange, value }) => {
1214
}))
1315
)
1416
}, [arrayList])
17+
18+
useEffect(() => {
19+
setCustomEntry(
20+
value !== '' && !arrayList.some(({ name }) => name === value)
21+
)
22+
}, [arrayList, value])
23+
1524
const handleChange = e =>
1625
onChange({
1726
target: { name: 'employer', type: 'text', value: e.value }
1827
})
28+
1929
return (
2030
<div className="form-group">
2131
<Label htmlFor="employer">Who is your employer? *</Label>
@@ -33,6 +43,12 @@ const EmployerDropDown = ({ arrayList, isEmpty, onChange, value }) => {
3343
placeholder="Type your employer name here"
3444
value={employersList.find(employer => employer.value === value)}
3545
/>
46+
{customEntry && (
47+
<p className="reminder">
48+
This employer will be added to our list. Make sure you typed it
49+
correctly.
50+
</p>
51+
)}
3652
</div>
3753
)
3854
}

src/Components/forms/inputs/EmployerDropDown.test.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,26 @@ describe('EmployerDropDown', () => {
103103
])
104104
})
105105

106+
describe('reminder', () => {
107+
const reminder =
108+
'This employer will be added to our list. Make sure you typed it correctly.'
109+
110+
it('does not show message when no value is entered', () => {
111+
renderInForm({ employers: ['ABC', 'BBC', 'CBC'], value: '' })
112+
expect(screen.queryByText(reminder)).not.toBeInTheDocument()
113+
})
114+
115+
it('does not show message when employer is in list', () => {
116+
renderInForm({ employers: ['ABC', 'BBC', 'CBC'], value: 'BBC' })
117+
expect(screen.queryByText(reminder)).not.toBeInTheDocument()
118+
})
119+
120+
it('shows message when employer is custom entry', () => {
121+
renderInForm({ employers: ['ABC', 'BBC', 'CBC'], value: 'Google' })
122+
expect(screen.queryByText(reminder)).toBeInTheDocument()
123+
})
124+
})
125+
106126
it('shows the expected values in AC', async () => {
107127
const { user } = renderInForm({
108128
employers: [
@@ -158,7 +178,8 @@ describe('EmployerDropDown', () => {
158178
const renderInForm = ({
159179
employers = [],
160180
isEmpty = false,
161-
onChange = () => {}
181+
onChange = () => {},
182+
value = ''
162183
}) => {
163184
const user = userEvent.setup()
164185
const wrapper = render(
@@ -168,6 +189,7 @@ const renderInForm = ({
168189
isEmpty={isEmpty}
169190
name="employer"
170191
onChange={onChange}
192+
value={value}
171193
/>
172194
</form>
173195
)

0 commit comments

Comments
 (0)