OrganizationItem.spec.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { renderComponent } from '#tests/support/components/index.ts'
  3. import OrganizationItem from '../OrganizationItem.vue'
  4. import type { OrganizationItemData } from '../types.ts'
  5. vi.hoisted(() => {
  6. const now = new Date(2022, 1, 1, 20, 0, 0, 0)
  7. vi.setSystemTime(now)
  8. })
  9. describe('ticket item display', () => {
  10. it('renders correctly', () => {
  11. const now = new Date(2022, 1, 1)
  12. vi.setSystemTime(now)
  13. const organization: OrganizationItemData = {
  14. id: '54321',
  15. ticketsCount: {
  16. open: 2,
  17. closed: 1,
  18. },
  19. internalId: 3,
  20. name: 'lorem ipsum',
  21. active: true,
  22. members: {
  23. edges: [
  24. {
  25. node: { fullname: 'Erik Wise' },
  26. },
  27. {
  28. node: { fullname: 'Peter Smith' },
  29. },
  30. ],
  31. totalCount: 3,
  32. },
  33. updatedAt: new Date(2022, 1, 1, 10, 0, 0, 0).toISOString(),
  34. updatedBy: {
  35. id: '456',
  36. fullname: 'Jane Doe',
  37. },
  38. }
  39. const view = renderComponent(OrganizationItem, {
  40. props: {
  41. entity: organization,
  42. },
  43. store: true,
  44. })
  45. expect(view.getByText('lorem ipsum')).toBeInTheDocument()
  46. expect(view.getByText(/2 tickets/)).toBeInTheDocument()
  47. expect(view.getByText(/·/)).toBeInTheDocument()
  48. expect(view.getByText(/Erik Wise, Peter Smith, \+1/)).toBeInTheDocument()
  49. expect(
  50. view.getByText('edited 10 hours ago by Jane Doe'),
  51. ).toBeInTheDocument()
  52. })
  53. it('renders when something is missing', () => {
  54. const organization: OrganizationItemData = {
  55. id: '54321',
  56. internalId: 2,
  57. ticketsCount: {
  58. open: 1,
  59. closed: 0,
  60. },
  61. name: 'lorem ipsum',
  62. active: true,
  63. }
  64. const view = renderComponent(OrganizationItem, {
  65. props: {
  66. entity: organization,
  67. },
  68. store: true,
  69. })
  70. expect(view.getByText('lorem ipsum')).toBeInTheDocument()
  71. expect(view.getByText(/1 ticket/)).toBeInTheDocument()
  72. expect(view.queryByText(/·/)).not.toBeInTheDocument()
  73. expect(view.queryByTestId('stringUpdated')).not.toBeInTheDocument()
  74. })
  75. it('renders VIP status', () => {
  76. const organization: OrganizationItemData = {
  77. id: '54321',
  78. internalId: 2,
  79. ticketsCount: {
  80. open: 1,
  81. closed: 0,
  82. },
  83. name: 'lorem ipsum',
  84. active: true,
  85. vip: true,
  86. }
  87. const view = renderComponent(OrganizationItem, {
  88. props: {
  89. entity: organization,
  90. },
  91. store: true,
  92. })
  93. expect(view.getByLabelText('Avatar (lorem ipsum)')).toBeAvatarElement({
  94. vip: true,
  95. active: true,
  96. type: 'organization',
  97. })
  98. })
  99. })