// e2e/test-helpers.ts import { expect } from './fixtures'; import type { Page } from '@playwright/test'; /* ----------------------- Shared constants ----------------------- */ export const areaName = 'Drinks'; export const additionalProduct = 'Pump 750'; export const listProductName = 'List Flow Soda'; export const updatedListProductName = 'List Flow Soda Zero'; export const searchTerm = 'E2E Search'; export const matchingProducts = [`${searchTerm} Alpha`, `${searchTerm} Beta`]; export const nonMatchingProduct = 'E2E Other Gamma'; export const secondaryProduct = 'Mount Franklin 600ml'; /* ----------------------- Small helpers ----------------------- */ export const waitForScreenHeading = async (page: Page, heading: string, timeout = 15000) => { try { await page.locator('text=Loading…').waitFor({ state: 'hidden', timeout: 5000 }); } catch { // ignore if no fallback } await expect(page.getByRole('heading', { name: heading })).toBeVisible({ timeout }); }; export const openAddProductDialog = async (page: Page) => { const dialog = page.getByLabel('Add product dialog'); const isDialogVisible = (await dialog.count()) > 0 && (await dialog.first().isVisible()); if (!isDialogVisible) { await page.getByRole('button', { name: 'Add product' }).click(); } await dialog.first().waitFor({ state: 'visible', timeout: 5000 }); }; export const openSelect = async (page: Page, label: string, optionName: string, testId?: string) => { const tryOpen = async (lbl: string) => { // 1) Try testId wrapper if provided if (testId) { const wrapper = page.getByTestId(testId); if ((await wrapper.count()) > 0) { await wrapper.first().waitFor({ state: 'visible', timeout: 10000 }); // native