guided-setup-manual-admin.spec.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 { EnumSystemSetupInfoStatus } from '#shared/graphql/types.ts'
  6. import { useAuthenticationStore } from '#shared/stores/authentication.ts'
  7. import { mockSystemSetupInfoQuery } from '../graphql/queries/systemSetupInfo.mocks.ts'
  8. import { useSystemSetupInfoStore } from '../stores/systemSetupInfo.ts'
  9. describe('guided setup admin user creation', () => {
  10. describe('when system initialization is done', () => {
  11. beforeEach(() => {
  12. mockApplicationConfig({
  13. system_init_done: true,
  14. })
  15. })
  16. it('redirects to login window', async () => {
  17. const view = await visitView('/guided-setup/manual')
  18. // Check that we ware on the login page
  19. expect(view.getByText('Username / Email')).toBeInTheDocument()
  20. expect(view.getByText('Password')).toBeInTheDocument()
  21. expect(view.getByText('Sign in')).toBeInTheDocument()
  22. })
  23. })
  24. describe('when system is not ready', () => {
  25. beforeEach(() => {
  26. mockApplicationConfig({
  27. system_init_done: false,
  28. })
  29. })
  30. afterEach(() => {
  31. vi.clearAllMocks()
  32. })
  33. it('shows guided setup screen and opens manual setup on click', async () => {
  34. mockSystemSetupInfoQuery({
  35. systemSetupInfo: {
  36. status: EnumSystemSetupInfoStatus.New,
  37. type: null,
  38. },
  39. })
  40. const view = await visitView('/guided-setup')
  41. view.getByText('Set up a new system').click()
  42. await vi.waitFor(() => {
  43. expect(
  44. view,
  45. 'correctly redirects to guided setup manual',
  46. ).toHaveCurrentUrl('/guided-setup/manual')
  47. })
  48. expect(view.getByText('Create Administrator Account')).toBeInTheDocument()
  49. const firstNameField = view.getByLabelText('First name')
  50. const lastNameField = view.getByLabelText('Last name')
  51. const emailField = view.getByLabelText('Email')
  52. const passwordField = view.getByLabelText('Password')
  53. const confirmPasswordField = view.getByLabelText('Confirm password')
  54. expect(firstNameField).toBeInTheDocument()
  55. expect(lastNameField).toBeInTheDocument()
  56. expect(emailField).toBeInTheDocument()
  57. expect(passwordField).toBeInTheDocument()
  58. expect(confirmPasswordField).toBeInTheDocument()
  59. await view.events.type(firstNameField, 'Bender')
  60. await view.events.type(lastNameField, 'Rodriguez')
  61. await view.events.type(emailField, 'bender.rodriguez@futurama.corp')
  62. await view.events.type(passwordField, 'planetexpress')
  63. await view.events.type(confirmPasswordField, 'planetexpress')
  64. const createUserCurrentButton = view.getByRole('button', {
  65. name: 'Create account',
  66. })
  67. await view.events.click(createUserCurrentButton)
  68. await vi.waitFor(() => {
  69. expect(
  70. view,
  71. 'correctly redirects to guided setup manual system information step',
  72. ).toHaveCurrentUrl('/guided-setup/manual/system-information')
  73. })
  74. expect(useAuthenticationStore().authenticated).toBe(true)
  75. // Redirects to home screen on back navigation, if the setup was completed.
  76. mockSystemSetupInfoQuery({
  77. systemSetupInfo: {
  78. status: EnumSystemSetupInfoStatus.Done,
  79. type: null,
  80. },
  81. })
  82. const { setSystemSetupInfo } = useSystemSetupInfoStore()
  83. await setSystemSetupInfo()
  84. const router = getTestRouter()
  85. router.back()
  86. await vi.waitFor(() => {
  87. expect(view, 'correctly redirects to home screen').toHaveCurrentUrl('/')
  88. })
  89. })
  90. })
  91. })