feat(search): add group headers to DocumentList by sort field
Documents sorted by DATE show year dividers, SENDER/RECEIVER sort shows person name dividers. Dividers only appear when there are 2+ distinct groups. Multi-receiver docs appear in each receiver group. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { render } from 'vitest-browser-svelte';
|
||||
import { describe, expect, it, vi, afterEach } from 'vitest';
|
||||
import { cleanup, render } from 'vitest-browser-svelte';
|
||||
import { page } from 'vitest/browser';
|
||||
import DocumentList from './DocumentList.svelte';
|
||||
|
||||
vi.mock('$app/navigation', () => ({ goto: vi.fn() }));
|
||||
|
||||
afterEach(() => cleanup());
|
||||
|
||||
const baseProps = {
|
||||
documents: [],
|
||||
canWrite: false,
|
||||
@@ -13,7 +15,14 @@ const baseProps = {
|
||||
q: ''
|
||||
};
|
||||
|
||||
const makeDoc = () => ({
|
||||
type DocOverrides = {
|
||||
id?: string;
|
||||
documentDate?: string | null;
|
||||
sender?: { firstName?: string | null; lastName: string; displayName: string } | null;
|
||||
receivers?: { firstName?: string | null; lastName: string; displayName: string }[];
|
||||
};
|
||||
|
||||
const makeDoc = (overrides: DocOverrides = {}) => ({
|
||||
id: '1',
|
||||
title: 'Testbrief',
|
||||
originalFilename: 'testbrief.pdf',
|
||||
@@ -21,8 +30,9 @@ const makeDoc = () => ({
|
||||
documentDate: '2024-03-15',
|
||||
location: null,
|
||||
sender: null,
|
||||
receivers: [],
|
||||
tags: []
|
||||
receivers: [] as { firstName?: string | null; lastName: string; displayName: string }[],
|
||||
tags: [],
|
||||
...overrides
|
||||
});
|
||||
|
||||
describe('DocumentList – result count', () => {
|
||||
@@ -49,3 +59,50 @@ describe('DocumentList – empty state with search term', () => {
|
||||
await expect.element(page.getByText(/"Urlaub"/)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Group headers ────────────────────────────────────────────────────────────
|
||||
|
||||
describe('DocumentList – group headers', () => {
|
||||
it('renders group-divider elements when DATE sort spans multiple years', async () => {
|
||||
const documents = [
|
||||
makeDoc({ id: '1', documentDate: '1923-04-12' }),
|
||||
makeDoc({ id: '2', documentDate: '1965-08-03' })
|
||||
];
|
||||
render(DocumentList, { ...baseProps, documents, total: 2, sort: 'DATE' });
|
||||
await expect.element(page.getByTestId('group-divider').first()).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not render group-divider when DATE sort has only one distinct year', async () => {
|
||||
const documents = [
|
||||
makeDoc({ id: '1', documentDate: '1938-01-01' }),
|
||||
makeDoc({ id: '2', documentDate: '1938-06-15' })
|
||||
];
|
||||
render(DocumentList, { ...baseProps, documents, total: 2, sort: 'DATE' });
|
||||
await expect.element(page.getByTestId('group-divider')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not render group-divider for TITLE sort', async () => {
|
||||
const documents = [
|
||||
makeDoc({ id: '1', documentDate: '1923-04-12' }),
|
||||
makeDoc({ id: '2', documentDate: '1965-08-03' })
|
||||
];
|
||||
render(DocumentList, { ...baseProps, documents, total: 2, sort: 'TITLE' });
|
||||
await expect.element(page.getByTestId('group-divider')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('a doc with two receivers appears in both receiver groups', async () => {
|
||||
const documents = [
|
||||
makeDoc({
|
||||
id: '1',
|
||||
receivers: [
|
||||
{ firstName: null, lastName: 'Müller', displayName: 'Anna Müller' },
|
||||
{ firstName: null, lastName: 'Bauer', displayName: 'Karl Bauer' }
|
||||
]
|
||||
})
|
||||
];
|
||||
render(DocumentList, { ...baseProps, documents, total: 1, sort: 'RECEIVER' });
|
||||
const links = page.getByRole('link', { name: /Testbrief/ });
|
||||
await expect.element(links.first()).toBeInTheDocument();
|
||||
await expect.element(links.nth(1)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user