test+fix(docs): correct fallbackLabel when sort prop is omitted

Add failing test for DATE-sort + undated doc showing "Undatiert" fallback
label, then fix DocumentList by null-coalescing sort before comparison
((sort ?? 'DATE') === 'DATE'). Test uses one dated + one undated doc to
produce two groups and trigger GroupDivider rendering.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-04-15 09:37:19 +02:00
parent 67c03dab8c
commit 593a6c8a38
2 changed files with 12 additions and 1 deletions

View File

@@ -30,7 +30,9 @@ let {
sort?: string; sort?: string;
} = $props(); } = $props();
const fallbackLabel = $derived(sort === 'DATE' ? m.docs_group_undated() : m.docs_group_unknown()); const fallbackLabel = $derived(
(sort ?? 'DATE') === 'DATE' ? m.docs_group_undated() : m.docs_group_unknown()
);
const groupedDocuments = $derived.by(() => const groupedDocuments = $derived.by(() =>
groupDocuments(documents, sort ?? 'DATE', fallbackLabel) groupDocuments(documents, sort ?? 'DATE', fallbackLabel)
); );

View File

@@ -90,6 +90,15 @@ describe('DocumentList group headers', () => {
await expect.element(page.getByTestId('group-divider')).not.toBeInTheDocument(); await expect.element(page.getByTestId('group-divider')).not.toBeInTheDocument();
}); });
it('shows Undatiert fallback label when sort is undefined and doc has no date', async () => {
const documents = [
makeDoc({ id: '1', documentDate: '1938-01-01' }),
makeDoc({ id: '2', documentDate: null })
];
render(DocumentList, { ...baseProps, documents, total: 2 }); // sort omitted — defaults to DATE grouping
await expect.element(page.getByText(/UNDATIERT/i)).toBeInTheDocument();
});
it('a doc with two receivers appears in both receiver groups', async () => { it('a doc with two receivers appears in both receiver groups', async () => {
const documents = [ const documents = [
makeDoc({ makeDoc({