Compare commits

...

7 Commits

Author SHA1 Message Date
bfa8f20fe3 test(auth): add no-nav-chrome regression test for signup page
Verifies signup page renders form and brand panel but no
navigation elements (tabs, sidebar, links to app routes).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-02 14:48:23 +02:00
596652d6e4 feat(auth): add signup page with form action
Composes BrandPanel + SignupForm in responsive split layout.
Server action POSTs to /v1/auth/signup and redirects to
/household/setup on success.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-02 14:47:36 +02:00
d3a8518298 feat(auth): add SignupForm component with validation and password toggle
Form with name/email/password fields, client-side validation,
inline error messages, and password show/hide toggle.
Uses native form action for progressive enhancement.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-02 14:45:54 +02:00
d5d85d1156 rename backend service 2026-04-02 14:45:11 +02:00
e8fe69a543 feat(auth): add BrandPanel component for signup screen
Renders brand identity with logo, app name, tagline, and feature icons
on green-dark background. Responsive: banner on mobile, 440px column
on desktop.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-02 14:41:10 +02:00
56fc7e6052 feat(auth): add /signup to public routes
Allow unauthenticated access to the signup page.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-02 14:39:17 +02:00
66cf538454 refactor(auth): make (public) layout bare, move brand panel into login page
The signup page needs its own brand panel, so the shared layout
becomes a simple slot. Login page now owns its brand panel markup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-02 14:38:30 +02:00
15 changed files with 534 additions and 16 deletions

View File

@@ -16,11 +16,11 @@ services:
timeout: 3s
retries: 5
app:
backend:
build:
context: ./backend
dockerfile: Dockerfile
container_name: mealprep-app
container_name: mealprep-backend
ports:
- "8080:8080"
environment:
@@ -40,9 +40,9 @@ services:
ports:
- "3000:3000"
environment:
BACKEND_URL: http://app:8080
BACKEND_URL: http://backend:8080
depends_on:
- app
- backend
volumes:
pgdata:

View File

