TicketItem.spec.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { renderComponent } from '#tests/support/components/index.ts'
  3. import { TicketState } from '#shared/entities/ticket/types.ts'
  4. import { EnumTicketStateColorCode } from '#shared/graphql/types.ts'
  5. import TicketItem from '../TicketItem.vue'
  6. import type { TicketItemData } from '../types.ts'
  7. vi.hoisted(() => {
  8. const now = new Date(2022, 1, 1, 20, 0, 0, 0)
  9. vi.setSystemTime(now)
  10. })
  11. describe('ticket item display', () => {
  12. it('renders correctly', () => {
  13. const ticket: TicketItemData = {
  14. id: '54321',
  15. number: '12345',
  16. internalId: 1,
  17. state: { name: TicketState.Open },
  18. title: 'test ticket',
  19. customer: {
  20. fullname: 'John Doe',
  21. },
  22. updatedAt: new Date(2022, 1, 1, 10, 0, 0, 0).toISOString(),
  23. updatedBy: {
  24. id: '456',
  25. fullname: 'Jane Doe',
  26. },
  27. priority: {
  28. name: '3 high',
  29. uiColor: 'high-priority',
  30. defaultCreate: false,
  31. },
  32. stateColorCode: EnumTicketStateColorCode.Open,
  33. }
  34. const view = renderComponent(TicketItem, {
  35. props: {
  36. entity: ticket,
  37. },
  38. store: true,
  39. router: true,
  40. })
  41. expect(view.getByRole('group')).toHaveClass('text-yellow')
  42. expect(view.getByIconName('check-circle-no')).toHaveAccessibleName(
  43. '(state: open)',
  44. )
  45. expect(view.getByText('#12345 · John Doe')).toBeInTheDocument()
  46. expect(view.getByText('test ticket')).toBeInTheDocument()
  47. expect(
  48. view.getByText('edited 10 hours ago by Jane Doe'),
  49. ).toBeInTheDocument()
  50. const priority = view.getByText('3 high')
  51. expect(priority).toBeInTheDocument()
  52. expect(priority).toHaveClasses(['bg-red-dark', 'text-red-bright'])
  53. })
  54. it('renders when something is missing', () => {
  55. const ticket: TicketItemData = {
  56. id: '54321',
  57. number: '12345',
  58. internalId: 1,
  59. state: { name: TicketState.Open },
  60. title: 'test ticket',
  61. stateColorCode: EnumTicketStateColorCode.Open,
  62. }
  63. const view = renderComponent(TicketItem, {
  64. props: {
  65. entity: ticket,
  66. },
  67. store: true,
  68. router: true,
  69. })
  70. expect(view.getByRole('group')).toHaveClass('text-yellow')
  71. expect(view.getByIconName('check-circle-no')).toHaveAccessibleName(
  72. '(state: open)',
  73. )
  74. expect(view.getByText('#12345')).toBeInTheDocument()
  75. expect(view.queryByText(/·/)).not.toBeInTheDocument()
  76. expect(view.getByText('test ticket')).toBeInTheDocument()
  77. expect(view.queryByTestId('stringUpdated')).not.toBeInTheDocument()
  78. expect(view.queryByText('3 high')).not.toBeInTheDocument()
  79. })
  80. })