signup-verify.spec.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 { getByIconName } from '#tests/support/components/iconQueries.ts'
  5. import { getTestRouter } from '#tests/support/components/renderComponent.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 home 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('Home')
  56. })
  57. })
  58. })