@@ -52,6 +52,41 @@ test('use sidebar to go to Hello World page', async ({ page }) => {
5252 await expect ( page ) . toHaveTitle ( / H e l l o W o r l d - G i t H u b D o c s / )
5353} )
5454
55+ test ( 'press "/" to open the search overlay' , async ( { page } ) => {
56+ await page . goto ( '/' )
57+ await turnOffExperimentsInPage ( page )
58+
59+ // Wait for the header search button to render, so the keydown listener is attached.
60+ await page . locator ( '[data-testid="search"]:visible' ) . waitFor ( )
61+
62+ const searchInput = page . getByTestId ( 'overlay-search-input' )
63+ // The overlay (and its input) is not in the DOM until it's opened.
64+ await expect ( searchInput ) . toHaveCount ( 0 )
65+
66+ // Pressing "/" anywhere on the page opens the overlay and focuses the input.
67+ await page . keyboard . press ( '/' )
68+ await expect ( searchInput ) . toBeFocused ( )
69+
70+ // Escape closes it again.
71+ await page . keyboard . press ( 'Escape' )
72+ await expect ( searchInput ) . toHaveCount ( 0 )
73+ } )
74+
75+ test ( '"/" typed inside the search input is a literal slash' , async ( { page } ) => {
76+ await page . goto ( '/' )
77+ await turnOffExperimentsInPage ( page )
78+
79+ await page . locator ( '[data-testid="search"]:visible' ) . waitFor ( )
80+
81+ await page . keyboard . press ( '/' )
82+ const searchInput = page . getByTestId ( 'overlay-search-input' )
83+ await expect ( searchInput ) . toBeFocused ( )
84+
85+ // The "/" shortcut must not fire while typing in a field, so it is not swallowed.
86+ await page . keyboard . type ( 'a/b' )
87+ await expect ( searchInput ) . toHaveValue ( 'a/b' )
88+ } )
89+
5590test ( 'do a search from home page and click on "Foo" page' , async ( { page } ) => {
5691 test . skip ( ! SEARCH_TESTS , 'No local Elasticsearch, no tests involving search' )
5792
0 commit comments