warranty.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { expect, type Locator, type Page } from '@playwright/test'
  2. /**
  3. * The warranty panel, which is one component on the quote editor and on the
  4. * work order editor. It is folded shut until a document says something about
  5. * warranty, so everything here opens it first.
  6. */
  7. export type WarrantyStatement = 'Not stated' | 'Included' | 'Not included'
  8. /** The panel, opened. */
  9. export async function warrantyPanel(page: Page): Promise<Locator> {
  10. const panel = page.getByTestId('warranty-section')
  11. await expect(panel).toBeVisible()
  12. // Folded on the quote editor; always open on the work order page, which
  13. // has no header button at all.
  14. const header = panel.getByRole('button', { name: /^Warranty/ })
  15. await expect(async () => {
  16. if ((await header.count()) > 0 && (await header.getAttribute('aria-expanded')) !== 'true') {
  17. await header.click()
  18. }
  19. await expect(panel.getByRole('radiogroup')).toBeVisible({ timeout: 2_000 })
  20. }).toPass({ timeout: 30_000 })
  21. return panel
  22. }
  23. /** Which of the three statements the open document currently makes. */
  24. export async function expectWarrantyStatement(
  25. page: Page,
  26. statement: WarrantyStatement
  27. ): Promise<Locator> {
  28. const panel = await warrantyPanel(page)
  29. await expect(panel.getByRole('radio', { name: statement, exact: true })).toHaveAttribute(
  30. 'aria-checked',
  31. 'true'
  32. )
  33. return panel
  34. }
  35. /** Picks a statement, retried because a click before hydration does nothing. */
  36. export async function chooseWarrantyStatement(
  37. page: Page,
  38. statement: WarrantyStatement
  39. ): Promise<Locator> {
  40. const panel = await warrantyPanel(page)
  41. const choice = panel.getByRole('radio', { name: statement, exact: true })
  42. await expect(async () => {
  43. await choice.click()
  44. await expect(choice).toHaveAttribute('aria-checked', 'true', { timeout: 2_000 })
  45. }).toPass({ timeout: 30_000 })
  46. return panel
  47. }