guided-setup-start.spec.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { getTestRouter } from '#tests/support/components/renderComponent.ts'
  3. import { visitView } from '#tests/support/components/visitView.ts'
  4. import { mockApplicationConfig } from '#tests/support/mock-applicationConfig.ts'
  5. import {
  6. EnumSystemSetupInfoStatus,
  7. EnumSystemSetupInfoType,
  8. } from '#shared/graphql/types.ts'
  9. import { mockSystemSetupLockMutation } from '../graphql/mutations/systemSetupLock.mocks.ts'
  10. import { mockSystemSetupInfoQuery } from '../graphql/queries/systemSetupInfo.mocks.ts'
  11. import { useSystemSetupInfoStore } from '../stores/systemSetupInfo.ts'
  12. import { mockSystemSetupInfo } from './mocks/mock-systemSetupInfo.ts'
  13. describe('guided setup start', () => {
  14. describe('when system initialization is done', () => {
  15. beforeEach(() => {
  16. mockApplicationConfig({
  17. system_init_done: true,
  18. })
  19. })
  20. it('redirects to login window', async () => {
  21. const view = await visitView('/guided-setup')
  22. // Check that we ware on the login page
  23. expect(view.getByText('Username / Email')).toBeInTheDocument()
  24. expect(view.getByText('Password')).toBeInTheDocument()
  25. expect(view.getByText('Sign in')).toBeInTheDocument()
  26. })
  27. })
  28. describe('when system is not ready', () => {
  29. beforeEach(() => {
  30. mockApplicationConfig({
  31. system_init_done: false,
  32. })
  33. })
  34. it('shows guided setup screen and opens manual setup on click', async () => {
  35. mockSystemSetupInfoQuery({
  36. systemSetupInfo: {
  37. status: EnumSystemSetupInfoStatus.New,
  38. type: null,
  39. },
  40. })
  41. mockSystemSetupLockMutation({
  42. systemSetupLock: {
  43. resource: 'Zammad::System::Setup',
  44. value: 'random-uuid',
  45. },
  46. })
  47. const view = await visitView('/guided-setup')
  48. const manualSetupButton = view.getByText('Set up a new system')
  49. expect(manualSetupButton).toBeInTheDocument()
  50. expect(
  51. view.getByText('Or migrate from another system'),
  52. ).toBeInTheDocument()
  53. await view.events.click(manualSetupButton)
  54. await vi.waitFor(() => {
  55. expect(
  56. view,
  57. 'correctly redirects to guided setup manual',
  58. ).toHaveCurrentUrl('/guided-setup/manual')
  59. })
  60. expect(view.getByRole('button', { name: 'Go Back' })).toBeInTheDocument()
  61. expect(view.getByText('Create Administrator Account')).toBeInTheDocument()
  62. })
  63. it('shows guided setup screen and opens import setup on click', async () => {
  64. mockSystemSetupInfoQuery({
  65. systemSetupInfo: {
  66. status: EnumSystemSetupInfoStatus.New,
  67. type: null,
  68. },
  69. })
  70. mockSystemSetupLockMutation({
  71. systemSetupLock: {
  72. resource: 'Zammad::System::Setup',
  73. value: 'random-uuid',
  74. },
  75. })
  76. const view = await visitView('/guided-setup')
  77. const importSetupButton = view.getByText('Or migrate from another system')
  78. expect(importSetupButton).toBeInTheDocument()
  79. await view.events.click(importSetupButton)
  80. await vi.waitFor(() => {
  81. expect(
  82. view,
  83. 'correctly redirects to guided setup import',
  84. ).toHaveCurrentUrl('/guided-setup/import')
  85. })
  86. expect(
  87. view.getByRole('button', { name: 'Freshdesk Beta' }),
  88. ).toBeInTheDocument()
  89. expect(
  90. view.getByRole('button', { name: 'Kayako Beta' }),
  91. ).toBeInTheDocument()
  92. expect(
  93. view.getByRole('button', { name: 'OTRS Beta' }),
  94. ).toBeInTheDocument()
  95. expect(
  96. view.getByRole('button', { name: 'Zendesk Beta' }),
  97. ).toBeInTheDocument()
  98. expect(view.getByRole('button', { name: 'Go Back' })).toBeInTheDocument()
  99. })
  100. it('shows guided setup manual screen when lock exists', async () => {
  101. mockSystemSetupInfo({
  102. status: EnumSystemSetupInfoStatus.InProgress,
  103. type: EnumSystemSetupInfoType.Manual,
  104. lockValue: 'random-uuid-lock',
  105. })
  106. mockSystemSetupInfoQuery({
  107. systemSetupInfo: {
  108. status: EnumSystemSetupInfoStatus.InProgress,
  109. type: EnumSystemSetupInfoType.Manual,
  110. },
  111. })
  112. const view = await visitView('/guided-setup')
  113. await vi.waitFor(() => {
  114. expect(
  115. view,
  116. 'correctly redirects to guided setup manual',
  117. ).toHaveCurrentUrl('/guided-setup/manual')
  118. })
  119. expect(view.getByRole('button', { name: 'Go Back' })).toBeInTheDocument()
  120. expect(view.getByText('Create Administrator Account')).toBeInTheDocument()
  121. })
  122. it('redirects to home screen on back navigation, if the setup was completed', async () => {
  123. mockSystemSetupInfoQuery({
  124. systemSetupInfo: {
  125. status: EnumSystemSetupInfoStatus.New,
  126. type: null,
  127. },
  128. })
  129. const view = await visitView('/guided-setup')
  130. await view.events.click(view.getByText('Set up a new system'))
  131. await vi.waitFor(() => {
  132. expect(
  133. view,
  134. 'correctly redirects to guided setup manual',
  135. ).toHaveCurrentUrl('/guided-setup/manual')
  136. })
  137. mockSystemSetupInfoQuery({
  138. systemSetupInfo: {
  139. status: EnumSystemSetupInfoStatus.Done,
  140. type: null,
  141. },
  142. })
  143. const { setSystemSetupInfo } = useSystemSetupInfoStore()
  144. await setSystemSetupInfo()
  145. const router = getTestRouter()
  146. router.back()
  147. await vi.waitFor(() => {
  148. expect(view, 'correctly redirects to home screen').toHaveCurrentUrl('/')
  149. })
  150. })
  151. })
  152. })