Skip to content

Commit 515e77d

Browse files
feat(cypress select tests): added tests for select component using cypress
1 parent 3a7a31b commit 515e77d

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import {
2+
SelectMarker,
3+
SelectListBox,
4+
SelectGroup,
5+
SelectOption,
6+
SelectRoot,
7+
SelectLabel,
8+
SelectTrigger,
9+
SelectValue,
10+
} from './select';
11+
import { component$ } from '@builder.io/qwik';
12+
13+
const ThreeOptionSelect = component$(() => {
14+
return (
15+
<>
16+
<SelectRoot data-testid="selectRoot">
17+
<SelectLabel>Label for Select</SelectLabel>
18+
<SelectTrigger data-testid="selectTrigger">
19+
<SelectValue data-testid="selectValue" placeholder="Placeholder">
20+
Select an option
21+
</SelectValue>
22+
<SelectMarker>
23+
<svg
24+
xmlns="http://www.w3.org/2000/svg"
25+
viewBox="0 0 24 24"
26+
fill="none"
27+
stroke="currentColor"
28+
stroke-width="2"
29+
stroke-linecap="round"
30+
stroke-linejoin="round"
31+
style="width: 20px; height: 20px;"
32+
>
33+
<polyline points="6 9 12 15 18 9"></polyline>
34+
</svg>
35+
</SelectMarker>
36+
</SelectTrigger>
37+
<SelectListBox data-testid="listBox">
38+
<SelectGroup>
39+
<SelectOption value="One">Option 1</SelectOption>
40+
<SelectOption data-testid="selectOptionTwo" value="Two">
41+
Option 2
42+
</SelectOption>
43+
<SelectOption value="Three">Option 3</SelectOption>
44+
</SelectGroup>
45+
</SelectListBox>
46+
</SelectRoot>
47+
</>
48+
);
49+
});
50+
51+
describe('Select', () => {
52+
it('INIT', () => {
53+
cy.mount(<ThreeOptionSelect />);
54+
55+
cy.checkA11yForComponent();
56+
});
57+
58+
it('should render the component', () => {
59+
cy.mount(<ThreeOptionSelect />);
60+
61+
cy.findByTestId('selectRoot').should('be.visible');
62+
});
63+
64+
it('should toggle aria-expanded and the listbox should be visible', () => {
65+
cy.mount(<ThreeOptionSelect />);
66+
67+
cy.findByTestId('selectTrigger')
68+
.click()
69+
.should('have.attr', 'aria-expanded');
70+
71+
cy.findByRole('listbox').should('exist');
72+
});
73+
74+
it('should toggle aria-expanded and the listbox should be hidden', () => {
75+
cy.mount(<ThreeOptionSelect />);
76+
77+
cy.get('button').click().should('have.attr', 'aria-expanded', 'true');
78+
79+
// current passed test for now. doesn't work with click for some reason
80+
cy.get('button')
81+
.focus()
82+
.type('{enter}')
83+
.should('have.attr', 'aria-expanded', 'false');
84+
85+
cy.findByRole('listbox').should('not.exist');
86+
});
87+
88+
it('should use the arrow keys to navigate options', () => {
89+
cy.mount(<ThreeOptionSelect />);
90+
91+
cy.findByTestId('selectTrigger').type('{enter}');
92+
93+
cy.findByRole('listbox').should('be.visible');
94+
95+
cy.findByRole('group').type('{downarrow}');
96+
97+
cy.findByTestId('selectOptionTwo').type('{enter}').should('not.be.visible');
98+
99+
cy.findByTestId('selectValue').should('have.text', 'Two');
100+
});
101+
});

0 commit comments

Comments
 (0)