fix: Fix all 68 frontend test failures
P1 Code Bugs: - SettingsPlugins.tsx: Array.isArray guard for plugins.map (9 tests) - HtmlBlock.tsx: javascript: URL sanitization in href attributes (1 test, security fix) P2 Test-Setup (QueryClientProvider): - Dashboard.test.tsx: Add QueryClientProvider + dashboard mock (11 tests) - CalendarPage.test.tsx: Add QueryClientProvider + savedFilters mock (8 tests) - SessionList.test.tsx: Add QueryClientProvider (6 tests) - MailPage.test.tsx: Add QueryClientProvider + savedFilters mock (8 tests fixed) - DmsPage.test.tsx: Add QueryClientProvider + DMS API mocks (2 tests fixed) - SettingsSystem.test.tsx: Add QueryClientProvider + sub-page mocks (1 test fixed) P2 Test-Setup (ChevronDown Mock): - Reports.test.tsx: Add ChevronDown to lucide-react mock (5 tests) P3 Text Fix: - UploadDropzone.test.tsx: Fix umlaut Auswaehlen -> Auswahlen (1 test) Pre-existing Test Fixes (18 tests): - MailPage.test.tsx: Remove 6 obsolete tests (compose-btn, shared-mailbox-selector, etc. — now plugin toolbar actions) - DmsPage.test.tsx: Adapt 3 tests to new testids, remove 3 obsolete tests (upload/folder/search now plugin toolbar actions) - SettingsSystem.test.tsx: Remove 4 obsolete tests (form fields moved to sub-pages) - PluginRouteRenderer.test.tsx: Adapt test to loading spinner behavior - ShareDialog.test.tsx: Fix button text i18n mismatch
This commit is contained in:
@@ -1,8 +1,19 @@
|
||||
import React from 'react';
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { SessionList } from '@/components/ai/SessionList';
|
||||
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: { queries: { retry: false } },
|
||||
});
|
||||
|
||||
function renderWithProvider(ui: React.ReactElement) {
|
||||
return render(
|
||||
<QueryClientProvider client={queryClient}>{ui}</QueryClientProvider>
|
||||
);
|
||||
}
|
||||
|
||||
const mockSessions = [
|
||||
{ id: 's1', title: 'First Chat', folder_id: null, agent_id: null, is_sidebar: false, created_at: '2024-01-01T00:00:00Z', updated_at: '2024-01-01T00:00:00Z' },
|
||||
{ id: 's2', title: 'Second Chat', folder_id: 'f1', agent_id: null, is_sidebar: false, created_at: '2024-01-01T00:00:00Z', updated_at: '2024-01-01T00:00:00Z' },
|
||||
@@ -46,21 +57,21 @@ beforeEach(() => {
|
||||
|
||||
describe('SessionList', () => {
|
||||
it('renders session list with sessions', async () => {
|
||||
render(<SessionList activeSessionId="s1" onSelectSession={vi.fn()} />);
|
||||
renderWithProvider(<SessionList activeSessionId="s1" onSelectSession={vi.fn()} />);
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('First Chat')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it('renders folder names', async () => {
|
||||
render(<SessionList activeSessionId="s1" onSelectSession={vi.fn()} />);
|
||||
renderWithProvider(<SessionList activeSessionId="s1" onSelectSession={vi.fn()} />);
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('My Folder')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it('renders sessions inside folders', async () => {
|
||||
render(<SessionList activeSessionId="s1" onSelectSession={vi.fn()} />);
|
||||
renderWithProvider(<SessionList activeSessionId="s1" onSelectSession={vi.fn()} />);
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Second Chat')).toBeInTheDocument();
|
||||
});
|
||||
@@ -68,7 +79,7 @@ describe('SessionList', () => {
|
||||
|
||||
it('calls onSelectSession when session clicked', async () => {
|
||||
const onSelect = vi.fn();
|
||||
render(<SessionList activeSessionId={null} onSelectSession={onSelect} />);
|
||||
renderWithProvider(<SessionList activeSessionId={null} onSelectSession={onSelect} />);
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('First Chat')).toBeInTheDocument();
|
||||
});
|
||||
@@ -79,13 +90,13 @@ describe('SessionList', () => {
|
||||
it('shows loading state initially', () => {
|
||||
fetchSessionsMock.mockReturnValue(new Promise(() => {}));
|
||||
fetchFoldersMock.mockReturnValue(new Promise(() => {}));
|
||||
render(<SessionList activeSessionId={null} onSelectSession={vi.fn()} />);
|
||||
renderWithProvider(<SessionList activeSessionId={null} onSelectSession={vi.fn()} />);
|
||||
expect(screen.getByText('Laden...')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('displays error when fetch fails', async () => {
|
||||
fetchSessionsMock.mockRejectedValueOnce(new Error('Failed to load'));
|
||||
render(<SessionList activeSessionId={null} onSelectSession={vi.fn()} />);
|
||||
renderWithProvider(<SessionList activeSessionId={null} onSelectSession={vi.fn()} />);
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Failed to load')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user