Tickets: ticketPath, Listenzustand in der URL (Reiter, Art, Dringend, Suche, limit), woid-Umleitung, Zeilenklick-Helfer
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f3b73ca1dd
commit
54fc44ed11
7 files changed
+249
-1
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { loadModule } from './load.mjs'
|
||||
|
||||
const { isRowActivation } = await loadModule('src/lib/rowClick.js')
|
||||
|
||||
const TAGS = ['a', 'button', 'select', 'input', 'textarea', 'label']
|
||||
|
||||
// Ereignis ohne DOM: closest liefert nur dann einen Treffer, wenn der Selektor das Tag nennt
|
||||
function click({ target = 'td', outside = false, ...over } = {}) {
|
||||
const row = { contains: (el) => el?.inRow === true }
|
||||
const hit = TAGS.includes(target) ? { inRow: !outside } : null
|
||||
return {
|
||||
target: { closest: (sel) => (hit && sel.split(',').map((s) => s.trim()).includes(target) ? hit : null) },
|
||||
currentTarget: row, button: 0, defaultPrevented: false, metaKey: false, ctrlKey: false, shiftKey: false, altKey: false, ...over,
|
||||
}
|
||||
}
|
||||
|
||||
test('Linksklick auf Zelle oder Zeile aktiviert die Zeile', () => {
|
||||
assert.equal(isRowActivation(click()), true)
|
||||
assert.equal(isRowActivation(click({ target: 'tr' })), true)
|
||||
})
|
||||
|
||||
test('Klick auf a, button, select, input, textarea oder label aktiviert nicht', () => {
|
||||
for (const tag of TAGS) assert.equal(isRowActivation(click({ target: tag })), false, tag)
|
||||
})
|
||||
|
||||
test('Mittelklick, Modifikatortasten und behandelte Klicks aktivieren nicht', () => {
|
||||
assert.equal(isRowActivation(click({ button: 1 })), false)
|
||||
for (const key of ['metaKey', 'ctrlKey', 'shiftKey', 'altKey']) assert.equal(isRowActivation(click({ [key]: true })), false, key)
|
||||
assert.equal(isRowActivation(click({ defaultPrevented: true })), false)
|
||||
})
|
||||
|
||||
test('ein interaktiver Vorfahre außerhalb der Zeile zählt nicht', () => {
|
||||
assert.equal(isRowActivation(click({ target: 'label', outside: true })), true)
|
||||
})
|
||||
@@ -0,0 +1,47 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { loadModule } from './load.mjs'
|
||||
|
||||
const m = await loadModule('src/lib/ticketListUrl.js')
|
||||
const { LIST_TABS, LIST_DEFAULTS, parseListParams: parse, serializeListParams: ser, withFilter, nextLimit, listFilters, countFilters, woidRedirectTarget } = m
|
||||
const { TYPE_FILTERS } = await loadModule('src/lib/ticketStatus.js')
|
||||
|
||||
test('Reiter und Art-Auswahl nach Spec', () => {
|
||||
assert.deepEqual(LIST_TABS.map((t) => [t.id, t.label]), [['aktiv', 'Aktiv'], ['open', 'Offen'], ['working', 'In Arbeit'], ['waiting', 'Wartet auf Kunde'], ['review', 'Prüfung'], ['done', 'Erledigt'], ['cancelled', 'Storniert'], ['alle', 'Alle']])
|
||||
assert.deepEqual(TYPE_FILTERS.map((f) => f.label), ['Aufträge', 'Webpage', 'Migration', 'Projekt', 'Akquise', 'Aufträge und Akquise'])
|
||||
})
|
||||
|
||||
test('parse: Standard, gültige und ungültige Werte', () => {
|
||||
assert.deepEqual(parse(''), LIST_DEFAULTS)
|
||||
assert.deepEqual(parse('?status=done&art=all&dringend=1&q=%20Müller%20&limit=30'), { tab: 'done', typeId: 'all', urgentOnly: true, search: 'Müller', limit: 30 })
|
||||
assert.deepEqual(parse('status=foo&art=bar&dringend=ja&limit=abc'), LIST_DEFAULTS)
|
||||
for (const [raw, want] of [['5', 10], ['0', 10], ['25', 25], ['500', 500], ['9999', 500], ['-3', 10], ['1e3', 10], ['', 10]]) assert.equal(parse('limit=' + raw).limit, want, raw)
|
||||
})
|
||||
|
||||
test('serialize: Standardwerte werden nicht geschrieben, Rundlauf', () => {
|
||||
assert.equal(ser(LIST_DEFAULTS).toString(), '')
|
||||
assert.equal(ser({ ...LIST_DEFAULTS, tab: 'alle', limit: 20 }).toString(), 'status=alle&limit=20')
|
||||
assert.equal(ser({ ...LIST_DEFAULTS, urgentOnly: true, search: 'a b' }).toString(), 'dringend=1&q=a+b')
|
||||
for (const s of [LIST_DEFAULTS, { tab: 'done', typeId: 'Akquise', urgentOnly: true, search: 'x y', limit: 40 }]) assert.deepEqual(parse(ser(s)), s)
|
||||
})
|
||||
|
||||
test('Filteränderung setzt limit zurück, Mehr laden +10 bis 500', () => {
|
||||
for (const patch of [{ tab: 'done' }, { typeId: 'all' }, { urgentOnly: true }, { search: 'x' }]) assert.equal(withFilter({ ...LIST_DEFAULTS, limit: 50 }, patch).limit, 10)
|
||||
assert.deepEqual([10, 495, 500].map((limit) => nextLimit({ limit })), [20, 500, 500])
|
||||
})
|
||||
|
||||
test('listFilters und countFilters', () => {
|
||||
assert.deepEqual(listFilters(LIST_DEFAULTS), { status: ['Open', 'Occupied', 'Assigned', 'Added Info', 'In Kontakt', 'Awaiting', 'Halted', 'In Test'], type: [], excludeType: 'Akquise', priority: [], search: undefined, limit: 10 })
|
||||
assert.deepEqual(listFilters({ ...LIST_DEFAULTS, tab: 'alle', typeId: 'Akquise', urgentOnly: true, search: 'abc' }), { status: [], type: ['Akquise'], excludeType: undefined, priority: [3, 4], search: 'abc', limit: 10 })
|
||||
assert.deepEqual(listFilters({ ...LIST_DEFAULTS, tab: 'done' }).status, ['Closed', 'Zugesagt'])
|
||||
const s = { ...LIST_DEFAULTS, typeId: 'Webpage', urgentOnly: true, search: 'zzz', limit: 80 }
|
||||
assert.deepEqual(countFilters(s, 'review'), { status: ['In Test'], type: ['Webpage'], excludeType: undefined, priority: [3, 4] })
|
||||
for (const t of LIST_TABS) assert.deepEqual(countFilters(s, t.id).status, listFilters({ ...s, tab: t.id }).status, t.id)
|
||||
})
|
||||
|
||||
test('woid-Umleitung hat Vorrang', () => {
|
||||
assert.equal(woidRedirectTarget('?woid=100131'), '/tickets/100131')
|
||||
assert.equal(woidRedirectTarget('?woid=%20100131%20&status=done&q=x'), '/tickets/100131')
|
||||
assert.equal(woidRedirectTarget('?woid=a%2Fb'), '/tickets/a%2Fb')
|
||||
for (const none of ['', '?woid=', '?status=done']) assert.equal(woidRedirectTarget(none), null)
|
||||
})
|
||||
@@ -0,0 +1,39 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { loadModule } from './load.mjs'
|
||||
|
||||
const { ticketPath, ticketRef, resolveTicketTab, listBackPath } = await loadModule('src/lib/ticketRoutes.js')
|
||||
|
||||
test('ticketPath: woid, Zahl, $id, Reiter', () => {
|
||||
assert.equal(ticketPath('100131'), '/tickets/100131')
|
||||
assert.equal(ticketPath(100131), '/tickets/100131')
|
||||
assert.equal(ticketPath('100131', 'details'), '/tickets/100131')
|
||||
assert.equal(ticketPath('100131', 'arbeitsblaetter'), '/tickets/100131/arbeitsblaetter')
|
||||
assert.equal(ticketPath('100131', 'unbekannt'), '/tickets/100131')
|
||||
assert.equal(ticketPath('66f1c2a9000b1c2d3e4f'), '/tickets/66f1c2a9000b1c2d3e4f')
|
||||
})
|
||||
|
||||
test('ticketPath: Sonderzeichen kodiert, leeres ref ergibt /tickets', () => {
|
||||
assert.equal(ticketPath('a/b c?d#e'), '/tickets/a%2Fb%20c%3Fd%23e')
|
||||
for (const empty of ['', ' ', null, undefined]) {
|
||||
assert.equal(ticketPath(empty), '/tickets')
|
||||
assert.equal(ticketPath(empty, 'arbeitsblaetter'), '/tickets')
|
||||
}
|
||||
})
|
||||
|
||||
test('ticketRef: woid vor $id, nie die Kurznummer', () => {
|
||||
assert.equal(ticketRef({ woid: '100131', $id: 'abc' }), '100131')
|
||||
assert.equal(ticketRef({ woid: '', $id: 'abcdefghij' }), 'abcdefghij')
|
||||
assert.equal(ticketRef(null), '')
|
||||
})
|
||||
|
||||
test('resolveTicketTab: unbekannt ergibt null', () => {
|
||||
assert.equal(resolveTicketTab(undefined), 'details')
|
||||
assert.equal(resolveTicketTab('arbeitsblaetter'), 'arbeitsblaetter')
|
||||
for (const bad of ['Details', 'worksheets', '', 'x']) assert.equal(resolveTicketTab(bad), null)
|
||||
})
|
||||
|
||||
test('listBackPath: nur Suchteile mit ?', () => {
|
||||
assert.equal(listBackPath({ listSearch: '?status=done&q=x' }), '/tickets?status=done&q=x')
|
||||
for (const bad of [undefined, null, {}, { listSearch: '' }, { listSearch: '?' }, { listSearch: 'evil' }, { listSearch: 42 }]) assert.equal(listBackPath(bad), '/tickets')
|
||||
})
|
||||
Reference in new issue
Block a user