Merge remote-tracking branch 'origin/main' into HEAD
Some checks failed
CI / Unit & Component Tests (pull_request) Successful in 3m30s
CI / OCR Service Tests (pull_request) Successful in 23s
CI / Backend Unit Tests (pull_request) Successful in 3m46s
CI / fail2ban Regex (pull_request) Failing after 46s
CI / Semgrep Security Scan (pull_request) Successful in 21s
CI / Compose Bucket Idempotency (pull_request) Successful in 1m5s
Some checks failed
CI / Unit & Component Tests (pull_request) Successful in 3m30s
CI / OCR Service Tests (pull_request) Successful in 23s
CI / Backend Unit Tests (pull_request) Successful in 3m46s
CI / fail2ban Regex (pull_request) Failing after 46s
CI / Semgrep Security Scan (pull_request) Successful in 21s
CI / Compose Bucket Idempotency (pull_request) Successful in 1m5s
# Conflicts: # frontend/src/lib/shared/dashboard/ReaderRecentDocs.svelte.spec.ts # frontend/src/routes/+page.server.ts
This commit is contained in:
@@ -3,16 +3,16 @@ import * as m from '$lib/paraglide/messages.js';
|
||||
import { relativeTimeDe } from '$lib/shared/relativeTime';
|
||||
import type { components } from '$lib/generated/api';
|
||||
|
||||
type Document = components['schemas']['Document'];
|
||||
type DocumentListItem = components['schemas']['DocumentListItem'];
|
||||
|
||||
interface Props {
|
||||
documents: Document[];
|
||||
documents: DocumentListItem[];
|
||||
}
|
||||
|
||||
const { documents }: Props = $props();
|
||||
|
||||
function isNew(doc: Document): boolean {
|
||||
return new Date(doc.createdAt).getTime() === new Date(doc.updatedAt).getTime();
|
||||
function isNew(doc: DocumentListItem): boolean {
|
||||
return new Date(doc.createdAt).getTime() > Date.now() - 7 * 24 * 60 * 60 * 1000;
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -5,25 +5,34 @@ import { page } from 'vitest/browser';
|
||||
import ReaderRecentDocs from './ReaderRecentDocs.svelte';
|
||||
import type { components } from '$lib/generated/api';
|
||||
|
||||
type Document = components['schemas']['Document'];
|
||||
type DocumentListItem = components['schemas']['DocumentListItem'];
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
const baseDoc: Document = {
|
||||
const baseDoc: DocumentListItem = {
|
||||
id: 'doc1',
|
||||
title: 'Brief an Hans',
|
||||
originalFilename: 'brief.pdf',
|
||||
status: 'UPLOADED',
|
||||
metaDatePrecision: 'UNKNOWN',
|
||||
metadataComplete: true,
|
||||
scriptType: 'HANDWRITING_KURRENT',
|
||||
completionPercentage: 0,
|
||||
receivers: [],
|
||||
tags: [],
|
||||
contributors: [],
|
||||
matchData: {
|
||||
titleOffsets: [],
|
||||
senderMatched: false,
|
||||
matchedReceiverIds: [],
|
||||
matchedTagIds: [],
|
||||
snippetOffsets: [],
|
||||
summaryOffsets: []
|
||||
},
|
||||
createdAt: '2025-01-01T12:00:00Z',
|
||||
updatedAt: '2025-01-01T12:00:00Z'
|
||||
};
|
||||
|
||||
const updatedDoc: Document = {
|
||||
const updatedDoc: DocumentListItem = {
|
||||
...baseDoc,
|
||||
id: 'doc2',
|
||||
title: 'Urkunde 1920',
|
||||
@@ -89,8 +98,14 @@ describe('ReaderRecentDocs', () => {
|
||||
expect(thumb!.className).toMatch(/rounded-/);
|
||||
});
|
||||
|
||||
it('shows "Neu" accent-pill badge when createdAt equals updatedAt', async () => {
|
||||
render(ReaderRecentDocs, { documents: [baseDoc] });
|
||||
it('shows "Neu" accent-pill badge when document was created within the last 7 days', async () => {
|
||||
const recentDoc: DocumentListItem = {
|
||||
...baseDoc,
|
||||
id: 'doc-recent',
|
||||
createdAt: new Date(Date.now() - 2 * 24 * 60 * 60 * 1000).toISOString(),
|
||||
updatedAt: new Date(Date.now() - 1 * 24 * 60 * 60 * 1000).toISOString()
|
||||
};
|
||||
render(ReaderRecentDocs, { documents: [recentDoc] });
|
||||
const badge = page.getByText(/^Neu$/i);
|
||||
await expect.element(badge).toBeInTheDocument();
|
||||
const cls = ((await badge.element()) as HTMLElement).className;
|
||||
@@ -99,7 +114,7 @@ describe('ReaderRecentDocs', () => {
|
||||
expect(cls).toMatch(/\btext-ink\b/);
|
||||
});
|
||||
|
||||
it('shows no badge when updatedAt differs from createdAt', async () => {
|
||||
it('shows no badge when document was created more than 7 days ago', async () => {
|
||||
render(ReaderRecentDocs, { documents: [updatedDoc] });
|
||||
const badge = page.getByText(/^Neu$/i);
|
||||
await expect.element(badge).not.toBeInTheDocument();
|
||||
@@ -107,20 +122,20 @@ describe('ReaderRecentDocs', () => {
|
||||
await expect.element(updatedBadge).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows "Neu" badge when createdAt and updatedAt represent the same instant in different ISO formats', async () => {
|
||||
const sameInstantDoc: Document = {
|
||||
it('shows "Neu" badge when document was created 6 days ago', async () => {
|
||||
const almostOldDoc: DocumentListItem = {
|
||||
...baseDoc,
|
||||
id: 'doc-same-instant',
|
||||
createdAt: '2025-01-01T12:00:00Z',
|
||||
updatedAt: '2025-01-01T12:00:00.000Z'
|
||||
id: 'doc-almost-old',
|
||||
createdAt: new Date(Date.now() - 6 * 24 * 60 * 60 * 1000).toISOString(),
|
||||
updatedAt: new Date(Date.now() - 5 * 24 * 60 * 60 * 1000).toISOString()
|
||||
};
|
||||
render(ReaderRecentDocs, { documents: [sameInstantDoc] });
|
||||
render(ReaderRecentDocs, { documents: [almostOldDoc] });
|
||||
const badge = page.getByText(/^Neu$/i);
|
||||
await expect.element(badge).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders sender name text when sender is present', async () => {
|
||||
const docWithSender: Document = {
|
||||
const docWithSender: DocumentListItem = {
|
||||
...baseDoc,
|
||||
sender: {
|
||||
id: 'p1',
|
||||
|
||||
@@ -31,25 +31,25 @@ describe('ReaderRecentDocs', () => {
|
||||
.toHaveAttribute('href', '/documents');
|
||||
});
|
||||
|
||||
it('renders the New badge when createdAt equals updatedAt', async () => {
|
||||
it('renders the New badge when document was created within the last 7 days', async () => {
|
||||
const recentDate = new Date(Date.now() - 2 * 24 * 60 * 60 * 1000).toISOString();
|
||||
const laterUpdate = new Date(Date.now() - 1 * 24 * 60 * 60 * 1000).toISOString();
|
||||
render(ReaderRecentDocs, {
|
||||
props: {
|
||||
documents: [
|
||||
makeDoc({ createdAt: '2026-04-15T10:00:00Z', updatedAt: '2026-04-15T10:00:00Z' })
|
||||
]
|
||||
documents: [makeDoc({ createdAt: recentDate, updatedAt: laterUpdate })]
|
||||
}
|
||||
});
|
||||
|
||||
await expect.element(page.getByText('Neu')).toBeVisible();
|
||||
});
|
||||
|
||||
it('hides the New badge when document was updated after creation', async () => {
|
||||
it('hides the New badge when document was created more than 7 days ago', async () => {
|
||||
render(ReaderRecentDocs, {
|
||||
props: {
|
||||
documents: [
|
||||
makeDoc({
|
||||
createdAt: '2026-04-15T10:00:00Z',
|
||||
updatedAt: '2026-04-15T11:00:00Z'
|
||||
updatedAt: '2026-04-15T10:00:00Z'
|
||||
})
|
||||
]
|
||||
}
|
||||
|
||||
67
frontend/src/lib/shared/dashboard/ThemenWidget.svelte
Normal file
67
frontend/src/lib/shared/dashboard/ThemenWidget.svelte
Normal file
@@ -0,0 +1,67 @@
|
||||
<script lang="ts">
|
||||
import * as m from '$lib/paraglide/messages.js';
|
||||
import type { components } from '$lib/generated/api';
|
||||
import { hasAnyDocuments } from '$lib/shared/utils/tagUtils';
|
||||
|
||||
type TagTreeNodeDTO = components['schemas']['TagTreeNodeDTO'];
|
||||
|
||||
interface Props {
|
||||
tags: TagTreeNodeDTO[];
|
||||
compact?: boolean;
|
||||
}
|
||||
|
||||
const MAX_VISIBLE_TAGS = 6;
|
||||
|
||||
const { tags, compact = false }: Props = $props();
|
||||
|
||||
const visibleTags = $derived.by(() => tags.filter(hasAnyDocuments));
|
||||
const shownTags = $derived(visibleTags.slice(0, MAX_VISIBLE_TAGS));
|
||||
</script>
|
||||
|
||||
<section class="rounded-sm border border-line bg-surface p-5 shadow-sm">
|
||||
<div class="mb-4 flex items-center justify-between">
|
||||
<h2 class="font-sans text-xs font-bold tracking-widest text-ink-3 uppercase">
|
||||
{m.themen_widget_title()}
|
||||
</h2>
|
||||
<a
|
||||
href="/themen"
|
||||
class="flex min-h-[44px] items-center text-[11px] font-semibold text-ink-2 no-underline focus-visible:ring-2 focus-visible:ring-brand-navy focus-visible:outline-none"
|
||||
>
|
||||
{m.themen_alle()} →
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{#if visibleTags.length === 0}
|
||||
<p class="font-sans text-sm text-ink-3">{m.themen_leer()}</p>
|
||||
{:else}
|
||||
<div
|
||||
class="grid gap-2 {compact ? 'grid-cols-1' : 'grid-cols-1 sm:grid-cols-2'}"
|
||||
data-compact={compact}
|
||||
>
|
||||
{#each shownTags as tag (tag.id)}
|
||||
<a
|
||||
href="/documents?tag={encodeURIComponent(tag.name)}"
|
||||
aria-label="{tag.name}{tag.documentCount > 0
|
||||
? ', ' + m.themen_dokumente({ count: tag.documentCount })
|
||||
: ''}"
|
||||
class="flex cursor-pointer items-stretch overflow-hidden rounded-sm border border-line bg-canvas hover:bg-surface focus-visible:ring-2 focus-visible:ring-brand-navy focus-visible:outline-none"
|
||||
style="min-height: 56px"
|
||||
>
|
||||
<span
|
||||
class="w-1 flex-shrink-0 self-stretch"
|
||||
aria-hidden="true"
|
||||
style="background: var(--c-tag-{tag.color ?? 'slate'})"
|
||||
></span>
|
||||
<span class="flex min-w-0 flex-1 flex-col justify-center gap-0.5 px-3 py-3">
|
||||
<span class="truncate font-serif text-sm font-semibold text-ink">{tag.name}</span>
|
||||
{#if tag.documentCount > 0}
|
||||
<span class="font-sans text-xs text-ink-3 tabular-nums">
|
||||
{m.themen_dokumente({ count: tag.documentCount })}
|
||||
</span>
|
||||
{/if}
|
||||
</span>
|
||||
</a>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</section>
|
||||
@@ -0,0 +1,58 @@
|
||||
import { describe, it, expect, afterEach } from 'vitest';
|
||||
import { cleanup, render } from 'vitest-browser-svelte';
|
||||
import ThemenWidget from './ThemenWidget.svelte';
|
||||
import type { components } from '$lib/generated/api';
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
type TagTreeNodeDTO = components['schemas']['TagTreeNodeDTO'];
|
||||
|
||||
function makeTag(
|
||||
name: string,
|
||||
documentCount: number,
|
||||
children: TagTreeNodeDTO[] = []
|
||||
): TagTreeNodeDTO {
|
||||
return { id: 'id-' + name, name, documentCount, children };
|
||||
}
|
||||
|
||||
describe('ThemenWidget', () => {
|
||||
it('renders a card link per visible tag', async () => {
|
||||
const tags = [makeTag('Briefe', 5), makeTag('Fotos', 3)];
|
||||
const { getByRole } = render(ThemenWidget, { tags });
|
||||
await expect.element(getByRole('link', { name: /Briefe/ })).toBeInTheDocument();
|
||||
await expect.element(getByRole('link', { name: /Fotos/ })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('hides tags where no document exists in the subtree', async () => {
|
||||
const tags = [makeTag('Briefe', 5), makeTag('Leer', 0)];
|
||||
render(ThemenWidget, { tags });
|
||||
expect(document.body.textContent).toContain('Briefe');
|
||||
expect(document.body.textContent).not.toContain('Leer');
|
||||
});
|
||||
|
||||
it('shows the empty state text when all tags are filtered out', async () => {
|
||||
render(ThemenWidget, { tags: [makeTag('Leer', 0)] });
|
||||
expect(document.body.textContent).toMatch(/Noch keine Themen/);
|
||||
});
|
||||
|
||||
it('shows empty state when tags array is empty', async () => {
|
||||
render(ThemenWidget, { tags: [] });
|
||||
expect(document.body.textContent).toMatch(/Noch keine Themen/);
|
||||
});
|
||||
|
||||
it('renders in compact single-column mode when compact prop is true', async () => {
|
||||
const tags = [makeTag('Briefe', 5)];
|
||||
const { container } = render(ThemenWidget, { tags, compact: true });
|
||||
const grid = container.querySelector('[data-compact="true"]');
|
||||
expect(grid).not.toBeNull();
|
||||
});
|
||||
|
||||
it('links to "Alle Themen" page', async () => {
|
||||
const tags = [makeTag('Briefe', 5)];
|
||||
const { getByRole } = render(ThemenWidget, { tags });
|
||||
const link = getByRole('link', { name: /Alle Themen/ });
|
||||
await expect.element(link).toHaveAttribute('href', '/themen');
|
||||
});
|
||||
});
|
||||
@@ -417,19 +417,24 @@ describe('PersonMentionEditor — onExit cancels pending debounce', () => {
|
||||
await new Promise((r) => setTimeout(r, SEARCH_DEBOUNCE_MS + POST_DEBOUNCE_SLACK_MS));
|
||||
const fetchesBeforeEscape = fetchMock.mock.calls.length;
|
||||
|
||||
// Trigger a new debounced search (queues runSearch after 150 ms), then
|
||||
// immediately Escape *while focus is back in the editor* so Tiptap's
|
||||
// suggestion-plugin Escape handler fires onExit before the debounce.
|
||||
// Without onExit cancelling the pending debounce, runSearch executes
|
||||
// against the now-unmounted dropdown's state.
|
||||
await page.getByRole('searchbox').fill('Walter');
|
||||
// Focus the editor so the Escape lands on Tiptap's suggestion handler.
|
||||
(page.getByRole('textbox').element() as HTMLElement).focus();
|
||||
await userEvent.keyboard('{Escape}');
|
||||
|
||||
// Wait past the debounce window. If onExit did not cancel the pending
|
||||
// debounce, a fetch with q=Walter would still fire here.
|
||||
await new Promise((r) => setTimeout(r, SEARCH_DEBOUNCE_MS + POST_DEBOUNCE_SLACK_MS));
|
||||
// Freeze setTimeout so the 150 ms debounce cannot fire before Escape
|
||||
// triggers onExit. We install fake timers only now — after the setup
|
||||
// above — so that vi.waitFor()'s real-timer polling still worked.
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
// fill() dispatches the input event synchronously via CDP; by the
|
||||
// time the await resolves, onSearch('Walter') has run and the fake
|
||||
// debounce timer is set.
|
||||
await page.getByRole('searchbox').fill('Walter');
|
||||
// Focus the editor so the Escape lands on Tiptap's suggestion handler.
|
||||
(page.getByRole('textbox').element() as HTMLElement).focus();
|
||||
await userEvent.keyboard('{Escape}');
|
||||
// onExit has now called debouncedSearch.cancel(). Advance past the
|
||||
// debounce window — the cancelled timer must not fire.
|
||||
await vi.advanceTimersByTimeAsync(SEARCH_DEBOUNCE_MS + POST_DEBOUNCE_SLACK_MS);
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
|
||||
const newFetches = fetchMock.mock.calls.slice(fetchesBeforeEscape);
|
||||
const walterFetches = newFetches.filter(
|
||||
|
||||
29
frontend/src/lib/shared/utils/tagUtils.test.ts
Normal file
29
frontend/src/lib/shared/utils/tagUtils.test.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { hasAnyDocuments } from './tagUtils';
|
||||
import type { components } from '$lib/generated/api';
|
||||
|
||||
type TagTreeNodeDTO = components['schemas']['TagTreeNodeDTO'];
|
||||
|
||||
function makeNode(documentCount: number, children: TagTreeNodeDTO[] = []): TagTreeNodeDTO {
|
||||
return { id: 'id', name: 'name', documentCount, children };
|
||||
}
|
||||
|
||||
describe('hasAnyDocuments', () => {
|
||||
it('returns false for a leaf node with documentCount=0', () => {
|
||||
expect(hasAnyDocuments(makeNode(0))).toBe(false);
|
||||
});
|
||||
|
||||
it('returns true for a leaf node with documentCount=3', () => {
|
||||
expect(hasAnyDocuments(makeNode(3))).toBe(true);
|
||||
});
|
||||
|
||||
it('returns true for a root with documentCount=0 but a child with documentCount=5', () => {
|
||||
const node = makeNode(0, [makeNode(5)]);
|
||||
expect(hasAnyDocuments(node)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false for a root with documentCount=0 and all children also 0', () => {
|
||||
const node = makeNode(0, [makeNode(0), makeNode(0)]);
|
||||
expect(hasAnyDocuments(node)).toBe(false);
|
||||
});
|
||||
});
|
||||
7
frontend/src/lib/shared/utils/tagUtils.ts
Normal file
7
frontend/src/lib/shared/utils/tagUtils.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import type { components } from '$lib/generated/api';
|
||||
|
||||
type TagTreeNodeDTO = components['schemas']['TagTreeNodeDTO'];
|
||||
|
||||
export function hasAnyDocuments(node: TagTreeNodeDTO): boolean {
|
||||
return (node.documentCount ?? 0) > 0 || (node.children ?? []).some(hasAnyDocuments);
|
||||
}
|
||||
Reference in New Issue
Block a user