inventory.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { expect, type Page } from '@playwright/test'
  2. import { partRows } from './work-order'
  3. /**
  4. * Adding a stocked part to a work order, through the picker a workshop uses.
  5. *
  6. * Typing a name into a part row makes free text, which moves no stock. Only a
  7. * row that carries the inventory part's id does, and the only way to get one
  8. * is this dialog.
  9. */
  10. export async function addPartFromInventory(
  11. page: Page,
  12. name: string,
  13. quantity: number
  14. ): Promise<void> {
  15. const rows = partRows(page)
  16. const before = await rows.count()
  17. const dialog = page.getByRole('dialog', { name: 'Select Part from Inventory' })
  18. await expect(async () => {
  19. await page.getByRole('button', { name: 'From Inventory', exact: true }).click()
  20. await expect(dialog).toBeVisible({ timeout: 2_000 })
  21. }).toPass({ timeout: 30_000 })
  22. await dialog.getByPlaceholder('Search inventory...').fill(name)
  23. await dialog
  24. .getByRole('button', { name: new RegExp(name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'i') })
  25. .first()
  26. .click()
  27. // The picked part is put at the top of the list, and comes in at one.
  28. await expect(rows).toHaveCount(before + 1)
  29. await setPartQuantityField(page, quantity)
  30. }
  31. /** Types a quantity into the first part row, which is the one just added. */
  32. export async function setPartQuantityField(page: Page, quantity: number): Promise<void> {
  33. const row = partRows(page).first().locator('xpath=ancestor::*[.//input[@placeholder="Cost"]][1]')
  34. await row.locator('input[type="number"]').first().fill(String(quantity))
  35. }