From 2004b5d3a05e01b7d8d427e2c0b4a798676b3537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20=C3=98rjavik?= Date: Mon, 16 Nov 2026 13:44:24 +0100 Subject: [PATCH] test(e2e): make keyboard select tests pass on macOS Native with the keyboard only. + * + * Arrow keys behave differently per platform: on Linux and Windows they + * change the value, but on macOS they open the option popup instead. + * Type-ahead (typing the start of an option's label) changes the value on + * every platform, so the test stays keyboard-only and portable. + */ +async function chooseByTyping(page: Page, select: Locator, label: string) { + await expect(select).toBeFocused(); + await page.keyboard.type(label); +} + test('desktop search, category, time and sorting work using only the keyboard', async ({ page, }) => { @@ -93,21 +106,18 @@ test('desktop search, category, time and sorting work using only the keyboard', }); await tabTo(page, category); await expect(category).toHaveCSS('outline-style', 'solid'); - await page.keyboard.press('ArrowDown'); - await page.keyboard.press('Enter'); + await chooseByTyping(page, category, 'Breakfast'); await expect(page).toHaveURL(/category=breakfast/); const time = page.getByRole('combobox', { name: 'Cooking time', exact: true, }); await tabTo(page, time); - await page.keyboard.press('ArrowDown'); - await page.keyboard.press('Enter'); + await chooseByTyping(page, time, '15'); await expect(page).toHaveURL(/time=lte15/); const sort = page.getByRole('combobox', { name: 'Sort by', exact: true }); await tabTo(page, sort); - await page.keyboard.press('End'); - await page.keyboard.press('Enter'); + await chooseByTyping(page, sort, 'Sort by: Highest'); await expect(page).toHaveURL(/sort=highest_rated/); }); @@ -189,13 +199,11 @@ test('Cookbook filters and sorting can be used with a keyboard', async ({ exact: true, }); await tabTo(page, category); - await page.keyboard.press('ArrowDown'); - await page.keyboard.press('Enter'); + await chooseByTyping(page, category, 'Breakfast'); await expect(page).toHaveURL(/category=breakfast/); const sort = page.getByRole('combobox', { name: 'Sort by', exact: true }); await tabTo(page, sort); - await page.keyboard.press('End'); - await page.keyboard.press('Enter'); + await chooseByTyping(page, sort, 'Sort by: Highest'); await expect(page).toHaveURL(/sort=highest_rated/); await page.setViewportSize({ width: 375, height: 812 }); const mobileSort = page.getByRole('button', { name: /^Sort:/ });