| 2 | import { tid } from '../utils/data-testid' |
| 3 | |
| 4 | export const createUtils = (page: Page) => ({ |
| 5 | /** |
| 6 | * Returns a locator that matches the given data-testid. |
| 7 | * @param args - The data-testid to match. |
| 8 | */ |
| 9 | getByTestId: (...args: string[]) => |
| 10 | page.locator(`data-testid=${tid(...args)}`), |
| 11 | getByTestIdWithinElement: (element: Locator, ...args: string[]) => |
| 12 | element.locator(`data-testid=${tid(...args)}`), |
| 13 | /** |
| 14 | * Returns true when a viewport is mobile. |
| 15 | * |
| 16 | * Useful for when different selectors are needed at different screen sizes. |
| 17 | */ |
| 18 | isMobileViewport: () => (page.viewportSize()?.width ?? 0) <= 600, |
| 19 | }) |
| 20 | |
| 21 | export type Utils = ReturnType<typeof createUtils> |