signup-verify.spec.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { getByIconName } from '#tests/support/components/iconQueries.ts'
  3. import { getTestRouter } from '#tests/support/components/renderComponent.ts'
  4. import { visitView } from '#tests/support/components/visitView.ts'
  5. import { mockApplicationConfig } from '#tests/support/mock-applicationConfig.ts'
  6. import { mockUserSignupVerifyMutation } from '../graphql/mutations/userSignupVerify.mocks.ts'
  7. describe('signup verify view', () => {
  8. beforeEach(() => {
  9. mockApplicationConfig({
  10. user_create_account: true,
  11. })
  12. })
  13. it('shows an error message without the token parameter', async () => {
  14. const view = await visitView('/signup/verify')
  15. expect(
  16. view.getByText(
  17. 'Email could not be verified. Please contact your administrator.',
  18. ),
  19. ).toBeInTheDocument()
  20. })
  21. it('shows a loading indicator during the verification process', async () => {
  22. const view = await visitView('/signup/verify/123')
  23. expect(view.getByText('Verifying your email…')).toBeInTheDocument()
  24. const loader = view.getByRole('status')
  25. expect(getByIconName(loader, 'spinner')).toBeInTheDocument()
  26. })
  27. it('shows an error message when an invalid token is supplied', async () => {
  28. mockUserSignupVerifyMutation({
  29. userSignupVerify: {
  30. session: null,
  31. errors: [{ message: 'The provided token is invalid.' }],
  32. },
  33. })
  34. const view = await visitView('/signup/verify/123')
  35. expect(
  36. await view.findByText(
  37. 'Email could not be verified. Please contact your administrator.',
  38. ),
  39. ).toBeInTheDocument()
  40. })
  41. it('shows a success message when a valid token is supplied', async () => {
  42. const view = await visitView('/signup/verify/123')
  43. expect(
  44. await view.findByText('Woo hoo! Your email address has been verified!'),
  45. ).toBeInTheDocument()
  46. })
  47. it('redirects to dashboard screen when the verification was successful', async () => {
  48. vi.useFakeTimers()
  49. await visitView('/signup/verify/123')
  50. await vi.runAllTimersAsync()
  51. vi.useRealTimers()
  52. await vi.waitFor(() => {
  53. const router = getTestRouter()
  54. const route = router.currentRoute.value
  55. expect(route.name).toBe('Dashboard')
  56. })
  57. })
  58. })