@@ -6,28 +6,67 @@ const ARIA_ROLES = ['grid', 'listbox', 'menu', 'tree', 'tooltip', 'alertdialog',
6
6
7
7
describe ( 'useRole' , ( ) => {
8
8
it ( 'by default applies the "dialog" role to the floating element' , ( ) => {
9
- render ( App , { role : undefined } ) ;
9
+ render ( App , { role : undefined , open : true } ) ;
10
10
expect ( screen . queryByRole ( 'dialog' ) ) . toBeInTheDocument ( ) ;
11
11
cleanup ( ) ;
12
12
} ) ;
13
13
14
14
for ( const role of ARIA_ROLES ) {
15
15
it ( `applies the "${ role } " role to the floating element` , ( ) => {
16
- render ( App , { role } ) ;
16
+ render ( App , { role, open : true } ) ;
17
17
expect ( screen . queryByRole ( role ) ) . toBeInTheDocument ( ) ;
18
18
cleanup ( ) ;
19
19
} ) ;
20
20
}
21
21
22
- it . skip ( 'sets correct aria attributes based on the open state' , async ( ) => {
23
- const { rerender } = render ( App , { role : 'tooltip' , open : true } ) ;
22
+ describe ( 'tooltip' , ( ) => {
23
+ it . skip ( 'sets correct aria attributes based on the open state' , async ( ) => {
24
+ const { rerender } = render ( App , { role : 'tooltip' , open : true } ) ;
24
25
25
- expect ( screen . getByRole ( 'button' ) ) . toHaveAttribute ( 'aria-describedby' ) ;
26
+ expect ( screen . getByRole ( 'button' ) ) . toHaveAttribute (
27
+ 'aria-describedby' ,
28
+ screen . getByRole ( 'tooltip' ) . getAttribute ( 'id' )
29
+ ) ;
26
30
27
- await rerender ( { role : 'tooltip' , open : false } ) ;
31
+ await rerender ( { role : 'tooltip' , open : false } ) ;
28
32
29
- expect ( screen . getByRole ( 'buton' ) ) . not . toHaveAttribute ( 'aria-describedby' ) ;
33
+ expect ( screen . getByRole ( 'buton' ) ) . not . toHaveAttribute ( 'aria-describedby' ) ;
30
34
31
- cleanup ( ) ;
35
+ cleanup ( ) ;
36
+ } ) ;
37
+ } ) ;
38
+
39
+ describe ( 'label' , ( ) => {
40
+ it . skip ( 'sets correct aria attributes based on the open state' , async ( ) => {
41
+ const { rerender } = render ( App , { role : 'label' , open : true } ) ;
42
+
43
+ expect ( screen . getByRole ( 'button' ) ) . toHaveAttribute (
44
+ 'aria-labelledby' ,
45
+ screen . getByRole ( 'tooltip' ) . getAttribute ( 'id' )
46
+ ) ;
47
+
48
+ await rerender ( { role : 'tooltip' , open : false } ) ;
49
+
50
+ expect ( screen . getByRole ( 'buton' ) ) . not . toHaveAttribute ( 'aria-labelledby' ) ;
51
+
52
+ cleanup ( ) ;
53
+ } ) ;
54
+ } ) ;
55
+
56
+ describe ( 'dialog' , ( ) => {
57
+ it . skip ( 'sets correct aria attributes based on the open state' , async ( ) => {
58
+ const { rerender } = render ( App , { role : 'dialog' , open : false } ) ;
59
+
60
+ expect ( screen . getByRole ( 'button' ) ) . toHaveAttribute ( 'aria-haspopup' , 'dialog' ) ;
61
+ expect ( screen . getByRole ( 'button' ) ) . toHaveAttribute ( 'aria-expanded' , 'false' ) ;
62
+
63
+ await rerender ( { role : 'dialog' , open : true } ) ;
64
+
65
+ expect ( screen . getByRole ( 'dialog' ) ) . toBeInTheDocument ( ) ;
66
+ expect ( screen . getByRole ( 'button' ) ) . toHaveAttribute (
67
+ 'aria-controls' ,
68
+ screen . getByRole ( 'dialog' ) . getAttribute ( 'id' )
69
+ ) ;
70
+ } ) ;
32
71
} ) ;
33
72
} ) ;
0 commit comments