opening-home.spec.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { getByTestId } from '@testing-library/vue'
  3. import { visitView } from '#tests/support/components/visitView.ts'
  4. import { mockPermissions } from '#tests/support/mock-permissions.ts'
  5. import { mockUserCurrent } from '#tests/support/mock-userCurrent.ts'
  6. import { mockTicketOverviews } from '#tests/support/mocks/ticket-overviews.ts'
  7. import { getTicketOverviewStorage } from '#mobile/entities/ticket/helpers/ticketOverviewStorage.ts'
  8. describe('home page', () => {
  9. beforeEach(() => {
  10. mockUserCurrent({ id: '666' })
  11. mockTicketOverviews()
  12. })
  13. it('renders ticket overviews based on localStorage', async () => {
  14. mockPermissions(['ticket.agent', 'ticket.customer'])
  15. const { saveOverviews } = getTicketOverviewStorage()
  16. saveOverviews(['3', '2'])
  17. const view = await visitView('/')
  18. expect(view.getByRole('link', { name: /Edit/ })).toHaveAttribute(
  19. 'href',
  20. '/mobile/favorite/ticker-overviews/edit',
  21. )
  22. const overviews = await view.findAllByText(/^Overview/)
  23. expect(overviews).toHaveLength(2)
  24. expect(overviews[0]).toHaveTextContent('Overview 3')
  25. expect(overviews[1]).toHaveTextContent('Overview 2')
  26. const overviewLinks = await view.findAllByTestId('section-menu-link')
  27. const lastOverview = overviewLinks.at(-1)
  28. expect(lastOverview).toHaveTextContent('Overview 2')
  29. if (lastOverview) {
  30. const overviewCount = getByTestId(
  31. lastOverview,
  32. 'section-menu-information',
  33. )
  34. expect(overviewCount).toHaveTextContent('2')
  35. }
  36. })
  37. it('do not show favorite ticket overview section on home without permission', async () => {
  38. const view = await visitView('/')
  39. expect(
  40. view.queryByRole('link', { name: /Edit/ }),
  41. "doesn't have link when account doesn't have rights",
  42. ).not.toBeInTheDocument()
  43. expect(view.queryByText('Ticket Overview')).not.toBeInTheDocument()
  44. })
  45. })