Skip to content

Commit 9fc2837

Browse files
committed
Add test for AutoFillDropDown
1 parent 4a94b87 commit 9fc2837

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import '@testing-library/jest-dom' // this should go in ./src/setupTests.js
2+
import { render, screen } from '@testing-library/react'
3+
import userEvent from '@testing-library/user-event'
4+
import exampleData from '../data.json'
5+
import AutoFillDropDown from './AutoFillDropDown'
6+
7+
describe('AutoFillDropDown', () => {
8+
describe('AutoFillDropDown', () => {
9+
it('shows a matching option for specific word', async () => {
10+
const user = userEvent.setup()
11+
render(
12+
<AutoFillDropDown
13+
arrayList={exampleData.employerList}
14+
employerOnChange={() => {}}
15+
isEmpty={false}
16+
label="Employer"
17+
name="employer"
18+
/>
19+
)
20+
21+
await user.type(
22+
screen.getByRole('textbox', { name: /employer/i }),
23+
'capgemini'
24+
)
25+
26+
expect(
27+
screen.getByRole('option', { name: /capgemini/i })
28+
).toBeInTheDocument()
29+
})
30+
expect(
31+
screen.queryByRole('option', { name: /Carnall Farrar/i })
32+
).not.toBeInTheDocument()
33+
})
34+
it('finds characters within words', async () => {
35+
const user = userEvent.setup()
36+
render(
37+
<AutoFillDropDown
38+
arrayList={exampleData.employerList}
39+
employerOnChange={() => {}}
40+
isEmpty={false}
41+
name="employer"
42+
label="Employer"
43+
/>
44+
)
45+
46+
await user.type(screen.getByRole('textbox', { name: /employer/i }), 'am')
47+
48+
expect(
49+
screen.getByRole('option', { name: 'Amazon Web Services (AWS)' })
50+
).toBeInTheDocument()
51+
expect(screen.getByRole('option', { name: 'Amazon' })).toBeInTheDocument()
52+
expect(
53+
screen.getByRole('option', { name: /American/i })
54+
).toBeInTheDocument()
55+
expect(screen.getByRole('option', { name: 'Beamery' })).toBeInTheDocument()
56+
expect(
57+
screen.getByRole('option', { name: 'Blueprint Gaming' })
58+
).toBeInTheDocument()
59+
expect(screen.getByRole('option', { name: /EPAM/i })).toBeInTheDocument()
60+
expect(
61+
screen.getByRole('option', { name: /Inspired Gaming /i })
62+
).toBeInTheDocument()
63+
expect(
64+
screen.getByRole('option', { name: 'Tamarix Tech' })
65+
).toBeInTheDocument()
66+
67+
expect(
68+
screen.queryByRole('option', { name: 'bmc' })
69+
).not.toBeInTheDocument()
70+
expect(
71+
screen.queryByRole('option', { name: 'Alpha FX Group' })
72+
).not.toBeInTheDocument()
73+
expect(
74+
screen.queryByRole('option', { name: 'BBC' })
75+
).not.toBeInTheDocument()
76+
})
77+
expect(
78+
screen.queryByRole('option', { name: 'Blue Frontier' })
79+
).not.toBeInTheDocument()
80+
81+
expect(
82+
screen.queryByRole('option', { name: 'Brandwatch' })
83+
).not.toBeInTheDocument()
84+
expect(
85+
screen.queryByRole('option', { name: 'EngineerBetter' })
86+
).not.toBeInTheDocument()
87+
expect(
88+
screen.queryByRole('option', { name: 'Equal Experts' })
89+
).not.toBeInTheDocument()
90+
expect(
91+
screen.queryByRole('option', { name: 'Infobip' })
92+
).not.toBeInTheDocument()
93+
expect(
94+
screen.queryByRole('option', { name: 'Synaptik Digital' })
95+
).not.toBeInTheDocument()
96+
expect(
97+
screen.queryByRole('option', { name: 'Tata Consultancy services' })
98+
).not.toBeInTheDocument()
99+
})

0 commit comments

Comments
 (0)