Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions e2e/smoke.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ async function tabTo(page: Page, target: Locator) {
await expect(target).toBeFocused();
}

/**
* Chooses an option in the focused native <select> 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,
}) => {
Expand All @@ -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/);
});

Expand Down Expand Up @@ -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:/ });
Expand Down