@@ -47,30 +47,23 @@ test('Renders expected items when opening the tutorials menu', async ({
4747 < Tutorials />
4848 </ TutorialProvider > ,
4949 {
50- routes : [ '/tutorial ' ] ,
51- initialEntries : [ '/tutorial ' ] ,
50+ routes : [ '/' ] ,
51+ initialEntries : [ '/' ] ,
5252 } ,
5353 { wrapper : Providers }
5454 ) ;
5555 const user = userEvent . setup ( ) ;
5656
57- await user . click ( screen . getByRole ( 'button' ) ) ;
57+ await user . click ( await screen . findByRole ( 'button' ) ) ;
5858
5959 await waitFor ( ( ) =>
60- expect (
61- screen . getByText ( `Available Tutorials (${ tutorials . length } )` )
62- ) . toBeInTheDocument ( )
60+ expect ( screen . getByText ( `Available Tutorials (1)` ) ) . toBeInTheDocument ( )
6361 ) ;
6462
6563 expect ( screen . getByText ( 'For current page' ) ) . toBeInTheDocument ( ) ;
66- expect ( screen . getByText ( 'For other pages' ) ) . toBeInTheDocument ( ) ;
67- expect ( screen . getByRole ( 'separator' ) ) . toBeInTheDocument ( ) ;
68-
69- for ( const tutorial of tutorials ) {
70- expect (
71- screen . getByRole ( 'button' , { name : tutorial . name } )
72- ) . toBeInTheDocument ( ) ;
73- }
64+ expect (
65+ screen . getByRole ( 'button' , { name : tutorials [ 0 ] . name } )
66+ ) . toBeInTheDocument ( ) ;
7467} ) ;
7568
7669test ( 'Hides expected tutorials when providing filter fn' , async ( {
@@ -83,8 +76,8 @@ test('Hides expected tutorials when providing filter fn', async ({
8376 < Tutorials filterTutorials = { filterFunction } />
8477 </ TutorialProvider > ,
8578 {
86- routes : [ '/tutorial ' ] ,
87- initialEntries : [ '/tutorial ' ] ,
79+ routes : [ '/' ] ,
80+ initialEntries : [ '/' ] ,
8881 } ,
8982 { wrapper : Providers }
9083 ) ;
@@ -95,91 +88,72 @@ test('Hides expected tutorials when providing filter fn', async ({
9588 await waitFor ( ( ) =>
9689 expect (
9790 screen . getByText (
98- `Available Tutorials (${ tutorials . filter ( filterFunction ) . length } )`
91+ `Available Tutorials (${ tutorials . filter ( ( t ) => t . path === '/' ) . filter ( filterFunction ) . length } )`
9992 )
10093 ) . toBeInTheDocument ( )
10194 ) ;
102-
103- for ( const tutorial of tutorials ) {
104- if ( tutorial . willPopUp ) {
105- expect (
106- screen . getByRole ( 'button' , { name : tutorial . name } )
107- ) . toBeInTheDocument ( ) ;
108- } else {
109- expect (
110- screen . queryByRole ( 'button' , { name : tutorial . name } )
111- ) . not . toBeInTheDocument ( ) ;
112- }
113- }
11495} ) ;
11596
11697test ( 'Clicking TutorialItem triggers callback, so we can navigate / do whatever we need' , async ( {
11798 worker,
11899} ) => {
119100 worker . use ( tutorialHandler ) ;
120101 const callback = vi . fn ( ) ;
121-
122102 await renderWithRouter (
123103 < TutorialProvider >
124104 < Tutorials onTutorialStart = { callback } />
125105 </ TutorialProvider > ,
126106 {
127- routes : [ '/tutorial ' ] ,
128- initialEntries : [ '/tutorial ' ] ,
107+ routes : [ '/' ] ,
108+ initialEntries : [ '/' ] ,
129109 } ,
130110 { wrapper : Providers }
131111 ) ;
132112 const user = userEvent . setup ( ) ;
133113
134- await user . click ( screen . getByRole ( 'button' ) ) ;
114+ await user . click ( await screen . findByRole ( 'button' ) ) ;
135115
136116 await waitFor ( ( ) =>
137- expect (
138- screen . getByText ( `Available Tutorials (${ tutorials . length } )` )
139- ) . toBeInTheDocument ( )
117+ expect ( screen . getByText ( `Available Tutorials (1)` ) ) . toBeInTheDocument ( )
140118 ) ;
141119
142- const randomTutorial = faker . helpers . arrayElement ( tutorials ) ;
143120 const tutorialItem = screen . getByRole ( 'button' , {
144- name : randomTutorial . name ,
121+ name : tutorials [ 0 ] . name ,
145122 } ) ;
146123
147124 await user . click ( tutorialItem ) ;
148125
149- expect ( callback ) . toHaveBeenCalledWith ( randomTutorial . id ) ;
126+ expect ( callback ) . toHaveBeenCalledWith ( tutorials [ 0 ] . id ) ;
150127} ) ;
151128
152129test ( 'Shows "completed" if tutorial has been seen' , async ( { worker } ) => {
153- worker . use ( tutorialHandler ) ;
154- const randomTutorial = faker . helpers . arrayElement ( tutorials ) ;
155130 window . localStorage . setItem (
156131 `sam-seen-tutorials-${ environment . getAppName ( import . meta. env . VITE_NAME ) } ` ,
157- JSON . stringify ( [ randomTutorial . id ] )
132+ JSON . stringify ( [ tutorials [ 0 ] . id ] )
158133 ) ;
134+ worker . use ( tutorialHandler ) ;
159135 const callback = vi . fn ( ) ;
160136 await renderWithRouter (
161137 < TutorialProvider >
162138 < Tutorials onTutorialStart = { callback } />
163139 </ TutorialProvider > ,
164140 {
165- routes : [ '/tutorial ' ] ,
166- initialEntries : [ '/tutorial ' ] ,
141+ routes : [ '/' ] ,
142+ initialEntries : [ '/' ] ,
167143 } ,
168144 { wrapper : Providers }
169145 ) ;
170146 const user = userEvent . setup ( ) ;
171147
172- await user . click ( screen . getByRole ( 'button' ) ) ;
148+ await user . click ( await screen . findByRole ( 'button' ) ) ;
173149
174150 await waitFor ( ( ) =>
175- expect (
176- screen . getByText ( `Available Tutorials (${ tutorials . length } )` )
177- ) . toBeInTheDocument ( )
151+ expect ( screen . getByText ( `Available Tutorials (1)` ) ) . toBeInTheDocument ( )
178152 ) ;
179153
180154 expect (
181155 screen . getByRole ( 'button' , {
182- name : `COMPLETED ${ randomTutorial . name } ` ,
156+ name : `COMPLETED ${ tutorials [ 0 ] . name } ` ,
183157 } )
184158 ) . toBeInTheDocument ( ) ;
185159} ) ;
0 commit comments