test(#357): Router-Test gefixt (QueryClientProvider+Mocks, 2/2 passed); Geister-Test ContactEditModal nach §10 gelöscht (Komponente weg seit db4701b)
This commit is contained in:
@@ -1,84 +0,0 @@
|
||||
import React from 'react';
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
||||
|
||||
// ContactEditModal imports UI components that transitively load lucide-react.
|
||||
// To avoid OOM in the vitest worker, we test via a stub that validates the
|
||||
// component's interface contract (props, rendering, callbacks).
|
||||
vi.mock('@/components/contacts/ContactEditModal', () => ({
|
||||
ContactEditModal: ({ open, onClose, contact, onSaved }: any) => {
|
||||
if (!open) return null;
|
||||
const isEdit = !!contact;
|
||||
return (
|
||||
<div data-testid="modal-stub">
|
||||
<h2>{isEdit ? 'Kontakt bearbeiten' : 'Kontakt erstellen'}</h2>
|
||||
<select data-testid="contact-type-select" defaultValue="company">
|
||||
<option value="company">Firmen</option>
|
||||
<option value="person">Personen</option>
|
||||
</select>
|
||||
<input data-testid="contact-name-input" placeholder="Firmenname" />
|
||||
<input data-testid="contact-first-name-input" placeholder="Vorname" style={{ display: 'none' }} />
|
||||
<input data-testid="contact-last-name-input" placeholder="Nachname" style={{ display: 'none' }} />
|
||||
<input data-testid="contact-submit-btn" type="submit" value={isEdit ? 'Speichern' : 'Erstellen'} />
|
||||
<button onClick={onClose}>Abbrechen</button>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
}));
|
||||
|
||||
import { ContactEditModal } from '@/components/contacts/ContactEditModal';
|
||||
|
||||
const defaultProps = {
|
||||
open: true,
|
||||
onClose: vi.fn(),
|
||||
contact: null,
|
||||
onSaved: vi.fn(),
|
||||
};
|
||||
|
||||
describe('ContactEditModal', () => {
|
||||
it('renders modal when open', () => {
|
||||
render(<ContactEditModal {...defaultProps} />);
|
||||
expect(screen.getByTestId('modal-stub')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not render when closed', () => {
|
||||
render(<ContactEditModal {...defaultProps} open={false} />);
|
||||
expect(screen.queryByTestId('modal-stub')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders type select', () => {
|
||||
render(<ContactEditModal {...defaultProps} />);
|
||||
expect(screen.getByTestId('contact-type-select')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders name input for company type', () => {
|
||||
render(<ContactEditModal {...defaultProps} />);
|
||||
expect(screen.getByTestId('contact-name-input')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders submit button', () => {
|
||||
render(<ContactEditModal {...defaultProps} />);
|
||||
expect(screen.getByTestId('contact-submit-btn')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders cancel button', () => {
|
||||
render(<ContactEditModal {...defaultProps} />);
|
||||
expect(screen.getByText(/abbrechen/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('calls onClose when cancel button clicked', () => {
|
||||
render(<ContactEditModal {...defaultProps} />);
|
||||
fireEvent.click(screen.getByText(/abbrechen/i));
|
||||
expect(defaultProps.onClose).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('renders create title for new contact', () => {
|
||||
render(<ContactEditModal {...defaultProps} />);
|
||||
expect(screen.getByText('Kontakt erstellen')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders edit title when editing existing contact', () => {
|
||||
render(<ContactEditModal {...defaultProps} contact={{ id: 'c1', type: 'company' } as any} />);
|
||||
expect(screen.getByText('Kontakt bearbeiten')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -1,22 +1,41 @@
|
||||
import React from 'react';
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { render, screen, act } from '@testing-library/react';
|
||||
import { MemoryRouter, Route, Routes, Navigate } from 'react-router-dom';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { MemoryRouter, Route, Routes } from 'react-router-dom';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { ProtectedRoute } from '@/routes/ProtectedRoute';
|
||||
import { useAuthStore } from '@/store/authStore';
|
||||
|
||||
// Mock API hooks used by useAuth (ProtectedRoute → useAuth → useCurrentUser)
|
||||
vi.mock('@/api/hooks', () => ({
|
||||
useCurrentUser: () => ({ data: null, isLoading: false, isError: false, error: null }),
|
||||
}));
|
||||
|
||||
// Mock permissions fetch (useAuth → useUserPermissions → apiGet)
|
||||
vi.mock('@/hooks/useUserPermissions', () => ({
|
||||
useUserPermissions: () => ({}),
|
||||
}));
|
||||
|
||||
function ProtectedTest() {
|
||||
const client = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: { retry: false, staleTime: 0, gcTime: 0 },
|
||||
mutations: { retry: false },
|
||||
},
|
||||
});
|
||||
return (
|
||||
<MemoryRouter initialEntries={['/dashboard']}>
|
||||
<Routes>
|
||||
<Route path="/login" element={<div data-testid="login-page">Login</div>} />
|
||||
<Route path="/dashboard" element={
|
||||
<ProtectedRoute>
|
||||
<div data-testid="protected-content">Protected</div>
|
||||
</ProtectedRoute>
|
||||
} />
|
||||
</Routes>
|
||||
</MemoryRouter>
|
||||
<QueryClientProvider client={client}>
|
||||
<MemoryRouter initialEntries={['/dashboard']}>
|
||||
<Routes>
|
||||
<Route path="/login" element={<div data-testid="login-page">Login</div>} />
|
||||
<Route path="/dashboard" element={
|
||||
<ProtectedRoute>
|
||||
<div data-testid="protected-content">Protected</div>
|
||||
</ProtectedRoute>
|
||||
} />
|
||||
</Routes>
|
||||
</MemoryRouter>
|
||||
</QueryClientProvider>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user