T07a: frontend core SPA — shell + auth + routing + i18n + UI library + a11y
- React 18 + Vite + TypeScript + Tailwind CSS setup - AppShell with Sidebar (plugin menu) + TopBar (tenant switcher, search, notifications, user menu) - Auth pages: Login, PasswordResetRequest, PasswordResetConfirm - Protected routes with auth guard - API client (axios with interceptors: session cookie, 401 redirect, 422 validation) - TanStack Query hooks for auth, users, companies, contacts, notifications - Zustand stores: authStore, uiStore - i18n setup (de/en locales) with react-i18next - UI component library: Button, Input, Select, Modal, Toast, Table, Card, Badge, Avatar, Pagination, EmptyState, Skeleton, ConfirmDialog - Accessibility: ARIA labels, 44px touch targets, keyboard nav, reduced-motion, sr-only - Design tokens from prototype as CSS custom properties - 111 tests passing across 20 test files - tsc --noEmit: 0 errors - npm run build: success (471KB JS, 24KB CSS)
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import React from 'react';
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import { ConfirmDialog } from '@/components/ui/ConfirmDialog';
|
||||
|
||||
describe('ConfirmDialog', () => {
|
||||
it('renders nothing when open=false', () => {
|
||||
render(<ConfirmDialog open={false} message="Wirklich löschen?" onConfirm={() => {}} onCancel={() => {}} />);
|
||||
expect(screen.queryByText('Wirklich löschen?')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders message when open=true', () => {
|
||||
render(<ConfirmDialog open={true} message="Wirklich löschen?" onConfirm={() => {}} onCancel={() => {}} />);
|
||||
expect(screen.getByText('Wirklich löschen?')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('calls onConfirm when confirm button clicked', () => {
|
||||
const onConfirm = vi.fn();
|
||||
render(<ConfirmDialog open={true} message="Löschen?" onConfirm={onConfirm} onCancel={() => {}} />);
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Bestätigen' }));
|
||||
expect(onConfirm).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('calls onCancel when cancel button clicked', () => {
|
||||
const onCancel = vi.fn();
|
||||
render(<ConfirmDialog open={true} message="Löschen?" onConfirm={() => {}} onCancel={onCancel} />);
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Abbrechen' }));
|
||||
expect(onCancel).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('renders default title', () => {
|
||||
render(<ConfirmDialog open={true} message="Test" onConfirm={() => {}} onCancel={() => {}} />);
|
||||
expect(screen.getByText('Bestätigung erforderlich')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders custom title', () => {
|
||||
render(<ConfirmDialog open={true} title="Löschen bestätigen" message="Test" onConfirm={() => {}} onCancel={() => {}} />);
|
||||
expect(screen.getByText('Löschen bestätigen')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('uses danger variant button when variant=danger', () => {
|
||||
render(<ConfirmDialog open={true} variant="danger" message="Test" onConfirm={() => {}} onCancel={() => {}} />);
|
||||
const confirmBtn = screen.getByRole('button', { name: 'Bestätigen' });
|
||||
expect(confirmBtn.className).toContain('bg-danger-600');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user