checkSimpleTableContent.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { within } from '@testing-library/vue'
  3. import type { ExtendedRenderResult } from '#tests/support/components/renderComponent.ts'
  4. export const checkSimpleTableHeader = (
  5. view: ExtendedRenderResult,
  6. tableHeaders: string[],
  7. tableLabel?: string,
  8. ) => {
  9. const table = within(view.getByRole('table', { name: tableLabel }))
  10. tableHeaders.forEach((header) => {
  11. expect(
  12. table.getByRole('columnheader', { name: header }),
  13. ).toBeInTheDocument()
  14. })
  15. }
  16. export const checkSimpleTableContent = (
  17. view: ExtendedRenderResult,
  18. rowContents: (string | string[])[][],
  19. tableLabel?: string,
  20. ) => {
  21. const table = within(view.getByRole('table', { name: tableLabel }))
  22. const rows = table.getAllByRole('row')
  23. expect(rows).toHaveLength(rowContents.length)
  24. rows.forEach((row, index) => {
  25. within(row)
  26. .getAllByRole('cell')
  27. .forEach((cell, cellIndex) => {
  28. const content = rowContents[index][cellIndex]
  29. if (content) {
  30. const withinCell = within(cell)
  31. if (Array.isArray(content)) {
  32. const dateTime = withinCell.getByLabelText(content[0])
  33. expect(dateTime).toHaveTextContent(content[1])
  34. } else {
  35. expect(withinCell.getByText(content)).toBeInTheDocument()
  36. }
  37. }
  38. })
  39. })
  40. }