ActivityMessage.spec.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { generateObjectData } from '#tests/graphql/builders/index.ts'
  3. import { renderComponent } from '#tests/support/components/index.ts'
  4. import type { Ticket } from '#shared/graphql/types.ts'
  5. import { convertToGraphQLId } from '#shared/graphql/utils.ts'
  6. import ActivityMessage from '../ActivityMessage.vue'
  7. import type { Props } from '../ActivityMessage.vue'
  8. const now = vi.hoisted(() => {
  9. const now = new Date('2022-01-03 00:00:00')
  10. vi.setSystemTime(now)
  11. return now
  12. })
  13. // this is not required, but Vitest is bugged and does not hoist "now" otherwise
  14. // https://github.com/vitest-dev/vitest/pull/4285/files
  15. vi.mock('non-existing')
  16. const userId = convertToGraphQLId('User', 100)
  17. const renderActivityMessage = (props: Partial<Props> = {}) => {
  18. const finishedProps: Props = {
  19. objectName: 'Ticket',
  20. typeName: 'update',
  21. createdBy: {
  22. id: userId,
  23. fullname: 'John Doe',
  24. firstname: 'John',
  25. lastname: 'Doe',
  26. active: true,
  27. },
  28. createdAt: new Date('2022-01-01 00:00:00').toISOString(),
  29. metaObject: generateObjectData<Ticket>('Ticket', {
  30. title: 'Ticket Title',
  31. id: convertToGraphQLId('Ticket', '1'),
  32. internalId: 1,
  33. }),
  34. ...props,
  35. }
  36. return renderComponent(ActivityMessage, {
  37. props: finishedProps,
  38. router: true,
  39. })
  40. }
  41. describe('NotificationItem.vue', () => {
  42. afterEach(() => {
  43. vi.useRealTimers()
  44. })
  45. it('check update activity message output', () => {
  46. const view = renderActivityMessage()
  47. expect(view.container).toHaveTextContent(
  48. 'John Doe updated ticket Ticket Title',
  49. )
  50. })
  51. it('check create activity message output', () => {
  52. const view = renderActivityMessage({
  53. typeName: 'create',
  54. })
  55. expect(view.container).toHaveTextContent(
  56. 'John Doe created ticket Ticket Title',
  57. )
  58. })
  59. it('check that avatar exists', () => {
  60. const view = renderActivityMessage()
  61. const avatar = view.getByTestId('common-avatar')
  62. expect(avatar).toHaveTextContent('JD')
  63. })
  64. it('check that link exists', () => {
  65. const view = renderActivityMessage()
  66. const link = view.getByRole('link')
  67. expect(link).toHaveAttribute('href', 'tickets/1')
  68. })
  69. it('check that create date exists', () => {
  70. vi.setSystemTime(now)
  71. const view = renderActivityMessage()
  72. expect(view.getByText(/2 days ago/)).toBeInTheDocument()
  73. })
  74. it('check that default message and avatar for no meta object is visible', () => {
  75. const view = renderActivityMessage({
  76. metaObject: undefined,
  77. createdBy: undefined,
  78. })
  79. expect(view.container).toHaveTextContent(
  80. 'You can no longer see the ticket.',
  81. )
  82. expect(view.getByIconName('lock')).toBeInTheDocument()
  83. })
  84. it('should emit "seen" event on click for none linked notifications', async () => {
  85. const view = renderActivityMessage({
  86. metaObject: undefined,
  87. createdBy: undefined,
  88. })
  89. const item = view.getByText('You can no longer see the ticket.')
  90. await view.events.click(item)
  91. expect(view.emitted().seen).toBeTruthy()
  92. })
  93. it('no output for not existing builder', (context) => {
  94. context.skipConsole = true
  95. const view = renderActivityMessage({
  96. objectName: 'NotExisting',
  97. })
  98. expect(view.html()).not.toContain('a')
  99. })
  100. })