|
| 1 | +/** |
| 2 | + * Focused regressions for the submit path in DfScriptDetailsComponent. |
| 3 | + * |
| 4 | + * These tests do not boot the full component — Angular Router + transloco + |
| 5 | + * Material make a full TestBed harness expensive. We exercise the pure |
| 6 | + * fallback and grep the committed HTML/TS to prove that the wiring which |
| 7 | + * broke a customer install on 2026-04-22 cannot silently regress. |
| 8 | + */ |
| 9 | +import { readFileSync } from 'fs'; |
| 10 | +import { join } from 'path'; |
| 11 | + |
| 12 | +const HTML_SRC = readFileSync( |
| 13 | + join(__dirname, 'df-script-details.component.html'), |
| 14 | + 'utf8' |
| 15 | +); |
| 16 | +const TS_SRC = readFileSync( |
| 17 | + join(__dirname, 'df-script-details.component.ts'), |
| 18 | + 'utf8' |
| 19 | +); |
| 20 | + |
| 21 | +describe('DfScriptDetailsComponent submit logic', () => { |
| 22 | + it('falls back on empty completeScriptName to selectedRouteItem', () => { |
| 23 | + // selectedServiceItemEvent() resets completeScriptName to '' (not null). |
| 24 | + // The old code used `??` which does not treat '' as missing, so |
| 25 | + // scriptItem.name became '' and the POST URL dropped the resource name |
| 26 | + // producing a 400 "No record(s) detected" from the backend. |
| 27 | + const completeScriptName = ''; |
| 28 | + const selectedRouteItem = 'test_underscore._schema.get.pre_process'; |
| 29 | + |
| 30 | + const name = completeScriptName || selectedRouteItem; |
| 31 | + |
| 32 | + expect(name).toBe('test_underscore._schema.get.pre_process'); |
| 33 | + }); |
| 34 | + |
| 35 | + it('prefers completeScriptName when set by selectedTable/selectedRoute', () => { |
| 36 | + const completeScriptName = 'db._schema.table_name.get.pre_process'; |
| 37 | + const selectedRouteItem = 'db._schema.{table_name}.get.pre_process'; |
| 38 | + |
| 39 | + const name = completeScriptName || selectedRouteItem; |
| 40 | + |
| 41 | + expect(name).toBe('db._schema.table_name.get.pre_process'); |
| 42 | + }); |
| 43 | + |
| 44 | + it('submit source uses `||` (not `??`) for the name fallback', () => { |
| 45 | + // Guard the exact call site — `??` would regress the empty-string bug. |
| 46 | + expect(TS_SRC).toMatch( |
| 47 | + /name:\s*this\.completeScriptName\s*\|\|\s*this\.selectedRouteItem/ |
| 48 | + ); |
| 49 | + expect(TS_SRC).not.toMatch( |
| 50 | + /name:\s*this\.completeScriptName\s*\?\?\s*this\.selectedRouteItem/ |
| 51 | + ); |
| 52 | + }); |
| 53 | +}); |
| 54 | + |
| 55 | +describe('DfScriptDetailsComponent template wiring contract', () => { |
| 56 | + // The three mat-selects must fire their change handlers. Removing any |
| 57 | + // (selectionChange) binding was what broke saving on the customer call. |
| 58 | + it('Script Method mat-select has (selectionChange)="selectedRoute()"', () => { |
| 59 | + const methodBlock = HTML_SRC.match( |
| 60 | + /scripts\.scriptMethod[\s\S]*?<\/mat-form-field>/ |
| 61 | + ); |
| 62 | + expect(methodBlock).not.toBeNull(); |
| 63 | + expect(methodBlock![0]).toContain('(selectionChange)="selectedRoute()"'); |
| 64 | + }); |
| 65 | + |
| 66 | + it('Service mat-select has (selectionChange)="selectedServiceItemEvent()"', () => { |
| 67 | + const serviceBlock = HTML_SRC.match( |
| 68 | + /'service' \| transloco[\s\S]*?<\/mat-form-field>/ |
| 69 | + ); |
| 70 | + expect(serviceBlock).not.toBeNull(); |
| 71 | + expect(serviceBlock![0]).toContain( |
| 72 | + '(selectionChange)="selectedServiceItemEvent()"' |
| 73 | + ); |
| 74 | + }); |
| 75 | + |
| 76 | + it('Script Type mat-select has (selectionChange)="selectedEventItemEvent()"', () => { |
| 77 | + const typeBlock = HTML_SRC.match( |
| 78 | + /scripts\.scriptType[\s\S]*?<\/mat-form-field>/ |
| 79 | + ); |
| 80 | + expect(typeBlock).not.toBeNull(); |
| 81 | + expect(typeBlock![0]).toContain( |
| 82 | + '(selectionChange)="selectedEventItemEvent()"' |
| 83 | + ); |
| 84 | + }); |
| 85 | +}); |
| 86 | + |
| 87 | +describe('DfScriptDetailsComponent service lookup key', () => { |
| 88 | + // /system/event responses are exempt from the case interceptor |
| 89 | + // (see case.interceptor.ts). The component must look up |
| 90 | + // response[serviceName] with the raw service name; the hardcoded |
| 91 | + // api_docs -> apiDocs rename must NOT return. |
| 92 | + it('does not reintroduce the api_docs → apiDocs rename', () => { |
| 93 | + expect(TS_SRC).not.toMatch(/serviceKey\s*=\s*['"]apiDocs['"]/); |
| 94 | + }); |
| 95 | + |
| 96 | + it('looks up events using the raw serviceName', () => { |
| 97 | + expect(TS_SRC).toMatch(/response\[serviceName\]/); |
| 98 | + }); |
| 99 | +}); |
0 commit comments