Files
ToBePlayed-Frontend/src/components/ResendConfirmation.test.jsx
T
lobo 6dda186bdf
Build, Test & Push Frontend / quality-check (push) Successful in 26s
Build, Test & Push Frontend / docker (push) Successful in 31s
feat(registration): add email confirmation UI
New ConfirmEmailPage for users to verify their email and set password.
Resend form on registration and error pages. Registration form no
longer asks for a password. Confirmation requires a button click. The
admin list marks unconfirmed requests and offers only delete for them.
2026-10-01 16:20:51 +02:00

38 lines
1.5 KiB
React

// @vitest-environment jsdom
import {afterEach, describe, expect, it, vi} from 'vitest';
import {cleanup, fireEvent, render, screen} from '@testing-library/react';
import ResendConfirmation from './ResendConfirmation.jsx';
import {fetchRoutes, json} from '../test/fetchRoutes.js';
vi.mock('react-i18next', () => ({
useTranslation: () => ({
t: (key, options) => (options?.minutes === undefined ? key : `${key}:${options.minutes}`),
i18n: {language: 'de'},
}),
}));
describe('ResendConfirmation', () => {
afterEach(cleanup);
it('sends the prefilled address and shows the same answer for any address', async () => {
const mock = fetchRoutes({'POST /api/registration/resend': json(204, null)});
render(<ResendConfirmation defaultEmail="a@b.de"/>);
fireEvent.click(screen.getByRole('button', {name: 'REGISTRATION.RESEND'}));
expect(await screen.findByText('REGISTRATION.RESEND_SENT')).toBeTruthy();
expect(JSON.parse(mock.mock.calls[0][1].body)).toEqual({email: 'a@b.de'});
});
it('shows the wait time when the IP is blocked', async () => {
fetchRoutes({
'POST /api/registration/resend': {...json(429, {}), headers: new Headers({'Retry-After': '900'})},
});
render(<ResendConfirmation/>);
fireEvent.click(screen.getByRole('button', {name: 'REGISTRATION.RESEND'}));
expect(await screen.findByText('REGISTRATION.ERROR_TOO_MANY_ATTEMPTS:15')).toBeTruthy();
});
});