Files
tickte-system/tests/unit/customerList.test.mjs
T
ClaudeandClaude Opus 5.5 d2883018fc Kunden: Reiter "Abgesagt", Absage eintragen und Warnung vor Doppelten
- Kundenliste mit Reiter "Abgesagt" (vorher nur unter "Alle"), rotes Abzeichen,
  Suche auch nach Telefon
- Kundenseite: "Absage eintragen" fuer Leads (Grund freiwillig); Vermerk
  "Abgesagt am TT.MM.JJJJ (Name): Grund" oben in die Notizen, offene
  Akquise-Tickets auf "Abgesagt"; roter Hinweis "nicht erneut anrufen" und
  "Wieder als Lead fuehren"
- Neuer Lead (jetzt mit Telefon) und Neuer Kunde gleichen live mit allen
  Kunden ab (auch archivierte/abgesagte): Name ohne Rechtsform, E-Mail,
  Firmen-Domain (ohne Freemailer), Telefon; Abgesagte rot und zuerst,
  Knopf heisst dann "Trotzdem anlegen"
- Uebersicht wird nach Speichern neu aufgebaut (key), damit kein alter
  Notizstand den Vermerk ueberschreibt

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 16:01:21 +00:00

77 lines
4.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import test from 'node:test'
import assert from 'node:assert/strict'
import { loadModule } from './load.mjs'
const { CUSTOMER_TABS, customerStage, isArchived, filterCustomers, stageCounts, customerBadges, stageLabel, customerEyebrow, customerTitle } =
await loadModule('src/lib/customerList.js')
const A = { $id: 'a', name: 'Alpha GmbH', code: 'K-1', location: 'Kaiserslautern', email: 'info@alpha.de', contactName: 'Anna Alt', customerStatus: 'customer' }
const B = { $id: 'b', name: 'Beta', customerStatus: 'lead' }
const C = { $id: 'c', name: 'Gamma', customerStatus: 'lost' }
const D = { $id: 'd', name: 'Delta' } // Bestandsdaten ohne Status gelten als fester Kunde
const E = { $id: 'e', name: 'Epsilon', customerStatus: 'lead', archived: true, importantCustomer: true }
const F = { $id: 'f', name: 'Zeta', customerStatus: 'customer', archived: true }
const ALL = [A, B, C, D, E, F]
const ids = (list) => list.map((c) => c.$id)
test('CUSTOMER_TABS, customerStage, isArchived', () => {
assert.deepEqual(CUSTOMER_TABS, [
{ id: 'customer', label: 'Feste Kunden' }, { id: 'lead', label: 'Leads' }, { id: 'lost', label: 'Abgesagt' },
{ id: 'archived', label: 'Archiviert' }, { id: 'all', label: 'Alle' },
])
assert.equal(customerStage({ customerStatus: 'LEAD' }), 'lead')
assert.equal(customerStage({ customerStatus: 'Lost' }), 'lost')
for (const c of [{}, { customerStatus: '' }, { customerStatus: 'sonstwas' }, null, undefined]) assert.equal(customerStage(c), 'customer')
assert.equal(isArchived({ archived: true }), true)
for (const c of [{}, { archived: false }, null, undefined]) assert.equal(isArchived(c), false)
})
test('filterCustomers: jeder Reiter', () => {
assert.deepEqual(ids(filterCustomers(ALL, { stage: 'customer' })), ['a', 'd'])
assert.deepEqual(ids(filterCustomers(ALL, { stage: 'lead' })), ['b'])
assert.deepEqual(ids(filterCustomers(ALL, { stage: 'lost' })), ['c'])
assert.deepEqual(ids(filterCustomers([{ $id: 'x', customerStatus: 'lost', archived: true }], { stage: 'lost' })), [])
assert.deepEqual(ids(filterCustomers(ALL, { stage: 'archived' })), ['e', 'f'])
assert.deepEqual(ids(filterCustomers(ALL, { stage: 'all' })), ['a', 'b', 'c', 'd'])
assert.deepEqual(ids(filterCustomers(ALL)), ['a', 'd'])
assert.deepEqual(ids(filterCustomers(ALL, { stage: 'x' })), [])
assert.deepEqual(filterCustomers(undefined, { stage: 'all' }), [])
})
test('filterCustomers: Suche in Name, Code, Standort, E-Mail, Ansprechpartner und Telefon', () => {
const find = (search, stage = 'all') => ids(filterCustomers(ALL, { stage, search }))
for (const s of ['ALPHA', 'k-1', 'kaisers', 'info@alpha', 'anna']) assert.deepEqual(find(s), ['a'], s)
assert.deepEqual(find('xyz'), [])
assert.deepEqual(ids(filterCustomers([{ $id: 'p', phone: '0631 12345' }], { stage: 'all', search: '0631 123' })), ['p'])
assert.deepEqual(find('eta', 'lead'), ['b'])
assert.deepEqual(find(''), ['a', 'b', 'c', 'd'])
assert.deepEqual(ids(filterCustomers([{ $id: 'n' }], { stage: 'all', search: 'undefined' })), [])
})
test('stageCounts: dieselbe Filterfunktion wie die Liste', () => {
assert.deepEqual(stageCounts(ALL), { customer: 2, lead: 1, lost: 1, archived: 2, all: 4 })
assert.deepEqual(stageCounts(ALL, 'eta'), { customer: 0, lead: 1, lost: 0, archived: 1, all: 1 })
assert.deepEqual(stageCounts([]), { customer: 0, lead: 0, lost: 0, archived: 0, all: 0 })
})
test('customerBadges: Reihenfolge, Töne, Option stage', () => {
assert.deepEqual(customerBadges(E), [
{ key: 'important', label: 'Wichtig', tone: 'warn' },
{ key: 'lead', label: 'Lead', tone: 'muted' },
{ key: 'archived', label: 'Archiviert', tone: 'plain' },
])
assert.deepEqual(customerBadges(C), [{ key: 'lost', label: 'Abgesagt', tone: 'danger' }])
for (const c of [A, D, null]) assert.deepEqual(customerBadges(c), [])
assert.deepEqual(customerBadges(E, { stage: false }).map((b) => b.key), ['important', 'archived'])
})
test('stageLabel, customerEyebrow, customerTitle', () => {
assert.deepEqual(['customer', 'lead', 'lost'].map(stageLabel), ['Fester Kunde', 'Lead', 'Abgesagt'])
assert.equal(customerEyebrow(A), 'K-1 · Fester Kunde')
assert.equal(customerEyebrow(B), 'Lead')
assert.equal(customerEyebrow({ code: ' ', customerStatus: 'lost' }), 'Abgesagt')
assert.equal(customerTitle(A), 'Alpha GmbH')
assert.equal(customerTitle({ email: 'x@y.de' }), 'x@y.de')
assert.equal(customerTitle({}), '–')
})