personal-setting-overviews.spec.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { getAllByRole } 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 { waitForNextTick } from '#tests/support/utils.ts'
  7. import { convertToGraphQLId } from '#shared/graphql/utils.ts'
  8. import { mockUserCurrentOverviewResetOrderMutation } from '../graphql/mutations/userCurrentOverviewResetOrder.mocks.ts'
  9. import { mockUserCurrentOverviewListQuery } from '../graphql/queries/userCurrentOverviewList.mocks.ts'
  10. import { getUserCurrentOverviewOrderingUpdatesSubscriptionHandler } from '../graphql/subscriptions/userCurrentOverviewOrderingUpdates.mocks.ts'
  11. const userCurrentOverviewList = [
  12. {
  13. id: convertToGraphQLId('Overview', 1),
  14. name: 'Open Tickets',
  15. },
  16. {
  17. id: convertToGraphQLId('Overview', 2),
  18. name: 'My Tickets',
  19. },
  20. {
  21. id: convertToGraphQLId('Overview', 3),
  22. name: 'All Tickets',
  23. },
  24. ]
  25. const userCurrentOverviewListAferReset = userCurrentOverviewList.reverse()
  26. describe('personal settings for token access', () => {
  27. beforeEach(() => {
  28. mockUserCurrent({
  29. firstname: 'John',
  30. lastname: 'Doe',
  31. })
  32. mockPermissions(['user_preferences.overview_sorting'])
  33. })
  34. it('shows the overviews order by priority', async () => {
  35. mockUserCurrentOverviewListQuery({ userCurrentOverviewList })
  36. const view = await visitView('/personal-setting/ticket-overviews')
  37. const overviewContainer = view.getByLabelText('Order of ticket overviews')
  38. const overviews = getAllByRole(overviewContainer, 'listitem')
  39. userCurrentOverviewList.forEach((overview, index) => {
  40. expect(overviews[index]).toHaveTextContent(overview.name)
  41. })
  42. })
  43. // TODO: Cover the update of overview order when the items are moved around the list.
  44. // We may need to implement a testable mechanism for reordering the list, though, as drag events are not fully
  45. // supported in JSDOM due to missing client-rectangle coordinate mocking.
  46. // One approach could be to add keyboard shortcuts for changing the order, or perhaps even hidden buttons.
  47. it('allows to reset the order of overviews', async () => {
  48. mockUserCurrentOverviewListQuery({ userCurrentOverviewList })
  49. const view = await visitView('/personal-setting/ticket-overviews')
  50. mockUserCurrentOverviewResetOrderMutation({
  51. userCurrentOverviewResetOrder: {
  52. success: true,
  53. overviews: userCurrentOverviewListAferReset,
  54. errors: null,
  55. },
  56. })
  57. const resetButton = view.getByRole('button', {
  58. name: 'Reset Overview Order',
  59. })
  60. expect(resetButton).toBeInTheDocument()
  61. await view.events.click(resetButton)
  62. await waitForNextTick()
  63. expect(
  64. await view.findByRole('dialog', { name: 'Confirmation' }),
  65. ).toBeInTheDocument()
  66. await view.events.click(view.getByRole('button', { name: 'Yes' }))
  67. await waitForNextTick()
  68. userCurrentOverviewListAferReset.forEach((overview) => {
  69. expect(view.getByText(overview.name)).toBeInTheDocument()
  70. })
  71. })
  72. it('updates the overviews list when a new overview is added', async () => {
  73. mockUserCurrentOverviewListQuery({ userCurrentOverviewList })
  74. const view = await visitView('/personal-setting/ticket-overviews')
  75. const overviewUpdateSubscription =
  76. getUserCurrentOverviewOrderingUpdatesSubscriptionHandler()
  77. userCurrentOverviewList.forEach((overview) => {
  78. expect(view.getByText(overview.name)).toBeInTheDocument()
  79. })
  80. overviewUpdateSubscription.trigger({
  81. userCurrentOverviewOrderingUpdates: {
  82. overviews: [
  83. ...userCurrentOverviewList,
  84. {
  85. id: convertToGraphQLId('Overview', 4),
  86. name: 'New Overview',
  87. },
  88. ],
  89. },
  90. })
  91. await waitForNextTick()
  92. expect(view.getByText('New Overview')).toBeInTheDocument()
  93. })
  94. })