Projekte: Reiter-Liste der sechs Ansichten als getestete Funktion

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Sonnet 5.5 committed 2026-10-06 14:34:20 +00:00
1 parent d2d4ad9cfb
commit 5647412e34
2 files changed
+35 -1

No files matched your search

+16
View File
@@ -29,6 +29,22 @@ export function projectsInView(projects, filter, { isAdmin = false } = {}) {
export const VIEW_LABELS = { all: 'Aktive Projekte', templates: 'Vorlagen', archived: 'Archiviert', everything: 'Alle inkl. Archiv' }
/**
* Reiter der Projektliste (Reihenfolge wie die bisherige Filter-Auswahl), je mit Zaehler aus
* `projectCounts`. Die IDs sind die Filterwerte der Seite; die Vorlagen-Ansicht gibt es nur fuer Admins.
*/
export function projectTabs(counts, { isAdmin = false } = {}) {
const tab = (id, label) => ({ id, label, count: counts?.[id] ?? 0 })
return [
tab('all', VIEW_LABELS.all),
tab('unassigned', 'Unzugeordnet'),
tab('assigned', 'Zugeordnet'),
...(isAdmin ? [tab('templates', VIEW_LABELS.templates)] : []),
tab('archived', VIEW_LABELS.archived),
tab('everything', VIEW_LABELS.everything),
]
}
// Ansichten, die ein Projekt zeigen koennen - die Vorlagen-Ansicht gibt es nur fuer Admins
const viewsFor = (isAdmin) => ['all', ...(isAdmin ? ['templates'] : []), 'archived', 'everything']
+19 -1
View File
@@ -2,7 +2,7 @@ import test from 'node:test'
import assert from 'node:assert/strict'
import { loadModule } from './load.mjs'
const { projectCounts, projectsInView, viewShowing, matchesSearch, hiddenMatches } = await loadModule('src/lib/projectList.js')
const { projectCounts, projectsInView, projectTabs, viewShowing, matchesSearch, hiddenMatches } = await loadModule('src/lib/projectList.js')
const P = [
{ $id: 'a' },
@@ -76,3 +76,21 @@ test('hiddenMatches: Treffer, die die aktuelle Ansicht ausblendet', () => {
assert.deepEqual(hiddenMatches(list, 'everything', shk, { isAdmin: true }), [], 'zeigt schon alles')
assert.deepEqual(hiddenMatches(list, 'all', (p) => matchesSearch(p, 'olz'), { isAdmin: true }), [])
})
const counts = { all: 5, unassigned: 2, assigned: 3, archived: 4, templates: 1, everything: 10 }
test('projectTabs: sechs Reiter für Admins, Wortlaut und Zähler', () => {
assert.deepEqual(projectTabs(counts, { isAdmin: true }), [
{ id: 'all', label: 'Aktive Projekte', count: 5 },
{ id: 'unassigned', label: 'Unzugeordnet', count: 2 },
{ id: 'assigned', label: 'Zugeordnet', count: 3 },
{ id: 'templates', label: 'Vorlagen', count: 1 },
{ id: 'archived', label: 'Archiviert', count: 4 },
{ id: 'everything', label: 'Alle inkl. Archiv', count: 10 },
])
})
test('projectTabs: ohne Admin keine Vorlagen, Zähler passen zur Ansicht', () => {
assert.deepEqual(projectTabs(counts).map((t) => t.id), ['all', 'unassigned', 'assigned', 'archived', 'everything'])
for (const t of projectTabs(projectCounts(P, { isAdmin: true }), { isAdmin: true })) {
assert.equal(t.count, projectsInView(P, t.id, { isAdmin: true }).length)
}
})