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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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(
  33. 'The system was configured successfully. You are being redirected.',
  34. ),
  35. ).toBeInTheDocument()
  36. await vi.runAllTimersAsync()
  37. vi.useRealTimers()
  38. await vi.waitFor(() => {
  39. expect(view, 'correctly redirects to home screen').toHaveCurrentUrl('/')
  40. })
  41. })
  42. it('shows an alert message and hides spinner on errors', async () => {
  43. mockSystemSetupRunAutoWizardMutation({
  44. systemSetupRunAutoWizard: {
  45. errors: [
  46. {
  47. message: 'An unexpected error occurred during system setup.',
  48. field: null,
  49. },
  50. ],
  51. },
  52. })
  53. const view = await visitView('/guided-setup/automated/run')
  54. await flushPromises()
  55. expect(view.getByText('Automated Setup')).toBeInTheDocument()
  56. expect(view.queryByIconName('spinner')).not.toBeInTheDocument()
  57. expect(
  58. view.getByText('An unexpected error occurred during system setup.'),
  59. ).toBeInTheDocument()
  60. })
  61. it('supports optional token parameter', async () => {
  62. await visitView('/guided-setup/automated/run/s3cr3t-t0k3n')
  63. await flushPromises()
  64. const calls = await waitForSystemSetupRunAutoWizardMutationCalls()
  65. expect(calls.at(-1)?.variables).toEqual(
  66. expect.objectContaining({
  67. token: 's3cr3t-t0k3n',
  68. }),
  69. )
  70. })
  71. })
  72. describe('when system is ready', () => {
  73. beforeEach(() => {
  74. mockApplicationConfig({
  75. system_init_done: true,
  76. })
  77. })
  78. it('redirects to home screen', async () => {
  79. mockAuthentication(true)
  80. const view = await visitView('/guided-setup/automated/run')
  81. await vi.waitFor(() => {
  82. expect(view, 'correctly redirects to home screen').toHaveCurrentUrl('/')
  83. })
  84. })
  85. it('redirects to login screen', async () => {
  86. mockAuthentication(false)
  87. const view = await visitView('/guided-setup/automated/run')
  88. await vi.waitFor(() => {
  89. expect(view, 'correctly redirects to login screen').toHaveCurrentUrl(
  90. '/login',
  91. )
  92. })
  93. })
  94. })
  95. })