feat(frontend): simplify homepage to pure dashboard — remove search/filter dual-mode

The homepage now always renders the dashboard. Search and browse
moves to the dedicated /documents route (upcoming).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-04-19 23:31:57 +02:00
parent eeca30e7a6
commit 6e888d9958
4 changed files with 132 additions and 652 deletions

View File

@@ -19,10 +19,42 @@ function makeUrl(params: Record<string, string | string[]> = {}) {
return url;
}
// ─── dashboard mode (no search filters) ──────────────────────────────────────
// ─── always-dashboard behaviour ───────────────────────────────────────────────
describe('home page load — dashboard mode', () => {
it('sets isDashboard true and fetches stats, resume, pulse, and activity APIs', async () => {
it('never calls /api/documents/search regardless of URL params', async () => {
const mockGet = vi.fn().mockResolvedValue({ response: { ok: true, status: 200 }, data: null });
vi.mocked(createApiClient).mockReturnValue({ GET: mockGet } as ReturnType<
typeof createApiClient
>);
await load({
url: makeUrl({ q: 'Urlaub', from: '2020-01-01' }),
fetch: vi.fn() as unknown as typeof fetch
});
const calledEndpoints = mockGet.mock.calls.map((c: unknown[]) => c[0]);
expect(calledEndpoints).not.toContain('/api/documents/search');
});
it('always fetches dashboard data regardless of URL params', async () => {
const mockGet = vi.fn().mockResolvedValue({ response: { ok: true, status: 200 }, data: null });
vi.mocked(createApiClient).mockReturnValue({ GET: mockGet } as ReturnType<
typeof createApiClient
>);
await load({ url: makeUrl({ q: 'Urlaub' }), fetch: vi.fn() as unknown as typeof fetch });
const calledEndpoints = mockGet.mock.calls.map((c: unknown[]) => c[0]);
expect(calledEndpoints).toContain('/api/stats');
expect(calledEndpoints).toContain('/api/dashboard/resume');
expect(calledEndpoints).toContain('/api/dashboard/pulse');
expect(calledEndpoints).toContain('/api/dashboard/activity');
});
// ─── dashboard mode ────────────────────────────────────────────────────────────
describe('home page load — dashboard', () => {
it('fetches stats, resume, pulse, and activity APIs', async () => {
const mockGet = vi
.fn()
.mockResolvedValueOnce({ response: { ok: true, status: 200 }, data: [] }) // persons
@@ -67,13 +99,11 @@ describe('home page load — dashboard mode', () => {
const result = await load({ url: makeUrl(), fetch: vi.fn() as unknown as typeof fetch });
expect(result.isDashboard).toBe(true);
expect(result.stats).toEqual({ totalDocuments: 42, totalPersons: 7 });
expect(result.resumeDoc).not.toBeNull();
expect(result.resumeDoc?.totalBlocks).toBe(2);
expect(result.pulse).not.toBeNull();
expect(result.activityFeed).toEqual([]);
expect(result.documents).toEqual([]);
});
it('returns stats with totalDocuments from /api/stats', async () => {
@@ -109,8 +139,8 @@ describe('home page load — dashboard mode', () => {
.fn()
.mockResolvedValueOnce({ response: { ok: true, status: 200 }, data: [] }) // persons
.mockRejectedValueOnce(new Error('network')) // stats
.mockResolvedValueOnce({ response: { ok: true }, data: [] }) // incomplete
.mockResolvedValueOnce({ response: { ok: true }, data: [] }); // recent
.mockResolvedValueOnce({ response: { ok: true }, data: [] }) // resume
.mockResolvedValueOnce({ response: { ok: true }, data: [] }); // pulse
vi.mocked(createApiClient).mockReturnValue({ GET: mockGet } as ReturnType<
typeof createApiClient
>);
@@ -158,123 +188,6 @@ describe('home page load — dashboard mode', () => {
});
});
// ─── search mode (any filter active) ─────────────────────────────────────────
describe('home page load — search mode', () => {
it('sets isDashboard false and skips widget APIs when q is set', async () => {
const mockGet = vi
.fn()
.mockResolvedValueOnce({
response: { ok: true, status: 200 },
data: { documents: [{ id: 'd1' }], total: 1 }
}) // search docs
.mockResolvedValueOnce({ response: { ok: true, status: 200 }, data: [] }); // persons
vi.mocked(createApiClient).mockReturnValue({ GET: mockGet } as ReturnType<
typeof createApiClient
>);
const result = await load({
url: makeUrl({ q: 'Urlaub' }),
fetch: vi.fn() as unknown as typeof fetch
});
expect(result.isDashboard).toBe(false);
expect(result.documents).toHaveLength(1);
expect(result.stats).toBeNull();
expect(result.resumeDoc).toBeNull();
expect(result.activityFeed).toEqual([]);
// Only two API calls — no widget calls
expect(mockGet).toHaveBeenCalledTimes(2);
});
it('passes search params from the URL to the documents API', async () => {
const mockGet = vi
.fn()
.mockResolvedValueOnce({
response: { ok: true, status: 200 },
data: { documents: [], total: 0 }
})
.mockResolvedValueOnce({ response: { ok: true, status: 200 }, data: [] });
vi.mocked(createApiClient).mockReturnValue({ GET: mockGet } as ReturnType<
typeof createApiClient
>);
await load({
url: makeUrl({ q: 'Urlaub', from: '2020-01-01' }),
fetch: vi.fn() as unknown as typeof fetch
});
const firstCall = mockGet.mock.calls[0];
expect(firstCall[1].params.query.q).toBe('Urlaub');
expect(firstCall[1].params.query.from).toBe('2020-01-01');
});
it('sets isDashboard false when only tagQ is set', async () => {
const mockGet = vi
.fn()
.mockResolvedValueOnce({
response: { ok: true, status: 200 },
data: { documents: [{ id: 'd1' }], total: 1 }
}) // search docs
.mockResolvedValueOnce({ response: { ok: true, status: 200 }, data: [] }); // persons
vi.mocked(createApiClient).mockReturnValue({ GET: mockGet } as ReturnType<
typeof createApiClient
>);
const result = await load({
url: makeUrl({ tagQ: 'fam' }),
fetch: vi.fn() as unknown as typeof fetch
});
expect(result.isDashboard).toBe(false);
expect(result.documents).toHaveLength(1);
});
});
it('passes sort, dir, and tagQ params to the documents API', async () => {
const mockGet = vi
.fn()
.mockResolvedValueOnce({
response: { ok: true, status: 200 },
data: { documents: [], total: 0 }
})
.mockResolvedValueOnce({ response: { ok: true, status: 200 }, data: [] });
vi.mocked(createApiClient).mockReturnValue({ GET: mockGet } as ReturnType<
typeof createApiClient
>);
await load({
url: makeUrl({ q: 'test', sort: 'TITLE', dir: 'asc', tagQ: 'fam' }),
fetch: vi.fn() as unknown as typeof fetch
});
const firstCall = mockGet.mock.calls[0];
expect(firstCall[1].params.query.sort).toBe('TITLE');
expect(firstCall[1].params.query.dir).toBe('asc');
expect(firstCall[1].params.query.tagQ).toBe('fam');
});
it('returns total from the DocumentSearchResult envelope', async () => {
const mockGet = vi
.fn()
.mockResolvedValueOnce({
response: { ok: true, status: 200 },
data: { documents: [{ id: 'd1' }], total: 42 }
})
.mockResolvedValueOnce({ response: { ok: true, status: 200 }, data: [] });
vi.mocked(createApiClient).mockReturnValue({ GET: mockGet } as ReturnType<
typeof createApiClient
>);
const result = await load({
url: makeUrl({ q: 'test' }),
fetch: vi.fn() as unknown as typeof fetch
});
expect(result.documents).toHaveLength(1);
expect(result.total).toBe(42);
});
// ─── 401 redirect ─────────────────────────────────────────────────────────────
describe('home page load — auth redirect', () => {
@@ -300,6 +213,5 @@ describe('home page load — network error fallback', () => {
const result = await load({ url: makeUrl(), fetch: vi.fn() as unknown as typeof fetch });
expect(result.error).toBe('Daten konnten nicht geladen werden.');
expect(result.documents).toEqual([]);
});
});