import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest'; import { render, screen, waitFor, cleanup } from '@testing-library/svelte'; vi.mock('../lib/client', () => { const real = vi.importActual('../lib/client'); return { ...real, listProjects: vi.fn() }; }); import ProjectsPage from '../pages/ProjectsPage.svelte'; import { listProjects } from '../lib/client'; import type { Project } from '../lib/types'; function project(i: number): Project { return { id: `p${i}`, name: `项目${i}`, description: null, draft_code: '', draft_generation: 0, created_at: '2026-09-17T01:00:00Z', updated_at: '2026-09-17T01:00:00Z' }; } beforeEach(() => { vi.mocked(listProjects).mockReset(); }); afterEach(() => cleanup()); describe('projects page loads the list (159399 QA regression: load() existed but was wired nowhere, UI always showed 还没有项目)', () => { it('listProjects is called on mount and existing rows render', async () => { vi.mocked(listProjects).mockResolvedValue({ items: [project(1), project(2)] }); render(ProjectsPage); await waitFor(() => expect(listProjects).toHaveBeenCalled()); await screen.findByText('项目1'); await screen.findByText('项目2'); expect(screen.queryByText('还没有项目')).toBeNull(); }); it('load failure is surfaced as a visible error, not an empty "no projects" state', async () => { vi.mocked(listProjects).mockRejectedValue(new Error('HTTP500: server unavailable')); render(ProjectsPage); await screen.findByText(/server unavailable/); }); });