Files
tickte-system/tests/unit/customerTabs.test.mjs

42 lines
2.1 KiB
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import { loadModule } from './load.mjs'
const { customerTabs, resolveCustomerTab } = await loadModule('src/lib/customerTabs.js')
test('customerTabs: volle Reiterfolge der Spec, „Aufträge und Rechnungen“ nur für Admins', () => {
assert.deepEqual(customerTabs(true), [
{ id: 'overview', label: 'Übersicht' },
{ id: 'tickets', label: 'Tickets' },
{ id: 'invoices', label: 'Aufträge und Rechnungen' },
{ id: 'projects', label: 'Projekte' },
{ id: 'chat', label: 'Chat' },
{ id: 'abo', label: 'Abo & Angebote' },
{ id: 'gutschriften', label: 'Gutschriften' },
{ id: 'funktionen', label: 'Funktionen' },
{ id: 'protokoll', label: 'Protokoll' },
])
const STAFF = ['overview', 'tickets', 'projects', 'chat', 'abo', 'gutschriften', 'funktionen', 'protokoll']
assert.deepEqual(customerTabs(false).map((t) => t.id), STAFF)
// unbekannt oder nicht eindeutig true gilt als kein Admin
for (const v of [undefined, null, 0, '', 'true']) {
assert.deepEqual(customerTabs(v).map((t) => t.id), STAFF, String(v))
}
// die Einträge tragen nur id und label (kein internes Feld)
assert.deepEqual(Object.keys(customerTabs(true)[2]), ['id', 'label'])
})
test('resolveCustomerTab: erlaubter Reiter bleibt, sonst Übersicht', () => {
assert.equal(resolveCustomerTab('invoices', true), 'invoices')
assert.equal(resolveCustomerTab('invoices', false), 'overview')
assert.equal(resolveCustomerTab('invoices', undefined), 'overview')
assert.equal(resolveCustomerTab('tickets', false), 'tickets')
assert.equal(resolveCustomerTab('projects', false), 'projects')
assert.equal(resolveCustomerTab('overview', false), 'overview')
assert.equal(resolveCustomerTab('protokoll', false), 'protokoll')
assert.equal(resolveCustomerTab('chat', false), 'chat')
for (const id of ['abo', 'gutschriften', 'funktionen']) assert.equal(resolveCustomerTab(id, false), id)
assert.equal(resolveCustomerTab('gibtsnicht', true), 'overview')
assert.equal(resolveCustomerTab(undefined, true), 'overview')
})