@@ -3,14 +3,31 @@ import { ChronoUnit, DateTimeFormatter } from '@js-joda/core'
33import { Locale } from '@js-joda/locale_en-us'
44import { currentTime , timeToISO } from '../test-utils'
55import { setupSite , populateStats , StatsEntry } from '../fixtures'
6+ import { randomID } from '../test-utils'
67
78test ( 'site switcher allows switching between different sites' , async ( {
89 page,
910 request
1011} ) => {
11- const { domain : domain1 , user } = await setupSite ( { page, request } )
12- const { domain : domain2 } = await setupSite ( { page, request, user } )
13- const { domain : domain3 } = await setupSite ( { page, request, user } )
12+ const suffix = randomID ( )
13+ // domain name matters in this test, the sites are sorted alphabetically in the dropdown
14+ const { domain : domain1 , user } = await setupSite ( {
15+ page,
16+ request,
17+ domain : `a-${ suffix } .example.com`
18+ } )
19+ const { domain : domain2 } = await setupSite ( {
20+ page,
21+ request,
22+ user,
23+ domain : `b-${ suffix } .example.com`
24+ } )
25+ const { domain : domain3 } = await setupSite ( {
26+ page,
27+ request,
28+ user,
29+ domain : `c-${ suffix } .example.com`
30+ } )
1431
1532 await populateStats ( {
1633 request,
@@ -40,24 +57,33 @@ test('site switcher allows switching between different sites', async ({
4057 const domain2Link = page . getByRole ( 'link' , { name : domain2 } )
4158 const domain3Link = page . getByRole ( 'link' , { name : domain3 } )
4259
43- const domain1Key = await domain1Link . locator ( 'kbd' ) . textContent ( )
44- const domain3Key = await domain3Link . locator ( 'kbd' ) . textContent ( )
45-
4660 await expect ( domain1Link ) . toBeVisible ( )
61+ await expect ( domain1Link . locator ( 'kbd' ) ) . toHaveText ( '1' )
4762 await expect ( domain2Link ) . toBeVisible ( )
63+ await expect ( domain2Link . locator ( 'kbd' ) ) . toHaveText ( '2' )
4864 await expect ( domain3Link ) . toBeVisible ( )
65+ await expect ( domain3Link . locator ( 'kbd' ) ) . toHaveText ( '3' )
4966
5067 await page . getByRole ( 'link' , { name : domain2 } ) . click ( )
5168
5269 await expect ( page ) . toHaveURL ( `/${ domain2 } ` )
5370 await expect ( switcherButton ) . toHaveText ( domain2 )
5471
55- await page . keyboard . press ( domain3Key ! )
72+ // make sure sites are loaded
73+ await switcherButton . click ( )
74+ await expect ( domain3Link ) . toBeVisible ( )
75+ // keybind should work when dropdown closed
76+ await switcherButton . click ( )
77+ await page . keyboard . press ( '3' )
5678
5779 await expect ( page ) . toHaveURL ( `/${ domain3 } ` )
5880 await expect ( switcherButton ) . toHaveText ( domain3 )
5981
60- await page . keyboard . press ( domain1Key ! )
82+ // make sure sites are loaded
83+ await switcherButton . click ( )
84+ await expect ( domain1Link ) . toBeVisible ( )
85+ // keybind should work when dropdown open
86+ await page . keyboard . press ( '1' )
6187
6288 await expect ( page ) . toHaveURL ( `/${ domain1 } ` )
6389 await expect ( switcherButton ) . toHaveText ( domain1 )
0 commit comments