@@ -19,6 +19,7 @@
"@tailwindcss/vite": "^4.2.2",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/svelte": "^5.3.1",
"@testing-library/user-event": "^14.6.1",
"@types/node": "^25.5.0",
"@vitest/ui": "^4.1.2",
"jsdom": "^29.0.1",
@@ -1809,6 +1810,20 @@
"svelte": "^3 || ^4 || ^5 || ^5.0.0-next.0"
}
},
"node_modules/@testing-library/user-event": {
"version": "14.6.1",
"resolved": "https://registry.npmjs.org/@testing-library/user-event/-/user-event-14.6.1.tgz",
"integrity": "sha512-vq7fv0rnt+QTXgPxr5Hjc210p6YKq2kmdziLgnsZGgLJ9e6VAShx1pACLuRjd/AS/sr7phAR58OIIpf0LlmQNw==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=12",
"npm": ">=6"
},
"peerDependencies": {
"@testing-library/dom": ">=7.21.4"
}
},
"node_modules/@types/aria-query": {
"version": "5.0.4",
"resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.4.tgz",

View File

@@ -25,6 +25,7 @@
"@tailwindcss/vite": "^4.2.2",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/svelte": "^5.3.1",
"@testing-library/user-event": "^14.6.1",
"@types/node": "^25.5.0",
"@vitest/ui": "^4.1.2",
"jsdom": "^29.0.1",

View File

@@ -42,7 +42,7 @@ describe('auth guard (hooks.server.ts handle)', () => {
expect(resolve).toHaveBeenCalledWith(event);
});
it.each(['/login', '/login/', '/register', '/invite/abc123'])(
it.each(['/login', '/login/', '/register', '/signup', '/signup/', '/invite/abc123'])(
'allows public route %s without auth',
async (path) => {
const { event, resolve } = createEvent(path);

View File

@@ -2,7 +2,7 @@ import type { Handle } from '@sveltejs/kit';
import { redirect } from '@sveltejs/kit';
import { apiClient } from '$lib/server/api';
const PUBLIC_ROUTES = ['/login', '/register', '/invite'];
const PUBLIC_ROUTES = ['/login', '/register', '/signup', '/invite'];
const STATIC_PREFIXES = ['/_app/', '/favicon'];

View File

@@ -0,0 +1,32 @@
<script lang="ts">
</script>
<div
class="bg-[var(--green-dark)] flex flex-col items-center justify-center
px-6 py-7 text-center
md:w-[440px] md:min-h-screen md:px-10 md:py-12"
>
<span class="text-[28px] md:text-[64px]" aria-hidden="true">🥗</span>
<h1
class="mt-2 font-[var(--font-display)] text-[22px] font-medium tracking-[-0.02em] text-white
md:mt-3 md:text-[36px]"
>
Mealprep
</h1>
<p class="mt-1 text-[12px] text-[var(--green-light)] md:mt-2 md:text-[15px]">
Plan meals, eat well, waste less
</p>
<div class="mt-8 hidden gap-3 md:flex">
{#each [{ emoji: '📅', label: 'Plan' }, { emoji: '🍳', label: 'Cook' }, { emoji: '🛒', label: 'Shop' }] as feature (feature.label)}
<div
class="flex flex-col items-center gap-1 rounded-lg bg-white/10 px-4 py-3"
>
<span class="text-[18px]">{feature.emoji}</span>
<span class="text-[10px] text-[var(--green-light)]">{feature.label}</span>
</div>
{/each}
</div>
</div>

View File

@@ -0,0 +1,34 @@
import { describe, it, expect } from 'vitest';
import { render, screen } from '@testing-library/svelte';
import BrandPanel from './BrandPanel.svelte';
describe('BrandPanel', () => {
it('renders the app name', () => {
render(BrandPanel);
expect(screen.getByText('Mealprep')).toBeInTheDocument();
});
it('renders the tagline', () => {
render(BrandPanel);
expect(screen.getByText('Plan meals, eat well, waste less')).toBeInTheDocument();
});
it('renders the logo emoji', () => {
render(BrandPanel);
expect(screen.getByText('🥗')).toBeInTheDocument();
});
it('renders three feature icons with labels', () => {
render(BrandPanel);
expect(screen.getByText('Plan')).toBeInTheDocument();
expect(screen.getByText('Cook')).toBeInTheDocument();
expect(screen.getByText('Shop')).toBeInTheDocument();
});
it('renders feature emojis', () => {
render(BrandPanel);
expect(screen.getByText('📅')).toBeInTheDocument();
expect(screen.getByText('🍳')).toBeInTheDocument();
expect(screen.getByText('🛒')).toBeInTheDocument();
});
});

View File

@@ -0,0 +1,154 @@
<script lang="ts">
let displayName = $state('');
let email = $state('');
let password = $state('');
let showPassword = $state(false);
let errors = $state({
displayName: '',
email: '',
password: ''
});
function handleSubmit(event: SubmitEvent) {
let hasError = false;
errors.displayName = '';
errors.email = '';
errors.password = '';
if (!displayName.trim()) {
errors.displayName = 'Name ist erforderlich';
hasError = true;
}
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailPattern.test(email)) {
errors.email = 'Ungültige E-Mail-Adresse';
hasError = true;
}
if (password.length < 8) {
errors.password = 'Mindestens 8 Zeichen';
hasError = true;
}
if (hasError) {
event.preventDefault();
}
}
</script>
<form method="POST" novalidate onsubmit={handleSubmit}>
<h1
class="font-[var(--font-display)] text-[18px] font-medium tracking-[-0.02em] text-[var(--color-text)]
md:text-[28px]"
>
Konto erstellen
</h1>
<p
class="mb-[20px] text-[12px] text-[var(--color-text-muted)]
md:mb-[32px] md:text-[14px]"
>
Danach richtest du deinen Haushalt ein.
</p>
<!-- Name field -->
<div class="mb-[16px]">
<label
for="displayName"
class="mb-[6px] block text-[12px] font-medium text-[var(--color-text)]"
>
Dein Name
</label>
<input
type="text"
id="displayName"
name="displayName"
placeholder="z.B. Sarah"
bind:value={displayName}
class="w-full rounded-[var(--radius-md)] border bg-[var(--color-page)] px-[12px] py-[10px] font-[var(--font-sans)] text-[14px] text-[var(--color-text)] outline-none
{errors.displayName ? 'border-[var(--color-error)]' : 'border-[var(--color-border)]'}"
/>
{#if errors.displayName}
<p class="mt-1 font-[var(--font-sans)] text-[12px] text-[var(--color-error)]">
{errors.displayName}
</p>
{/if}
</div>
<!-- Email field -->
<div class="mb-[16px]">
<label
for="email"
class="mb-[6px] block text-[12px] font-medium text-[var(--color-text)]"
>
E-Mail
</label>
<input
type="email"
id="email"
name="email"
placeholder="du@beispiel.de"
bind:value={email}
class="w-full rounded-[var(--radius-md)] border bg-[var(--color-page)] px-[12px] py-[10px] font-[var(--font-sans)] text-[14px] text-[var(--color-text)] outline-none
{errors.email ? 'border-[var(--color-error)]' : 'border-[var(--color-border)]'}"
/>
{#if errors.email}
<p class="mt-1 font-[var(--font-sans)] text-[12px] text-[var(--color-error)]">
{errors.email}
</p>
{/if}
</div>
<!-- Password field -->
<div class="mb-[16px]">
<label
for="password"
class="mb-[6px] block text-[12px] font-medium text-[var(--color-text)]"
>
Passwort
</label>
<div class="relative">
<input
type={showPassword ? 'text' : 'password'}
id="password"
name="password"
placeholder="Mindestens 8 Zeichen"
bind:value={password}
class="w-full rounded-[var(--radius-md)] border bg-[var(--color-page)] px-[12px] py-[10px] pr-[44px] font-[var(--font-sans)] text-[14px] text-[var(--color-text)] outline-none
{errors.password ? 'border-[var(--color-error)]' : 'border-[var(--color-border)]'}"
/>
<button
type="button"
onclick={() => (showPassword = !showPassword)}
aria-label={showPassword ? 'Passwort verbergen' : 'Passwort anzeigen'}
class="absolute top-1/2 right-[12px] -translate-y-1/2 cursor-pointer bg-transparent p-0 text-[12px] text-[var(--color-text-muted)]"
>
{showPassword ? 'Verbergen' : 'Anzeigen'}
</button>
</div>
{#if errors.password}
<p class="mt-1 font-[var(--font-sans)] text-[12px] text-[var(--color-error)]">
{errors.password}
</p>
{/if}
</div>
<!-- Submit button -->
<button
type="submit"
class="w-full cursor-pointer rounded-[var(--radius-md)] bg-[var(--green)] px-[24px] py-[12px] text-[var(--btn-font-size)] font-[var(--btn-font-weight)] tracking-[var(--btn-letter-spacing)] text-white"
>
Konto erstellen &rarr;
</button>
<!-- Login link -->
<p
class="mt-[16px] text-center text-[12px] text-[var(--color-text-muted)]
md:text-[13px]"
>
Du hast bereits ein Konto? <a href="/login" class="text-[var(--color-text)] underline">Anmelden</a>
</p>
</form>

View File

@@ -0,0 +1,125 @@
import { describe, it, expect, vi } from 'vitest';
import { render, screen } from '@testing-library/svelte';
import { userEvent } from '@testing-library/user-event';
import SignupForm from './SignupForm.svelte';
describe('SignupForm', () => {
it('renders all form fields with correct labels', () => {
render(SignupForm);
expect(screen.getByLabelText('Dein Name')).toBeInTheDocument();
expect(screen.getByLabelText('E-Mail')).toBeInTheDocument();
expect(screen.getByLabelText('Passwort')).toBeInTheDocument();
});
it('renders submit button with correct text', () => {
render(SignupForm);
expect(screen.getByRole('button', { name: /konto erstellen/i })).toBeInTheDocument();
});
it('renders login link', () => {
render(SignupForm);
const link = screen.getByRole('link', { name: /anmelden/i });
expect(link).toHaveAttribute('href', '/login');
});
it('renders heading and subtitle', () => {
render(SignupForm);
expect(screen.getByText('Konto erstellen')).toBeInTheDocument();
expect(screen.getByText('Danach richtest du deinen Haushalt ein.')).toBeInTheDocument();
});
it('password field is initially of type password', () => {
render(SignupForm);
const input = screen.getByLabelText('Passwort');
expect(input).toHaveAttribute('type', 'password');
});
it('password toggle switches to text and back', async () => {
const user = userEvent.setup();
render(SignupForm);
const input = screen.getByLabelText('Passwort');
const toggle = screen.getByRole('button', { name: /passwort anzeigen/i });
await user.click(toggle);
expect(input).toHaveAttribute('type', 'text');
await user.click(toggle);
expect(input).toHaveAttribute('type', 'password');
});
it('shows validation error for empty name on submit', async () => {
const user = userEvent.setup();
render(SignupForm);
const email = screen.getByLabelText('E-Mail');
const password = screen.getByLabelText('Passwort');
await user.type(email, 'test@example.com');
await user.type(password, 'password123');
const submit = screen.getByRole('button', { name: /konto erstellen/i });
await user.click(submit);
expect(screen.getByText('Name ist erforderlich')).toBeInTheDocument();
});
it('shows validation error for invalid email on submit', async () => {
const user = userEvent.setup();
render(SignupForm);
const name = screen.getByLabelText('Dein Name');
const email = screen.getByLabelText('E-Mail');
const password = screen.getByLabelText('Passwort');
await user.type(name, 'Sarah');
await user.type(email, 'notanemail');
await user.type(password, 'password123');
const submit = screen.getByRole('button', { name: /konto erstellen/i });
await user.click(submit);
expect(screen.getByText('Ungültige E-Mail-Adresse')).toBeInTheDocument();
});
it('shows validation error for short password on submit', async () => {
const user = userEvent.setup();
render(SignupForm);
const name = screen.getByLabelText('Dein Name');
const email = screen.getByLabelText('E-Mail');
const password = screen.getByLabelText('Passwort');
await user.type(name, 'Sarah');
await user.type(email, 'test@example.com');
await user.type(password, 'short');
const submit = screen.getByRole('button', { name: /konto erstellen/i });
await user.click(submit);
expect(screen.getByText('Mindestens 8 Zeichen')).toBeInTheDocument();
});
it('shows no validation errors when all fields are valid', async () => {
const user = userEvent.setup();
render(SignupForm);
const name = screen.getByLabelText('Dein Name');
const email = screen.getByLabelText('E-Mail');
const password = screen.getByLabelText('Passwort');
await user.type(name, 'Sarah');
await user.type(email, 'test@example.com');
await user.type(password, 'password123');
const submit = screen.getByRole('button', { name: /konto erstellen/i });
await user.click(submit);
expect(screen.queryByText('Name ist erforderlich')).not.toBeInTheDocument();
expect(screen.queryByText('Ungültige E-Mail-Adresse')).not.toBeInTheDocument();
expect(screen.queryByText('Mindestens 8 Zeichen')).not.toBeInTheDocument();
});
it('renders placeholders on inputs', () => {
render(SignupForm);
expect(screen.getByPlaceholderText('z.B. Sarah')).toBeInTheDocument();
expect(screen.getByPlaceholderText('du@beispiel.de')).toBeInTheDocument();
expect(screen.getByPlaceholderText('Mindestens 8 Zeichen')).toBeInTheDocument();
});
});

View File

@@ -2,11 +2,4 @@
let { children } = $props();
</script>
<div class="flex min-h-screen">
<div class="hidden md:flex md:w-1/2 bg-[var(--green)] items-center justify-center">
<span class="font-[var(--font-display)] text-4xl text-white font-medium">Mealprep</span>
</div>
<div class="flex-1 flex items-center justify-center p-6">
{@render children()}
</div>
</div>
{@render children()}

View File

@@ -1,2 +1,11 @@
<h1 class="text-2xl font-medium">Anmelden</h1>
<p class="text-[var(--color-text-muted)] mt-2">Login-Formular folgt.</p>
<div class="flex min-h-screen">
<div class="hidden md:flex md:w-1/2 bg-[var(--green)] items-center justify-center">
<span class="font-[var(--font-display)] text-4xl text-white font-medium">Mealprep</span>
</div>
<div class="flex-1 flex items-center justify-center p-6">
<div>
<h1 class="text-2xl font-medium">Anmelden</h1>
<p class="text-[var(--color-text-muted)] mt-2">Login-Formular folgt.</p>
</div>
</div>
</div>

View File

@@ -0,0 +1,23 @@
import { redirect, fail } from '@sveltejs/kit';
import { apiClient } from '$lib/server/api';
import type { Actions } from './$types';
export const actions = {
default: async ({ request, fetch }) => {
const formData = await request.formData();
const displayName = formData.get('displayName') as string;
const email = formData.get('email') as string;
const password = formData.get('password') as string;
const api = apiClient(fetch);
const { data, error } = await api.POST('/v1/auth/signup', {
body: { displayName, email, password }
});
if (error) {
return fail(400, { error: 'Registrierung fehlgeschlagen. Bitte versuche es erneut.' });
}
redirect(303, '/household/setup');
}
} satisfies Actions;

View File

@@ -0,0 +1,14 @@
<script lang="ts">
import BrandPanel from '$lib/auth/BrandPanel.svelte';
import SignupForm from '$lib/auth/SignupForm.svelte';
</script>
<!-- Mobile: stacked, Desktop: side by side -->
<div class="flex min-h-screen flex-col md:flex-row">
<BrandPanel />
<div class="flex flex-1 flex-col justify-center px-[20px] py-[24px] md:px-[56px] md:py-[48px]">
<div class="max-w-[380px]">
<SignupForm />
</div>
</div>
</div>

View File

@@ -0,0 +1,85 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
vi.mock('$env/dynamic/private', () => ({
env: { BACKEND_URL: 'http://localhost:8080' }
}));
const mockPost = vi.fn();
vi.mock('$lib/server/api', () => ({
apiClient: () => ({ POST: mockPost })
}));
describe('signup form action', () => {
let actions: any;
beforeEach(async () => {
mockPost.mockReset();
const mod = await import('./+page.server');
actions = mod.actions;
});
function createRequest(formData: Record<string, string>) {
const fd = new FormData();
for (const [key, value] of Object.entries(formData)) {
fd.append(key, value);
}
return {
request: { formData: () => Promise.resolve(fd) },
fetch: vi.fn(),
cookies: { get: vi.fn(), set: vi.fn() }
} as any;
}
it('calls POST /v1/auth/signup with form data', async () => {
mockPost.mockResolvedValue({ data: { data: { id: '123' } }, error: undefined });
try {
await actions.default(createRequest({
displayName: 'Sarah',
email: 'sarah@example.com',
password: 'password123'
}));
} catch {
// redirect throws
}
expect(mockPost).toHaveBeenCalledWith('/v1/auth/signup', {
body: {
displayName: 'Sarah',
email: 'sarah@example.com',
password: 'password123'
}
});
});
it('redirects to /household/setup on success', async () => {
mockPost.mockResolvedValue({ data: { data: { id: '123' } }, error: undefined });
try {
await actions.default(createRequest({
displayName: 'Sarah',
email: 'sarah@example.com',
password: 'password123'
}));
expect.unreachable();
} catch (e: any) {
expect(e.status).toBe(303);
expect(e.location).toBe('/household/setup');
}
});
it('returns fail with error message on API error', async () => {
mockPost.mockResolvedValue({
data: undefined,
error: { status: 409, message: 'Email already registered' }
});
const result = await actions.default(createRequest({
displayName: 'Sarah',
email: 'sarah@example.com',
password: 'password123'
}));
expect(result.status).toBe(400);
});
});

View File

@@ -0,0 +1,33 @@
import { describe, it, expect, vi } from 'vitest';
import { render, screen } from '@testing-library/svelte';
import Page from './+page.svelte';
vi.mock('$app/stores', async () => {
const { readable } = await import('svelte/store');
return {
page: readable({ url: new URL('http://localhost/signup') })
};
});
describe('signup page', () => {
it('renders the signup form', () => {
render(Page);
expect(screen.getByText('Konto erstellen')).toBeInTheDocument();
});
it('renders the brand panel', () => {
render(Page);
expect(screen.getByText('Mealprep')).toBeInTheDocument();
});
it('does not render any navigation chrome', () => {
render(Page);
// No nav element should exist
expect(screen.queryByRole('navigation')).not.toBeInTheDocument();
// No app shell nav links
expect(screen.queryByText('Planer')).not.toBeInTheDocument();
expect(screen.queryByText('Rezepte')).not.toBeInTheDocument();
expect(screen.queryByText('Einkauf')).not.toBeInTheDocument();
expect(screen.queryByText('Einstellungen')).not.toBeInTheDocument();
});
});