test(profile,documents): cover PasswordChangeForm and FileSectionNew branches
PasswordChangeForm: tests the null/success/error/mismatch banner branches plus the form action wiring. FileSectionNew: tests the no-file/file-selected toggle, onfileParsed callback invocation with the parsed metadata, the early-return when no file is in the change event, and the suggestedTitle fallback path. Eleven tests across two files. Both follow the UploadZone template (props, File API synthetic input, vi.fn() callback spies). Refs #496. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { describe, it, expect, afterEach } from 'vitest';
|
||||
import { cleanup, render } from 'vitest-browser-svelte';
|
||||
import { page } from 'vitest/browser';
|
||||
import PasswordChangeForm from './PasswordChangeForm.svelte';
|
||||
|
||||
afterEach(cleanup);
|
||||
|
||||
describe('PasswordChangeForm', () => {
|
||||
it('renders the three password inputs and a save button by default', async () => {
|
||||
render(PasswordChangeForm, { props: { form: null } });
|
||||
|
||||
await expect.element(page.getByRole('heading', { name: /passwort ändern/i })).toBeVisible();
|
||||
await expect.element(page.getByRole('button', { name: /speichern/i })).toBeVisible();
|
||||
});
|
||||
|
||||
it('does not render any banner when form is null', async () => {
|
||||
render(PasswordChangeForm, { props: { form: null } });
|
||||
|
||||
await expect.element(page.getByText(/erfolgreich geändert/i)).not.toBeInTheDocument();
|
||||
await expect.element(page.getByText(/stimmen nicht überein/i)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows the success banner when form.passwordSuccess is true', async () => {
|
||||
render(PasswordChangeForm, { props: { form: { passwordSuccess: true } } });
|
||||
|
||||
await expect.element(page.getByText('Passwort erfolgreich geändert.')).toBeVisible();
|
||||
});
|
||||
|
||||
it('shows the localised mismatch message for the PASSWORDS_DO_NOT_MATCH error code', async () => {
|
||||
render(PasswordChangeForm, {
|
||||
props: { form: { passwordError: 'PASSWORDS_DO_NOT_MATCH' } }
|
||||
});
|
||||
|
||||
await expect
|
||||
.element(page.getByText('Die neuen Passwörter stimmen nicht überein.'))
|
||||
.toBeVisible();
|
||||
});
|
||||
|
||||
it('shows the raw error message for any non-matching error code', async () => {
|
||||
render(PasswordChangeForm, {
|
||||
props: { form: { passwordError: 'Server-side error message' } }
|
||||
});
|
||||
|
||||
await expect.element(page.getByText('Server-side error message')).toBeVisible();
|
||||
});
|
||||
|
||||
it('declares POST as the form method and routes to the changePassword action', async () => {
|
||||
render(PasswordChangeForm, { props: { form: null } });
|
||||
|
||||
const form = document.querySelector('form');
|
||||
expect(form?.getAttribute('method')).toBe('POST');
|
||||
expect(form?.getAttribute('action')).toBe('?/changePassword');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user