Buchungskalender: Abgleich – art monteurzimmer, Zurückziehen-409 mit Meldung, Tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
knsoandClaude Opus 5.5 committed 2026-10-07 14:53:13 +00:00
1 parent 54442a4682
commit f01e6def59
2 files changed
+32 -4

No files matched your search

+6 -4
View File
@@ -6,11 +6,13 @@
import { allgemeinerFehler, datumText, feld, h, hakenFeld, request, setzeFehler, zeigeFehler } from './shop-dom.js'
import { fehlerFuerFormular } from './buchungen-fehler.js'
export const ARTEN = [['ferienwohnung', 'Ferienwohnung oder Ferienhaus'], ['monteur', 'Monteurwohnung'], ['pension', 'Pension oder Gästezimmer'], ['sonstiges', 'Sonstiges']]
export const ARTEN = [['ferienwohnung', 'Ferienwohnung oder Ferienhaus'], ['monteurzimmer', 'Monteurwohnung'], ['pension', 'Pension oder Gästezimmer'], ['sonstiges', 'Sonstiges']]
export const PORTALE = [['booking', 'Booking.com'], ['airbnb', 'Airbnb']]
export const KALENDER_PREIS = '199 €'
const text = (wert) => (typeof wert === 'string' ? wert : '')
/** Der Server liest 'monteur' als Alias, gibt es aber in der Anfrage so zurueck; die Auswahl kennt nur 'monteurzimmer'. */
const artWert = (a) => (a === 'monteur' ? 'monteurzimmer' : a)
const labelVon = (liste, key) => liste.find(([k]) => k === key)?.[1] || ''
const enc = encodeURIComponent
@@ -19,7 +21,7 @@ export function anfrageListe(a) {
const s = a && typeof a === 'object' ? a : {}
const portale = (Array.isArray(s.portale) ? s.portale : []).map((p) => labelVon(PORTALE, p)).filter(Boolean).join(', ')
const zeilen = [
['Art der Unterkunft', labelVon(ARTEN, s.art)],
['Art der Unterkunft', labelVon(ARTEN, artWert(s.art))],
['Anzahl Einheiten', Number.isInteger(s.einheiten) ? String(s.einheiten) : ''],
['Portale', portale || 'keine'],
['Nachricht', text(s.nachricht)],
@@ -31,7 +33,7 @@ export function anfrageListe(a) {
export function renderAnfrageFormular(root, { projectId, vorgabe = null, preis = KALENDER_PREIS, nachSenden } = {}) {
const v = vorgabe && typeof vorgabe === 'object' ? vorgabe : {}
const art = h('select', null, [h('option', { value: '' }, 'Bitte wählen …'), ...ARTEN.map(([w, n]) => h('option', { value: w }, n))])
art.value = ARTEN.some(([k]) => k === v.art) ? v.art : ''
art.value = ARTEN.some(([k]) => k === artWert(v.art)) ? artWert(v.art) : ''
const einheiten = h('input', { type: 'text', inputmode: 'numeric', maxlength: 3, autocomplete: 'off' })
einheiten.value = Number.isInteger(v.einheiten) ? String(v.einheiten) : ''
const portale = PORTALE.map(([wert]) => {
@@ -116,7 +118,7 @@ export function anfrageKarte(ansicht, { projectId, neu, neuLaden } = {}) {
return
} catch (err) {
meldung.textContent = err.message
if (err?.status === 409 && typeof neuLaden === 'function') { try { await neuLaden() } catch { /* Meldung bleibt */ } return }
if (err?.status === 409 && typeof neuLaden === 'function') { try { await neuLaden({ meldung: err.message }) } catch { /* Meldung bleibt */ } return }
}
aktion.disabled = false
})
+26
View File
@@ -731,6 +731,32 @@ test('Anfragekarte: offen mit Zurückziehen, abgelehnt mit Begründung als Text'
})()
})
test('Anfrageformular sendet monteurzimmer; ein vorhandenes monteur wird als Monteurwohnung gewaehlt', async () => {
await mit(() => ({ body: { anfrage: { status: 'offen' } } }), async (fx) => {
const wurzel = h('div')
fx.document.body.append(wurzel)
renderAnfrageFormular(wurzel, { projectId: 'p1', vorgabe: { art: 'monteur', einheiten: 2, portale: [], nachricht: '' }, nachSenden: async () => {} })
assert.equal(fx.finde(wurzel, '[data-feld="art"]').value, 'monteurzimmer')
await fx.setze(fx.finde(wurzel, '[data-feld="einheiten"]'), '2')
await fx.klick(fx.finde(wurzel, '[data-aktion="anfrage-senden"]'))
await fx.ruhe()
assert.equal(posts(fx).at(-1).body.art, 'monteurzimmer')
})()
})
test('Zurückziehen 409: Stand wird mit der Meldung neu geladen', async () => {
await mit((a) => (a.url.includes('zurueckziehen') ? { status: 409, body: { fehler: 'status_ungueltig', error: 'Die Anfrage wurde schon bearbeitet.' } } : { body: {} }), async (fx) => {
const gesehen = []
const k = anfrageKarte({ status: 'offen', at: '2026-10-07T10:00:00Z', anfrage: { art: 'pension' } }, { projectId: 'p1', neuLaden: async (o) => { gesehen.push(o) } })
fx.document.body.append(k)
await fx.klick(fx.finde(k, '[data-aktion="zurueckziehen"]'))
await fx.ruhe()
assert.equal(gesehen.length, 1)
assert.equal(typeof gesehen[0]?.meldung, 'string')
assert.ok(gesehen[0].meldung.length > 0)
})()
})
test('Ansicht #buchungen: Zustand off zeigt das Anfrageformular, Projekt vom Wunsch-Attribut', async () => {
vergissAuswahl()
await mit((a) => {