Files
tpf/docs/superpowers/specs/2026-03-12-step-wise-mock-data-design.md

5.6 KiB

Step-wise Mock Data & Flow Bug Fixes

Problem

The app has two categories of issues preventing a complete flow-through:

  1. Data integrity bugs — process step transitions don't update all relevant nutzer fields, so the antrag checklist can never fully complete even when the user follows the happy path.
  2. Mock data gaps — the existing seedMockData() creates a single fixed state (eigensuche with 20 therapists) but doesn't set nutzer.dringlichkeitscode or nutzer.tss_beantragt, making it impossible to test the full flow or individual steps.

Goal

Fix the flow bugs so the real UI path works end-to-end, and replace the single mock-data button with a step-wise scenario dropdown in dev settings that seeds the complete app state for any given process step.

Changes

1. Bug fix: SprechstundeForm (process-stepper.tsx)

Current behavior: SprechstundeForm.onSubmit inserts into sprechstunde table with dringlichkeitscode, then separately updates nutzer.aktueller_schritt = 'diagnose_erhalten'. It never writes nutzer.dringlichkeitscode or nutzer.dringlichkeitscode_datum.

Fix: Replace the two separate queries with a single sprechstunde INSERT and a combined nutzer UPDATE:

UPDATE nutzer SET
  aktueller_schritt = 'diagnose_erhalten',
  dringlichkeitscode = $1,
  dringlichkeitscode_datum = CASE WHEN $1 = TRUE THEN $2 ELSE NULL END,
  aktualisiert_am = NOW()
WHERE id = 1

Where $1 is the dringlichkeitscode boolean and $2 is the sprechstunde datum. Uses $1 = TRUE for explicit boolean comparison (safe regardless of how the driver serializes the parameter).

2. Bug fix: TSS advance button (process-stepper.tsx)

Current behavior: The AdvanceButton for diagnose_erhalten → tss_beantragt only updates nutzer.aktueller_schritt. It never sets nutzer.tss_beantragt or nutzer.tss_beantragt_datum.

Fix: Replace the generic AdvanceButton for this specific transition with a custom handler:

UPDATE nutzer SET
  aktueller_schritt = 'tss_beantragt',
  tss_beantragt = TRUE,
  tss_beantragt_datum = CURRENT_DATE,
  aktualisiert_am = NOW()
WHERE id = 1

The StepAction switch case for diagnose_erhalten gets an inline button instead of the generic AdvanceButton.

3. Scenario module (new file)

File: src/features/einstellungen/scenarios.ts

Exports: seedToStep(step: ProzessSchritt)

Behavior: Always clears kontakt, sprechstunde, and therapeut tables first, then resets nutzer fields, then builds state cumulatively based on the target step. Each call produces a fresh, deterministic state — calling seedToStep twice produces the same result, never duplicates.

Precondition: The nutzer row must exist (user completed onboarding). The scenario dropdown in settings should be disabled if no nutzer row exists. In practice this is guaranteed because the dev settings section is only reachable after onboarding.

Step semantics: Each dropdown option seeds the state so that the user lands on that step as the current step. For example, "Schritt 3 — TSS kontaktiert" sets aktueller_schritt = 'tss_beantragt', meaning the user sees the TSS step as active with its "Eigensuche starten" action available.

Target step aktueller_schritt State seeded
neu neu All flags false, no therapists/contacts/sprechstunden
diagnose_erhalten diagnose_erhalten 1 therapist + 1 sprechstunde with dringlichkeitscode=true, nutzer.dringlichkeitscode = true, nutzer.dringlichkeitscode_datum set
tss_beantragt tss_beantragt Above + nutzer.tss_beantragt = true, nutzer.tss_beantragt_datum set
eigensuche eigensuche Above + 20 therapists with mixed contact attempts (distribution already produces ≥5 absagen+keine_antwort)
antrag_gestellt antrag_gestellt Same data as eigensuche, step advanced to final

Mock data constants (MOCK_VORNAMEN, MOCK_NACHNAMEN, MOCK_STAEDTE, etc.) move here from kontakte/hooks.ts.

Legacy step: The sprechstunde_absolviert value in ProzessSchritt is legacy and not included as a dropdown option. seedToStep does not need to handle it.

4. Settings UI (settings-page.tsx)

Replace the current dev mode section (single "Testdaten einfügen" button) with a dropdown + button:

  • Label: "Szenario laden"
  • Description: "App-Zustand für einen bestimmten Prozessschritt laden"
  • Dropdown options:
    • Schritt 1 — Erstgespräch
    • Schritt 2 — Diagnose erhalten
    • Schritt 3 — TSS kontaktiert
    • Schritt 4 — Eigensuche
    • Schritt 5 — Antrag gestellt
  • Button: "Laden"
  • Feedback: Brief "Fertig" text after seeding (same pattern as current)

5. Cleanup in kontakte/hooks.ts

  • Delete seedMockData() function
  • Delete all MOCK_* constants (MOCK_VORNAMEN, MOCK_NACHNAMEN, MOCK_STAEDTE, MOCK_THERAPIEFORMEN, MOCK_ERGEBNISSE)
  • Delete daysAgoISO() helper
  • deleteAllData() stays — it's user-facing and deletes the nutzer row (full reset to onboarding)

Out of scope

  • Antrag checklist "Absagenliste exportiert" — stays hardcoded to false. Tracking PDF export clicks is a separate feature. The checklist will show 4/5 at antrag_gestellt.

Files changed

  • Modify: src/features/prozess/components/process-stepper.tsx — fix SprechstundeForm and TSS advance button
  • Create: src/features/einstellungen/scenarios.ts — step-wise seed logic + mock constants
  • Modify: src/features/einstellungen/components/settings-page.tsx — dropdown UI replacing single button
  • Modify: src/features/kontakte/hooks.ts — remove seedMockData, mock constants, daysAgoISO