LayoutBottomNavigation.spec.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { flushPromises } from '@vue/test-utils'
  3. import { renderComponent } from '#tests/support/components/index.ts'
  4. import { mockGraphQLSubscription } from '#tests/support/mock-graphql-api.ts'
  5. import { OnlineNotificationsCountDocument } from '#shared/entities/online-notification/graphql/subscriptions/onlineNotificationsCount.api.ts'
  6. import { convertToGraphQLId } from '#shared/graphql/utils.ts'
  7. import { useSessionStore } from '#shared/stores/session.ts'
  8. import type { UserData } from '#shared/types/store.ts'
  9. import LayoutBottomNavigation from '../LayoutBottomNavigation.vue'
  10. describe('bottom navigation in layout', () => {
  11. it('renders navigation', async () => {
  12. mockGraphQLSubscription(OnlineNotificationsCountDocument)
  13. const view = renderComponent(LayoutBottomNavigation, {
  14. store: true,
  15. router: true,
  16. })
  17. const store = useSessionStore()
  18. store.user = {
  19. id: convertToGraphQLId('User', 100),
  20. firstname: 'User',
  21. lastname: 'Test',
  22. } as UserData
  23. await flushPromises()
  24. expect(view.getByIconName('home')).toBeInTheDocument()
  25. expect(view.getByIconName('home').closest('a')).toHaveClass('text-blue')
  26. expect(view.getByIconName('notification-subscribed')).toBeInTheDocument()
  27. expect(view.getByText('UT')).toBeInTheDocument()
  28. })
  29. it('rendering notifications counter', async () => {
  30. const subscription = mockGraphQLSubscription(
  31. OnlineNotificationsCountDocument,
  32. )
  33. const view = renderComponent(LayoutBottomNavigation, {
  34. store: true,
  35. router: true,
  36. })
  37. const store = useSessionStore()
  38. store.user = {
  39. id: convertToGraphQLId('User', 100),
  40. firstname: 'User',
  41. lastname: 'Test',
  42. } as UserData
  43. await flushPromises()
  44. expect(
  45. view.queryByRole('status', { name: 'Unread notifications' }),
  46. ).not.toBeInTheDocument()
  47. await subscription.next({
  48. data: {
  49. onlineNotificationsCount: {
  50. unseenCount: 1,
  51. },
  52. },
  53. })
  54. expect(
  55. view.getByRole('status', { name: 'Unread notifications' }),
  56. ).toHaveTextContent('1')
  57. })
  58. })