guided-setup-automated-run.spec.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { flushPromises } from '@vue/test-utils'
  3. import { visitView } from '#tests/support/components/visitView.ts'
  4. import { mockApplicationConfig } from '#tests/support/mock-applicationConfig.ts'
  5. import { mockAuthentication } from '#tests/support/mock-authentication.ts'
  6. import { EnumSystemSetupInfoStatus } from '#shared/graphql/types.ts'
  7. import {
  8. mockSystemSetupRunAutoWizardMutation,
  9. waitForSystemSetupRunAutoWizardMutationCalls,
  10. } from '#desktop/pages/guided-setup/graphql/mutations/systemSetupRunAutoWizard.mocks.ts'
  11. import { mockSystemSetupInfoQuery } from '../graphql/queries/systemSetupInfo.mocks.ts'
  12. describe('guided setup automated run', () => {
  13. describe('when system is not ready', () => {
  14. beforeEach(() => {
  15. mockApplicationConfig({
  16. system_init_done: false,
  17. })
  18. mockAuthentication(false)
  19. mockSystemSetupInfoQuery({
  20. systemSetupInfo: {
  21. status: EnumSystemSetupInfoStatus.Automated,
  22. type: null,
  23. },
  24. })
  25. })
  26. it('redirects to home screen after successful setup', async () => {
  27. vi.useFakeTimers()
  28. const view = await visitView('/guided-setup/automated/run')
  29. expect(view.getByText('Automated Setup')).toBeInTheDocument()
  30. expect(view.getByIconName('spinner')).toBeInTheDocument()
  31. expect(
  32. view.getByText('Relax, your system is being set up…'),
  33. ).toBeInTheDocument()
  34. await flushPromises()
  35. expect(
  36. view.getByText(
  37. 'The system was configured successfully. You are being redirected.',
  38. ),
  39. ).toBeInTheDocument()
  40. await vi.runAllTimersAsync()
  41. vi.useRealTimers()
  42. await vi.waitFor(() => {
  43. expect(view, 'correctly redirects to home screen').toHaveCurrentUrl('/')
  44. })
  45. })
  46. it('shows an alert message and hides spinner on errors', async () => {
  47. mockSystemSetupRunAutoWizardMutation({
  48. systemSetupRunAutoWizard: {
  49. errors: [
  50. {
  51. message: 'An unexpected error occurred during system setup.',
  52. field: null,
  53. },
  54. ],
  55. },
  56. })
  57. const view = await visitView('/guided-setup/automated/run')
  58. await flushPromises()
  59. expect(view.getByText('Automated Setup')).toBeInTheDocument()
  60. expect(view.queryByIconName('spinner')).not.toBeInTheDocument()
  61. expect(
  62. view.getByText('An unexpected error occurred during system setup.'),
  63. ).toBeInTheDocument()
  64. })
  65. it('supports optional token parameter', async () => {
  66. await visitView('/guided-setup/automated/run/s3cr3t-t0k3n')
  67. await flushPromises()
  68. const calls = await waitForSystemSetupRunAutoWizardMutationCalls()
  69. expect(calls.at(-1)?.variables).toEqual(
  70. expect.objectContaining({
  71. token: 's3cr3t-t0k3n',
  72. }),
  73. )
  74. })
  75. })
  76. describe('when system is ready', () => {
  77. beforeEach(() => {
  78. mockApplicationConfig({
  79. system_init_done: true,
  80. })
  81. })
  82. it('redirects to home screen', async () => {
  83. mockAuthentication(true)
  84. const view = await visitView('/guided-setup/automated/run')
  85. await vi.waitFor(() => {
  86. expect(view, 'correctly redirects to home screen').toHaveCurrentUrl('/')
  87. })
  88. })
  89. it('redirects to login screen', async () => {
  90. mockAuthentication(false)
  91. const view = await visitView('/guided-setup/automated/run')
  92. await vi.waitFor(() => {
  93. expect(view, 'correctly redirects to login screen').toHaveCurrentUrl(
  94. '/login',
  95. )
  96. })
  97. })
  98. })
  99. })