/** * Lifecycle on the DETAIL page — owned later-phase rows render only while the * record's status is in the phase (guard compiled over `data`), and a section * whose every row shares one guard hides the whole card (no empty titled * shell). Legacy pagespecs keep byte-identical detail markup. */ import { describe, it, expect } from 'vitest' import { generate } from '../generate.js' import type { ScaffoldComponentInput, PageSpecMin } from '../types.js' function fixture(overrides: Partial = {}): ScaffoldComponentInput { return { module: 'fleet', appCode: 'TestV2', entity: 'Vehicle', section: 'vehicles', views: ['detail'], fields: [ { name: 'plate', type: 'string', required: true }, { name: 'etat', type: 'string', required: false, options: [ { value: 'EN_PARC', label: 'En parc' }, { value: 'SORTI', label: 'Sorti' }, ], }, { name: 'entryDate', type: 'date', required: false }, { name: 'exitDate', type: 'date', required: false }, { name: 'exitReason', type: 'string', required: false }, ], projectPath: '/web', ...overrides, } } function pageSpec(overrides: Partial = {}): PageSpecMin { return { screenCode: 'SCR-FLEET-VEHICLES-DETAIL', module: 'fleet', appCode: 'testv2', section: 'vehicles', entity: 'Vehicle', view: 'detail', filePath: 'src/pages/testv2/fleet/vehicles/VehicleDetailPage.tsx', permission: 'fleet.vehicles.read', actions: [], i18nKeys: { fr: {}, en: {}, it: {}, de: {} }, needsRefinement: false, specHash: 'x', ...overrides, } as PageSpecMin } const LIFECYCLE = { statusField: 'etat', phases: [ { key: 'sortie', statuses: ['SORTI'], fields: ['exitDate', 'exitReason'] }, ], } const detailOf = (files: ReturnType) => files.find((f) => /DetailPage\.tsx$/.test(f.path))!.content describe('scaffold-component / lifecycle — detail page', () => { it('guards each owned row on the record status (flat body)', () => { const c = detailOf(generate(fixture({ pageSpec: pageSpec({ lifecycle: LIFECYCLE }) }))) expect(c).toContain("{(data.etat === 'SORTI') && (") // Creation rows stay unguarded expect(c).toMatch(/\{t\('vehicle\.detail\.fields\.plate'\)\}/) expect(c).not.toMatch(/data\.etat === 'SORTI'\) && \([\s\S]{0,400}detail\.fields\.plate/) }) it('hides a fully-owned section behind ONE shared guard, rows unguarded inside', () => { const sections = [ { key: 'entree', label: 'Entrée', fields: ['plate', 'etat', 'entryDate'] }, { key: 'sortie', label: 'Sortie', fields: ['exitDate', 'exitReason'] }, ] const c = detailOf(generate(fixture({ pageSpec: pageSpec({ lifecycle: LIFECYCLE, sections }) }))) expect(c).toMatch(/\{\(data\.etat === 'SORTI'\) && \(\n\s+ { const c = detailOf(generate(fixture({ pageSpec: pageSpec() }))) expect(c).not.toContain("data.etat === 'SORTI'") }) })