UserItem.spec.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { renderComponent } from '#tests/support/components/index.ts'
  3. import UserItem from '../UserItem.vue'
  4. import type { UserItemData } 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('user item display', () => {
  10. it('renders correctly', () => {
  11. const user: UserItemData = {
  12. id: '123',
  13. ticketsCount: {
  14. open: 2,
  15. closed: 0,
  16. },
  17. firstname: 'John',
  18. lastname: 'Doe',
  19. updatedAt: new Date(2022, 1, 1, 10, 0, 0, 0).toISOString(),
  20. updatedBy: {
  21. id: '456',
  22. fullname: 'Jane Doe',
  23. },
  24. organization: {
  25. name: 'organization',
  26. },
  27. }
  28. const view = renderComponent(UserItem, {
  29. props: {
  30. entity: user,
  31. },
  32. store: true,
  33. })
  34. expect(view.getByText('JD')).toBeInTheDocument() // avatar
  35. expect(view.getByText(/organization/)).toBeInTheDocument()
  36. expect(view.getByText(/2 tickets/)).toBeInTheDocument()
  37. expect(view.getByText('John Doe')).toBeInTheDocument()
  38. expect(
  39. view.getByText('edited 10 hours ago by Jane Doe'),
  40. ).toBeInTheDocument()
  41. })
  42. it('renders when something is missing', () => {
  43. const user: UserItemData = {
  44. id: '123',
  45. ticketsCount: {
  46. open: 1,
  47. closed: 0,
  48. },
  49. firstname: 'John',
  50. }
  51. const view = renderComponent(UserItem, {
  52. props: {
  53. entity: user,
  54. },
  55. store: true,
  56. })
  57. expect(view.getByText('JO')).toBeInTheDocument() // avatar
  58. expect(view.getByText(/^John$/)).toBeInTheDocument()
  59. expect(view.getByText('1 ticket')).toBeInTheDocument()
  60. expect(view.queryByText(/·/)).not.toBeInTheDocument()
  61. expect(view.queryByTestId('stringUpdated')).not.toBeInTheDocument()
  62. })
  63. })