97 lines
4.7 KiB
JavaScript
97 lines
4.7 KiB
JavaScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { loadModule } from './load.mjs'
|
|
|
|
const { projectCounts, projectsInView, projectTabs, viewShowing, matchesSearch, hiddenMatches } = await loadModule('src/lib/projectList.js')
|
|
|
|
const P = [
|
|
{ $id: 'a' },
|
|
{ $id: 'b', customerId: 'k' },
|
|
{ $id: 'c', archived: true },
|
|
{ $id: 'd', isTemplate: true },
|
|
{ $id: 'e', isTemplate: true, archived: true },
|
|
]
|
|
const ids = (list) => list.map((p) => p.$id)
|
|
|
|
test('Aktive Projekte ohne Archiv und Vorlagen', () => {
|
|
assert.deepEqual(ids(projectsInView(P, 'all')), ['a', 'b'])
|
|
assert.deepEqual(ids(projectsInView(P, 'unassigned')), ['a'])
|
|
assert.deepEqual(ids(projectsInView(P, 'assigned')), ['b'])
|
|
})
|
|
|
|
test('Alle inkl. Archiv: wirklich alles (Vorlagen nur fuer Admins)', () => {
|
|
assert.deepEqual(ids(projectsInView(P, 'everything')), ['a', 'b', 'c'])
|
|
assert.deepEqual(ids(projectsInView(P, 'everything', { isAdmin: true })), ['a', 'b', 'c', 'd', 'e'])
|
|
})
|
|
|
|
test('Archiviert und Vorlagen', () => {
|
|
assert.deepEqual(ids(projectsInView(P, 'archived')), ['c'])
|
|
assert.deepEqual(ids(projectsInView(P, 'archived', { isAdmin: true })), ['c', 'e'])
|
|
assert.deepEqual(ids(projectsInView(P, 'templates')), ['d'])
|
|
})
|
|
|
|
test('Zaehler passen zu den Ansichten', () => {
|
|
assert.deepEqual(projectCounts(P), { all: 2, unassigned: 1, assigned: 1, archived: 1, templates: 1, everything: 3 })
|
|
assert.deepEqual(projectCounts(P, { isAdmin: true }).everything, 5)
|
|
})
|
|
|
|
// 04.10.2026: SHK-vorlage zur Vorlage gemacht -> verschwand kommentarlos aus "Aktive Projekte"
|
|
test('viewShowing: bleibt in der aktuellen Ansicht, wenn das Projekt dort steht', () => {
|
|
assert.equal(viewShowing(P[0], 'all', { isAdmin: true }), 'all')
|
|
assert.equal(viewShowing(P[1], 'assigned'), 'assigned')
|
|
assert.equal(viewShowing(P[3], 'everything', { isAdmin: true }), 'everything')
|
|
})
|
|
|
|
test('viewShowing: zur Vorlage gemacht -> Vorlagen, zurueck -> Aktive Projekte', () => {
|
|
assert.equal(viewShowing({ $id: 'x', isTemplate: true }, 'all', { isAdmin: true }), 'templates')
|
|
assert.equal(viewShowing({ $id: 'x', isTemplate: true }, 'unassigned', { isAdmin: true }), 'templates')
|
|
assert.equal(viewShowing({ $id: 'x' }, 'templates', { isAdmin: true }), 'all')
|
|
assert.equal(viewShowing({ $id: 'x', archived: true }, 'all'), 'archived')
|
|
})
|
|
|
|
test('viewShowing: ohne Admin keine Vorlagen-Ansicht, dann bleibt die Ansicht', () => {
|
|
assert.equal(viewShowing({ $id: 'x', isTemplate: true }, 'all'), 'all')
|
|
assert.equal(viewShowing(null, 'assigned'), 'assigned')
|
|
})
|
|
|
|
test('matchesSearch: Titel, Subdomain, Repo; leer passt immer', () => {
|
|
const p = { projectName: 'SHK-vorlage', subdomain: 'shk-vorlage', repoFullName: 'knso/SHK-vorlage', giteaRepoName: 'SHK-vorlage' }
|
|
assert.equal(matchesSearch(p, ''), true)
|
|
assert.equal(matchesSearch(p, ' shk '), true)
|
|
assert.equal(matchesSearch(p, 'knso/'), true)
|
|
assert.equal(matchesSearch(p, 'olzinger'), false)
|
|
})
|
|
|
|
test('hiddenMatches: Treffer, die die aktuelle Ansicht ausblendet', () => {
|
|
const list = [
|
|
{ $id: 'a', projectName: 'SHK Kunde' },
|
|
{ $id: 't', projectName: 'SHK-vorlage', isTemplate: true },
|
|
{ $id: 'r', projectName: 'SHK alt', archived: true },
|
|
{ $id: 'o', projectName: 'Olzinger' },
|
|
]
|
|
const shk = (p) => matchesSearch(p, 'shk')
|
|
assert.deepEqual(hiddenMatches(list, 'all', shk, { isAdmin: true }), [{ view: 'templates', count: 1 }, { view: 'archived', count: 1 }])
|
|
assert.deepEqual(hiddenMatches(list, 'all', shk), [{ view: 'archived', count: 1 }], 'Vorlagen nur fuer Admins')
|
|
assert.deepEqual(hiddenMatches(list, 'templates', shk, { isAdmin: true }), [{ view: 'archived', count: 1 }])
|
|
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)
|
|
}
|
|
})
|