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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { mockApplicationConfig } from '#tests/support/mock-applicationConfig.ts'
  3. import { visitView } from '#tests/support/components/visitView.ts'
  4. import { EnumSystemSetupInfoStatus } from '#shared/graphql/types.ts'
  5. import { useAuthenticationStore } from '#shared/stores/authentication.ts'
  6. import { mockSystemSetupInfoQuery } from '../graphql/queries/systemSetupInfo.mocks.ts'
  7. describe('guided setup admin user creation', () => {
  8. describe('when system initialization is done', () => {
  9. beforeEach(() => {
  10. mockApplicationConfig({
  11. system_init_done: true,
  12. })
  13. })
  14. it('redirects to login window', async () => {
  15. const view = await visitView('/guided-setup/manual')
  16. // Check that we ware on the login page
  17. expect(view.getByText('Username / Email')).toBeInTheDocument()
  18. expect(view.getByText('Password')).toBeInTheDocument()
  19. expect(view.getByText('Sign in')).toBeInTheDocument()
  20. })
  21. })
  22. describe('when system is not ready', () => {
  23. beforeEach(() => {
  24. mockApplicationConfig({
  25. system_init_done: false,
  26. })
  27. })
  28. it('shows guided setup screen and opens manual setup on click', async () => {
  29. mockSystemSetupInfoQuery({
  30. systemSetupInfo: {
  31. status: EnumSystemSetupInfoStatus.New,
  32. type: null,
  33. },
  34. })
  35. const view = await visitView('/guided-setup')
  36. view.getByText('Set up a new system').click()
  37. await vi.waitFor(() => {
  38. expect(
  39. view,
  40. 'correctly redirects to guided setup manual',
  41. ).toHaveCurrentUrl('/guided-setup/manual')
  42. })
  43. expect(view.getByText('Create Administrator Account')).toBeInTheDocument()
  44. const firstNameField = view.getByLabelText('First name')
  45. const lastNameField = view.getByLabelText('Last name')
  46. const emailField = view.getByLabelText('Email')
  47. const passwordField = view.getByLabelText('Password')
  48. const confirmPasswordField = view.getByLabelText('Confirm password')
  49. expect(firstNameField).toBeInTheDocument()
  50. expect(lastNameField).toBeInTheDocument()
  51. expect(emailField).toBeInTheDocument()
  52. expect(passwordField).toBeInTheDocument()
  53. expect(confirmPasswordField).toBeInTheDocument()
  54. await view.events.type(firstNameField, 'Bender')
  55. await view.events.type(lastNameField, 'Rodriguez')
  56. await view.events.type(emailField, 'bender.rodriguez@futurama.corp')
  57. await view.events.type(passwordField, 'planetexpress')
  58. await view.events.type(confirmPasswordField, 'planetexpress')
  59. const createAccountButton = view.getByRole('button', {
  60. name: 'Create account',
  61. })
  62. await view.events.click(createAccountButton)
  63. await vi.waitFor(() => {
  64. expect(
  65. view,
  66. 'correctly redirects to guided setup manual system information step',
  67. ).toHaveCurrentUrl('/guided-setup/manual/system-information')
  68. })
  69. expect(useAuthenticationStore().authenticated).toBe(true)
  70. })
  71. })
  72. })