pict-section-form 1.3.13 → 1.3.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/docs/Injection_Conformance.md +137 -0
  2. package/docs/_sidebar.md +1 -0
  3. package/docs/input_providers/012-tab-group-selector.md +3 -1
  4. package/docs/input_providers/013-tab-section-selector.md +3 -1
  5. package/package.json +6 -5
  6. package/source/providers/Pict-Provider-DynamicFormSolverBehaviors.js +73 -5
  7. package/source/providers/Pict-Provider-DynamicSolver.js +20 -2
  8. package/source/providers/inputs/Pict-Provider-Input-TabGroupSelector.js +42 -3
  9. package/source/providers/inputs/Pict-Provider-Input-TabSectionSelector.js +42 -3
  10. package/source/views/Pict-View-Form-Metacontroller.js +685 -90
  11. package/test/Pict-Provider-DynamicFormSolverBehaviors-OrdinalScope_tests.js +105 -0
  12. package/test/Pict-Provider-Input-TabGroupSelector-TabHashValidation_tests.js +178 -0
  13. package/test/Pict-Provider-Input-TabSectionSelector-TabHashValidation_tests.js +193 -0
  14. package/test/Pict-View-Form-Metacontroller-DistinctManifest_tests.js +410 -0
  15. package/test/PictSectionForm-Injection-Conformance_tests.js +751 -0
  16. package/test/browser/Injection-Conformance-Differential-Scenario.js +346 -0
  17. package/test/browser/Injection-Conformance-EdgeCase-Scenario.js +168 -0
  18. package/test/browser/Injection-Conformance-Harness-Driver.js +538 -0
  19. package/test/browser/Injection-Conformance-Harness-Runner.js +487 -0
  20. package/test/browser/Injection-Conformance-Reconstitution-Scenario.js +191 -0
  21. package/test/browser/Injection-Conformance-Standalone-Scenario.js +114 -0
  22. package/test/fixtures/injection/Injection-Fixture-Cases.js +203 -0
  23. package/test/fixtures/injection/Injection-Fixture-Manifest.json +366 -0
  24. package/types/source/providers/Pict-Provider-DynamicFormSolverBehaviors.d.ts +110 -1
  25. package/types/source/providers/Pict-Provider-DynamicFormSolverBehaviors.d.ts.map +1 -1
  26. package/types/source/providers/Pict-Provider-DynamicSolver.d.ts.map +1 -1
  27. package/types/source/providers/Pict-Provider-DynamicTabularData.d.ts +17 -1
  28. package/types/source/providers/Pict-Provider-DynamicTabularData.d.ts.map +1 -1
  29. package/types/source/providers/Pict-Provider-InputExtension.d.ts +31 -0
  30. package/types/source/providers/Pict-Provider-InputExtension.d.ts.map +1 -1
  31. package/types/source/providers/inputs/Pict-Provider-Input-Chart-CSS.d.ts +16 -0
  32. package/types/source/providers/inputs/Pict-Provider-Input-Chart-CSS.d.ts.map +1 -0
  33. package/types/source/providers/inputs/Pict-Provider-Input-Chart.d.ts +47 -0
  34. package/types/source/providers/inputs/Pict-Provider-Input-Chart.d.ts.map +1 -1
  35. package/types/source/providers/inputs/Pict-Provider-Input-Diagram.d.ts +86 -0
  36. package/types/source/providers/inputs/Pict-Provider-Input-Diagram.d.ts.map +1 -1
  37. package/types/source/providers/inputs/Pict-Provider-Input-ObjectEditor.d.ts +128 -0
  38. package/types/source/providers/inputs/Pict-Provider-Input-ObjectEditor.d.ts.map +1 -0
  39. package/types/source/providers/inputs/Pict-Provider-Input-PreciseNumber.d.ts.map +1 -1
  40. package/types/source/providers/inputs/Pict-Provider-Input-TabGroupSelector.d.ts +10 -1
  41. package/types/source/providers/inputs/Pict-Provider-Input-TabGroupSelector.d.ts.map +1 -1
  42. package/types/source/providers/inputs/Pict-Provider-Input-TabSectionSelector.d.ts +10 -1
  43. package/types/source/providers/inputs/Pict-Provider-Input-TabSectionSelector.d.ts.map +1 -1
  44. package/types/source/providers/layouts/Pict-Layout-Tabular.d.ts +76 -4
  45. package/types/source/providers/layouts/Pict-Layout-Tabular.d.ts.map +1 -1
  46. package/types/source/views/Pict-View-DynamicForm.d.ts.map +1 -1
  47. package/types/source/views/Pict-View-Form-Metacontroller.d.ts +63 -2
  48. package/types/source/views/Pict-View-Form-Metacontroller.d.ts.map +1 -1
@@ -0,0 +1,751 @@
1
+ /*
2
+ Injection conformance, data tier.
3
+
4
+ A manifest can be injected into a running form more than once, each copy salted so that it owns its own
5
+ data. This suite is the tier that runs anywhere, as part of `npm test`:
6
+
7
+ - fixture coverage, measured against the library's own registries: every input type, every construct
8
+ createDistinctManifest translates, every solver directive and every reference shape
9
+ - a salted copy refers to nothing of its own by its unsalted name
10
+ - data round trip through two injected copies: data in, solve, read back, write through the view, and
11
+ re-render from what was saved -- all through the view data API, which is what browser-env can drive
12
+
13
+ The browser tier (test/browser, `npm run test:injection`) covers what needs a painted page: charts, tab
14
+ switching, templated rendering, trigger groups driven by real events and the DOM controls themselves.
15
+
16
+ Adding an input type to the library fails the coverage suite until a fixture case is declared in
17
+ test/fixtures/injection/Injection-Fixture-Cases.js. See docs/Injection_Conformance.md.
18
+ */
19
+
20
+ // This is temporary, but enables unit tests
21
+ const libBrowserEnv = require('browser-env');
22
+ libBrowserEnv();
23
+
24
+ const libFS = require('fs');
25
+ const libPath = require('path');
26
+
27
+ const Chai = require('chai');
28
+ const Expect = Chai.expect;
29
+
30
+ const libPict = require('pict');
31
+
32
+ const libPictSectionForm = require('../source/Pict-Section-Form.js');
33
+ const libMetacontroller = require('../source/views/Pict-View-Form-Metacontroller.js');
34
+ const libDynamicFormSolverBehaviors = require('../source/providers/Pict-Provider-DynamicFormSolverBehaviors.js');
35
+ const libDefaultFormTemplates = require('../source/providers/dynamictemplates/Pict-DynamicTemplates-DefaultFormTemplates.js');
36
+ const libReadOnlyFormTemplates = require('../source/providers/dynamictemplates/Pict-DynamicTemplates-DefaultFormTemplates-ReadOnly.js');
37
+
38
+ const _Fixture = require('./fixtures/injection/Injection-Fixture-Manifest.json');
39
+ const _Cases = require('./fixtures/injection/Injection-Fixture-Cases.js');
40
+
41
+ const _CasesFile = 'test/fixtures/injection/Injection-Fixture-Cases.js';
42
+ const _ManifestFile = 'test/fixtures/injection/Injection-Fixture-Manifest.json';
43
+
44
+ // Properties whose strings are solver expressions, so they are read with the expression parser rather than
45
+ // scanned as text. Driven by the injector's own checklist, plus the manifest level solver arrays.
46
+ const _SolverProperties = [ 'Solvers', 'ValidationSolvers' ]
47
+ .concat(libMetacontroller.InjectionTranslation.InputSolverProperties)
48
+ .concat(libMetacontroller.InjectionTranslation.TriggerGroupSolverProperties)
49
+ .concat(libMetacontroller.InjectionTranslation.InputSolverSetProperties.map((pEntry) => pEntry.SolverProperty));
50
+ const _RecordRelativeSolverProperties = [ 'RecordSetSolvers' ];
51
+
52
+ /**
53
+ * Every input type the metatemplates dispatch on, and every input provider in the library.
54
+ *
55
+ * @return {Set<string>} registry keys, in the `InputType:<name>` / `Provider:<name>` form the cases use
56
+ */
57
+ function enumerateInputRegistry()
58
+ {
59
+ const tmpRegistry = new Set();
60
+ for (const tmpTemplateSet of [ libDefaultFormTemplates, libReadOnlyFormTemplates ])
61
+ {
62
+ for (const tmpTemplate of (tmpTemplateSet.Templates || []))
63
+ {
64
+ const tmpMatch = /-Input-(?:InputType|DataType)-([A-Za-z0-9]+)$/.exec(tmpTemplate.HashPostfix || '');
65
+ if (tmpMatch)
66
+ {
67
+ tmpRegistry.add(`InputType:${tmpMatch[1]}`);
68
+ }
69
+ }
70
+ }
71
+ for (const tmpFileName of libFS.readdirSync(libPath.join(__dirname, '..', 'source', 'providers', 'inputs')))
72
+ {
73
+ const tmpMatch = /^Pict-Provider-Input-(.+)\.js$/.exec(tmpFileName);
74
+ if (tmpMatch && !tmpMatch[1].endsWith('-CSS'))
75
+ {
76
+ tmpRegistry.add(`Provider:Pict-Input-${tmpMatch[1]}`);
77
+ }
78
+ }
79
+ return tmpRegistry;
80
+ }
81
+
82
+ /**
83
+ * @param {string} pMarshalDestination
84
+ * @return {any} a metacontroller with just enough wiring to salt a manifest
85
+ */
86
+ function buildMetacontroller(pMarshalDestination)
87
+ {
88
+ const tmpPict = new libPict({ Product: 'InjectionConformance', LogStreams: [ { streamtype: 'console', level: 'fatal' } ] });
89
+ tmpPict.addProvider('DynamicFormSolverBehaviors', {}, libDynamicFormSolverBehaviors);
90
+ tmpPict.providers.DynamicFormSolverBehaviors.injectBehaviors(tmpPict.instantiateServiceProviderIfNotExists('ExpressionParser'));
91
+ tmpPict.providers.DataBroker.marshalDestination = pMarshalDestination;
92
+ const tmpMetacontroller = Object.create(libMetacontroller.prototype);
93
+ tmpMetacontroller.pict = tmpPict;
94
+ tmpMetacontroller.fable = tmpPict;
95
+ tmpMetacontroller.log = tmpPict.log;
96
+ tmpMetacontroller.options = {};
97
+ return tmpMetacontroller;
98
+ }
99
+
100
+ /**
101
+ * Everything the manifest calls its own, by its unsalted name.
102
+ *
103
+ * @param {Record<string, any>} pManifest
104
+ * @return {Array<string>}
105
+ */
106
+ function localNames(pManifest)
107
+ {
108
+ const tmpNames = new Set();
109
+ for (const tmpSection of pManifest.Sections || [])
110
+ {
111
+ tmpNames.add(tmpSection.Hash);
112
+ for (const tmpGroup of tmpSection.Groups || [])
113
+ {
114
+ tmpNames.add(tmpGroup.Hash);
115
+ if (tmpGroup.RecordSetAddress)
116
+ {
117
+ tmpNames.add(tmpGroup.RecordSetAddress);
118
+ }
119
+ }
120
+ }
121
+ for (const [ tmpKey, tmpDescriptor ] of Object.entries(pManifest.Descriptors || {}))
122
+ {
123
+ tmpNames.add(tmpDescriptor.DataAddress || tmpKey);
124
+ if (tmpDescriptor.Hash)
125
+ {
126
+ tmpNames.add(tmpDescriptor.Hash);
127
+ }
128
+ }
129
+ return Array.from(tmpNames);
130
+ }
131
+
132
+ /**
133
+ * Every solver expression the fixture manifest holds, as written.
134
+ *
135
+ * @param {Record<string, any>} pManifest
136
+ * @return {Array<string>}
137
+ */
138
+ function solverExpressions(pManifest)
139
+ {
140
+ const tmpExpressions = [];
141
+ const collect = (pValue, pKey) =>
142
+ {
143
+ if (Array.isArray(pValue))
144
+ {
145
+ for (const tmpEntry of pValue)
146
+ {
147
+ collect(tmpEntry, pKey);
148
+ }
149
+ return;
150
+ }
151
+ if (typeof(pValue) === 'string')
152
+ {
153
+ tmpExpressions.push(pValue);
154
+ return;
155
+ }
156
+ if (pValue && (typeof(pValue) === 'object') && (typeof(pValue.Expression) === 'string'))
157
+ {
158
+ tmpExpressions.push(pValue.Expression);
159
+ }
160
+ };
161
+ const walk = (pNode) =>
162
+ {
163
+ if (Array.isArray(pNode))
164
+ {
165
+ pNode.forEach(walk);
166
+ return;
167
+ }
168
+ if (!pNode || (typeof(pNode) !== 'object'))
169
+ {
170
+ return;
171
+ }
172
+ for (const [ tmpKey, tmpChild ] of Object.entries(pNode))
173
+ {
174
+ if (_SolverProperties.includes(tmpKey) || _RecordRelativeSolverProperties.includes(tmpKey))
175
+ {
176
+ collect(tmpChild, tmpKey);
177
+ }
178
+ walk(tmpChild);
179
+ }
180
+ };
181
+ walk(pManifest);
182
+ return tmpExpressions;
183
+ }
184
+
185
+ /**
186
+ * Reads a salted solver expression with the expression parser and reports references to the manifest that
187
+ * were left unsalted. Iteration variables a directive declares, string literals that are not address
188
+ * parameters, and -- in a record set solver -- the columns of a record, are all names of something other
189
+ * than the manifest, so they are not reported.
190
+ *
191
+ * @param {any} pMetacontroller
192
+ * @param {string} pExpression
193
+ * @param {Array<string>} pLocalNames
194
+ * @param {boolean} pRecordRelative
195
+ * @return {Array<string>} the untranslated references
196
+ */
197
+ function findUntranslatedSolverReferences(pMetacontroller, pExpression, pLocalNames, pRecordRelative)
198
+ {
199
+ const tmpExpressionParser = pMetacontroller.pict.instantiateServiceProviderIfNotExists('ExpressionParser');
200
+ const tmpLocalNameSet = new Set(pLocalNames);
201
+ const tmpResultObject = {};
202
+ tmpExpressionParser.tokenize(pExpression, tmpResultObject);
203
+ const tmpTokens = Array.from(tmpResultObject.OriginalRawTokens || []);
204
+ const tmpDirectiveScope = pMetacontroller.parseSolverDirectiveScope(tmpTokens);
205
+ const tmpFindings = [];
206
+ const tmpFunctionStack = [];
207
+ let tmpParenDepth = 0;
208
+ for (let i = 0; i < tmpTokens.length; i++)
209
+ {
210
+ const tmpToken = String(tmpTokens[i]);
211
+ if (tmpToken === '(')
212
+ {
213
+ if ((i > 0) && (tmpTokens[i - 1].toLowerCase() in tmpExpressionParser.functionMap))
214
+ {
215
+ tmpFunctionStack.push({ name: tmpTokens[i - 1].toLowerCase(), paramIndex: 0, depth: tmpParenDepth });
216
+ }
217
+ tmpParenDepth++;
218
+ continue;
219
+ }
220
+ if (tmpToken === ')')
221
+ {
222
+ tmpParenDepth--;
223
+ if ((tmpFunctionStack.length > 0) && (tmpFunctionStack[tmpFunctionStack.length - 1].depth === tmpParenDepth))
224
+ {
225
+ tmpFunctionStack.pop();
226
+ }
227
+ continue;
228
+ }
229
+ if (tmpToken === ',')
230
+ {
231
+ if ((tmpFunctionStack.length > 0) && (tmpFunctionStack[tmpFunctionStack.length - 1].depth === (tmpParenDepth - 1)))
232
+ {
233
+ tmpFunctionStack[tmpFunctionStack.length - 1].paramIndex++;
234
+ }
235
+ continue;
236
+ }
237
+ if (tmpDirectiveScope)
238
+ {
239
+ if ((i >= tmpDirectiveScope.HeaderStart) && (i <= tmpDirectiveScope.HeaderEnd) && !tmpDirectiveScope.TranslateIndices.has(i))
240
+ {
241
+ continue;
242
+ }
243
+ if ((i > tmpDirectiveScope.HeaderEnd) && tmpDirectiveScope.Locals.has(tmpToken.replace(/^\{|\}$/g, '').split(/[.[]/)[0]))
244
+ {
245
+ continue;
246
+ }
247
+ }
248
+ const tmpTokenType = tmpExpressionParser.Tokenizer.getTokenType(tmpToken);
249
+ let tmpReference = null;
250
+ if ((tmpTokenType === 'Token.Symbol') && !pRecordRelative)
251
+ {
252
+ tmpReference = tmpToken;
253
+ }
254
+ else if ((tmpTokenType === 'Token.StateAddress') && !pRecordRelative)
255
+ {
256
+ tmpReference = tmpToken.substring(1, tmpToken.length - 1);
257
+ }
258
+ else if (tmpTokenType === 'Token.String')
259
+ {
260
+ const tmpFunction = tmpFunctionStack[tmpFunctionStack.length - 1];
261
+ const tmpFunctionEntry = tmpFunction ? tmpExpressionParser.functionMap[tmpFunction.name] : null;
262
+ if (tmpFunctionEntry && Array.isArray(tmpFunctionEntry.AddressParameterIndices) && tmpFunctionEntry.AddressParameterIndices.includes(tmpFunction.paramIndex))
263
+ {
264
+ tmpReference = tmpToken.substring(1, tmpToken.length - 1);
265
+ }
266
+ }
267
+ if (tmpReference === null)
268
+ {
269
+ continue;
270
+ }
271
+ const tmpBase = tmpReference.split(/[.[]/)[0];
272
+ if (tmpLocalNameSet.has(tmpReference) || tmpLocalNameSet.has(tmpBase))
273
+ {
274
+ tmpFindings.push(tmpReference);
275
+ }
276
+ }
277
+ return tmpFindings;
278
+ }
279
+
280
+ /**
281
+ * Finds names of the manifest that a salted copy still refers to by their unsalted name. Salted references
282
+ * are removed from the text first, so what is left is what was missed.
283
+ *
284
+ * @param {any} pMetacontroller
285
+ * @param {any} pValue - The salted node to scan.
286
+ * @param {Array<string>} pLocalNames
287
+ * @param {string} pSalt
288
+ * @param {string} [pPath]
289
+ * @param {Array<string>} [pFindings]
290
+ * @param {string} [pSolverProperty] - Set while walking the contents of a solver property.
291
+ * @return {Array<string>} `path: name` for each reference that was not translated
292
+ */
293
+ function findUntranslatedReferences(pMetacontroller, pValue, pLocalNames, pSalt, pPath, pFindings, pSolverProperty)
294
+ {
295
+ const tmpPath = pPath || '';
296
+ const tmpFindings = pFindings || [];
297
+ if (Array.isArray(pValue))
298
+ {
299
+ for (let i = 0; i < pValue.length; i++)
300
+ {
301
+ findUntranslatedReferences(pMetacontroller, pValue[i], pLocalNames, pSalt, `${tmpPath}[${i}]`, tmpFindings, pSolverProperty);
302
+ }
303
+ return tmpFindings;
304
+ }
305
+ if (pValue && (typeof(pValue) === 'object'))
306
+ {
307
+ for (const [ tmpKey, tmpChild ] of Object.entries(pValue))
308
+ {
309
+ if (_Cases.LABEL_PROPERTIES.includes(tmpKey))
310
+ {
311
+ continue;
312
+ }
313
+ const tmpChildSolverProperty = (_SolverProperties.includes(tmpKey) || _RecordRelativeSolverProperties.includes(tmpKey)) ? tmpKey : ((tmpKey === 'Expression') ? pSolverProperty : null);
314
+ findUntranslatedReferences(pMetacontroller, tmpChild, pLocalNames, pSalt, tmpPath ? `${tmpPath}.${tmpKey}` : tmpKey, tmpFindings, tmpChildSolverProperty);
315
+ }
316
+ return tmpFindings;
317
+ }
318
+ if (typeof(pValue) !== 'string')
319
+ {
320
+ return tmpFindings;
321
+ }
322
+ if (pSolverProperty)
323
+ {
324
+ for (const tmpReference of findUntranslatedSolverReferences(pMetacontroller, pValue, pLocalNames, _RecordRelativeSolverProperties.includes(pSolverProperty)))
325
+ {
326
+ tmpFindings.push(`${tmpPath}: ${tmpReference}`);
327
+ }
328
+ return tmpFindings;
329
+ }
330
+ const tmpRemainder = pValue
331
+ .replace(new RegExp(`${pSalt}\\.[A-Za-z0-9_$.[\\]]+`, 'g'), ' ')
332
+ .replace(new RegExp(`[A-Za-z0-9_$]+_${pSalt}`, 'g'), ' ');
333
+ for (const tmpName of pLocalNames)
334
+ {
335
+ const tmpPattern = new RegExp(`(^|[^A-Za-z0-9_$])${tmpName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}([^A-Za-z0-9_$]|$)`);
336
+ if (tmpPattern.test(tmpRemainder))
337
+ {
338
+ tmpFindings.push(`${tmpPath}: ${tmpName}`);
339
+ }
340
+ }
341
+ return tmpFindings;
342
+ }
343
+
344
+ suite('PictSectionForm injection conformance', () =>
345
+ {
346
+ suite('fixture coverage', () =>
347
+ {
348
+ test('every input type and input provider in the library has a fixture case', () =>
349
+ {
350
+ const tmpCovered = new Set(_Cases.INPUT_CASES.map((pCase) => pCase.Registry));
351
+ const tmpMissing = Array.from(enumerateInputRegistry()).filter((pEntry) => !tmpCovered.has(pEntry) && !(pEntry in _Cases.EXCLUDED_REGISTRY_ENTRIES));
352
+ Expect(tmpMissing, `Add a fixture case (or an explained exclusion) in ${_CasesFile} for: ${tmpMissing.join(', ')}`).to.deep.equal([]);
353
+ });
354
+
355
+ test('every fixture case names an input that is in the fixture manifest', () =>
356
+ {
357
+ const tmpHashes = new Set();
358
+ for (const [ tmpKey, tmpDescriptor ] of Object.entries(_Fixture.InjectableManifest.Descriptors))
359
+ {
360
+ tmpHashes.add(tmpDescriptor.Hash || tmpKey);
361
+ }
362
+ for (const tmpReferenceManifest of Object.values(_Fixture.InjectableManifest.ReferenceManifests || {}))
363
+ {
364
+ for (const [ tmpKey, tmpDescriptor ] of Object.entries(tmpReferenceManifest.Descriptors || {}))
365
+ {
366
+ tmpHashes.add(tmpDescriptor.Hash || tmpKey);
367
+ }
368
+ }
369
+ const tmpMissing = _Cases.INPUT_CASES.filter((pCase) => !tmpHashes.has(pCase.Hash)).map((pCase) => `${pCase.Registry} -> ${pCase.Hash}`);
370
+ Expect(tmpMissing, `Fixture cases naming an input ${_ManifestFile} does not define`).to.deep.equal([]);
371
+ });
372
+
373
+ test('every construct the injector translates appears in the fixture manifest', () =>
374
+ {
375
+ const tmpTranslation = libMetacontroller.InjectionTranslation;
376
+ const tmpProperties = []
377
+ .concat(tmpTranslation.InputSectionHashProperties, tmpTranslation.InputGroupHashProperties, tmpTranslation.InputSolverProperties,
378
+ tmpTranslation.InputAddressProperties, tmpTranslation.InputTriggerGroupProperties, tmpTranslation.InputTemplateProperties,
379
+ tmpTranslation.InputEntityBundleProperties, tmpTranslation.EntityBundleAddressProperties, tmpTranslation.EntityBundleTemplateProperties,
380
+ tmpTranslation.TriggerGroupSolverProperties, tmpTranslation.InputSolverSetProperties.map((pEntry) => pEntry.Property));
381
+ const tmpFixtureText = JSON.stringify(_Fixture.InjectableManifest);
382
+ const tmpMissing = tmpProperties.filter((pProperty) => !tmpFixtureText.includes(`"${pProperty}"`));
383
+ Expect(tmpMissing, `The injector translates these, so the fixture manifest has to use them; add them in ${_ManifestFile}: ${tmpMissing.join(', ')}`).to.deep.equal([]);
384
+ });
385
+
386
+ test('every manifest construct the injector translates is exercised by the fixture manifest', () =>
387
+ {
388
+ const tmpManifest = _Fixture.InjectableManifest;
389
+ const tmpGroups = (tmpManifest.Sections || []).reduce((pGroups, pSection) => pGroups.concat(pSection.Groups || []), []);
390
+ const tmpExercised =
391
+ {
392
+ 'Sections.Solvers': (tmpManifest.Sections || []).some((pSection) => Array.isArray(pSection.Solvers) && (pSection.Solvers.length > 0)),
393
+ 'Sections.Groups.RecordSetAddress': tmpGroups.some((pGroup) => Boolean(pGroup.RecordSetAddress)),
394
+ 'Sections.Groups.RecordSetSolvers': tmpGroups.some((pGroup) => Array.isArray(pGroup.RecordSetSolvers) && (pGroup.RecordSetSolvers.length > 0)),
395
+ 'ReferenceManifests': Object.keys(tmpManifest.ReferenceManifests || {}).length > 0,
396
+ 'ValidationSolvers': Array.isArray(tmpManifest.ValidationSolvers) && (tmpManifest.ValidationSolvers.length > 0),
397
+ 'Descriptors.DataAddress': Object.keys(tmpManifest.Descriptors || {}).length > 0,
398
+ 'Descriptors.Hash': Object.values(tmpManifest.Descriptors || {}).some((pDescriptor) => Boolean(pDescriptor.Hash)),
399
+ 'Descriptors.PictForm.Section': Object.values(tmpManifest.Descriptors || {}).some((pDescriptor) => Boolean(pDescriptor.PictForm && pDescriptor.PictForm.Section)),
400
+ 'Descriptors.PictForm.Group': Object.values(tmpManifest.Descriptors || {}).some((pDescriptor) => Boolean(pDescriptor.PictForm && pDescriptor.PictForm.Group)),
401
+ };
402
+ const tmpMissing = libMetacontroller.InjectionTranslation.ManifestConstructs.filter((pConstruct) => !tmpExercised[pConstruct]);
403
+ Expect(tmpMissing, 'Manifest constructs the injector translates with no fixture coverage').to.deep.equal([]);
404
+ });
405
+
406
+ test('every solver directive is used by the fixture manifest', () =>
407
+ {
408
+ const tmpSolverText = solverExpressions(_Fixture.InjectableManifest).join('\n');
409
+ const tmpMissing = libMetacontroller.InjectionTranslation.SolverDirectiveCodes
410
+ .filter((pCode) => !(pCode in _Cases.EXCLUDED_SOLVER_DIRECTIVES))
411
+ .filter((pCode) => !tmpSolverText.includes(pCode));
412
+ Expect(tmpMissing, `Add a fixture solver using each directive, or explain the exclusion in ${_CasesFile}: ${tmpMissing.join(', ')}`).to.deep.equal([]);
413
+ });
414
+
415
+ test('every reference shape a solver can name something of its own in appears in the fixture manifest', () =>
416
+ {
417
+ const tmpSolverText = solverExpressions(_Fixture.InjectableManifest).join('\n');
418
+ const tmpMissing = Object.entries(_Cases.REFERENCE_SHAPES).filter(([ , pPattern ]) => !pPattern.test(tmpSolverText)).map(([ pShape ]) => pShape);
419
+ Expect(tmpMissing, `Reference shapes with no fixture coverage; add a solver using them in ${_ManifestFile}`).to.deep.equal([]);
420
+ });
421
+ });
422
+
423
+ suite('a salted copy refers to nothing of its own by its unsalted name', () =>
424
+ {
425
+ test('no section, group or input of an injected copy holds an untranslated reference', () =>
426
+ {
427
+ const tmpMetacontroller = buildMetacontroller(_Cases.MARSHAL_DESTINATION);
428
+ const tmpNames = localNames(_Fixture.InjectableManifest);
429
+ for (const tmpSalt of _Cases.SALTS)
430
+ {
431
+ const tmpSalted = tmpMetacontroller.createDistinctManifest(_Fixture.InjectableManifest, tmpSalt);
432
+ const tmpFindings = findUntranslatedReferences(tmpMetacontroller, { Sections: tmpSalted.Sections, Descriptors: tmpSalted.Descriptors }, tmpNames, tmpSalt);
433
+ Expect(tmpFindings, `Untranslated references in the [${tmpSalt}] copy. Either translate the construct in createDistinctManifest, or -- if the property cannot name anything of the manifest -- add it to LABEL_PROPERTIES in ${_CasesFile}.`).to.deep.equal([]);
434
+ }
435
+ });
436
+
437
+ test('a record set column keeps its own name, but its trigger group is translated', () =>
438
+ {
439
+ const tmpMetacontroller = buildMetacontroller(_Cases.MARSHAL_DESTINATION);
440
+ const tmpSalted = tmpMetacontroller.createDistinctManifest(_Fixture.InjectableManifest, 'alpha');
441
+ const tmpColumn = tmpSalted.ReferenceManifests.CrateRow.Descriptors.Tally;
442
+ Expect(tmpColumn.Hash, 'a record set column is relative to a record, so its hash is untouched').to.equal('Tally');
443
+ Expect(tmpColumn.PictForm.TabularTriggerGroup[0].PostSolvers[0], 'a column trigger group solver runs against the section view').to.contain('alpha.Rows[].Tally');
444
+ Expect(tmpColumn.PictForm.TabularTriggerGroup[0].TriggerGroupHash, 'a column trigger group is salted with the rest of the copy').to.equal('CrateRowTally_alpha');
445
+ });
446
+
447
+ test('every input of the fixture is reachable by its salted hash', () =>
448
+ {
449
+ const tmpMetacontroller = buildMetacontroller(_Cases.MARSHAL_DESTINATION);
450
+ const tmpSalted = tmpMetacontroller.createDistinctManifest(_Fixture.InjectableManifest, 'alpha');
451
+ const tmpHashes = new Set(Object.values(tmpSalted.Descriptors).map((pDescriptor) => pDescriptor.Hash));
452
+ for (const tmpReferenceManifest of Object.values(tmpSalted.ReferenceManifests || {}))
453
+ {
454
+ for (const [ tmpKey, tmpDescriptor ] of Object.entries(tmpReferenceManifest.Descriptors || {}))
455
+ {
456
+ tmpHashes.add(tmpDescriptor.Hash || tmpKey);
457
+ }
458
+ }
459
+ const tmpMissing = _Cases.INPUT_CASES.filter((pCase) => !tmpHashes.has(`${pCase.Hash}_alpha`) && !tmpHashes.has(pCase.Hash)).map((pCase) => pCase.Hash);
460
+ Expect(tmpMissing, 'Fixture inputs missing from the salted copy').to.deep.equal([]);
461
+ });
462
+
463
+ test('two copies of the manifest share no address, hash or record set', () =>
464
+ {
465
+ const tmpMetacontroller = buildMetacontroller(_Cases.MARSHAL_DESTINATION);
466
+ const tmpFirst = tmpMetacontroller.createDistinctManifest(_Fixture.InjectableManifest, _Cases.SALTS[0]);
467
+ const tmpSecond = tmpMetacontroller.createDistinctManifest(_Fixture.InjectableManifest, _Cases.SALTS[1]);
468
+ const tmpFirstAddresses = new Set(Object.keys(tmpFirst.Descriptors));
469
+ Expect(Object.keys(tmpSecond.Descriptors).filter((pAddress) => tmpFirstAddresses.has(pAddress))).to.deep.equal([]);
470
+ const tmpFirstRecordSets = new Set(tmpFirst.Sections.reduce((pSet, pSection) => pSet.concat((pSection.Groups || []).map((pGroup) => pGroup.RecordSetAddress)), []).filter(Boolean));
471
+ const tmpSecondRecordSets = tmpSecond.Sections.reduce((pSet, pSection) => pSet.concat((pSection.Groups || []).map((pGroup) => pGroup.RecordSetAddress)), []).filter(Boolean);
472
+ Expect(tmpSecondRecordSets.filter((pAddress) => tmpFirstRecordSets.has(pAddress))).to.deep.equal([]);
473
+ });
474
+ });
475
+
476
+ suite('data round trip through two injected copies', () =>
477
+ {
478
+ let _BootedPict = null;
479
+
480
+ /**
481
+ * @param {string} pInputHash
482
+ * @return {{ View: any, Input: any }|null}
483
+ */
484
+ function findInput(pInputHash)
485
+ {
486
+ for (const tmpViewHash of Object.keys(_BootedPict.views))
487
+ {
488
+ const tmpView = _BootedPict.views[tmpViewHash];
489
+ if (!tmpView || !tmpView.isPictSectionForm)
490
+ {
491
+ continue;
492
+ }
493
+ const tmpInput = tmpView.getInputFromHash(pInputHash);
494
+ if (tmpInput)
495
+ {
496
+ return { View: tmpView, Input: tmpInput };
497
+ }
498
+ }
499
+ return null;
500
+ }
501
+
502
+ /**
503
+ * @param {string} pAddress - relative to the marshal destination
504
+ * @return {any}
505
+ */
506
+ function getValue(pAddress)
507
+ {
508
+ return _BootedPict.manifest.getValueAtAddress(_BootedPict.providers.DataBroker.marshalDestinationObject, pAddress);
509
+ }
510
+
511
+ suiteSetup((fDone) =>
512
+ {
513
+ document.body.innerHTML = '<div id="Pict-Form-Container"></div>';
514
+
515
+ class InjectionConformanceApplication extends libPictSectionForm.PictFormApplication
516
+ {
517
+ constructor(pFable, pOptions, pServiceHash)
518
+ {
519
+ super(pFable, pOptions, pServiceHash);
520
+ this.pict.providers.DataBroker.marshalDestination = _Cases.MARSHAL_DESTINATION;
521
+ }
522
+
523
+ set testDone(fTestDone)
524
+ {
525
+ this._testDone = fTestDone;
526
+ }
527
+
528
+ onAfterInitialize()
529
+ {
530
+ this._testDone();
531
+ return true;
532
+ }
533
+ }
534
+ InjectionConformanceApplication.default_configuration = JSON.parse(JSON.stringify(libPictSectionForm.PictFormApplication.default_configuration));
535
+ InjectionConformanceApplication.default_configuration.pict_configuration =
536
+ {
537
+ Product: 'InjectionConformance',
538
+ DefaultAppData: { Orchard: JSON.parse(JSON.stringify(_Cases.ROOT_DECOYS)) },
539
+ DefaultFormManifest: JSON.parse(JSON.stringify(_Fixture.HostManifest)),
540
+ };
541
+
542
+ const tmpPict = new libPict(InjectionConformanceApplication.default_configuration.pict_configuration);
543
+ tmpPict.LogNoisiness = 0;
544
+ tmpPict.addApplication('InjectionConformance', InjectionConformanceApplication.default_configuration, InjectionConformanceApplication);
545
+ tmpPict.PictApplication.testDone = () =>
546
+ {
547
+ try
548
+ {
549
+ _BootedPict = tmpPict;
550
+ const tmpMetacontroller = tmpPict.views.PictFormMetacontroller;
551
+ const tmpMarshalDestinationObject = tmpPict.providers.DataBroker.marshalDestinationObject;
552
+ for (const tmpSalt of _Cases.SALTS)
553
+ {
554
+ const tmpCopy = _Cases.COPIES[tmpSalt];
555
+ tmpMarshalDestinationObject[tmpSalt] = Object.assign(JSON.parse(JSON.stringify(tmpCopy.Seeded)), JSON.parse(JSON.stringify(tmpCopy.Entered)));
556
+ for (const tmpCase of _Cases.INPUT_CASES)
557
+ {
558
+ if ((tmpCase.Tier === 'data') && (tmpCase.Value !== undefined))
559
+ {
560
+ tmpMarshalDestinationObject[tmpSalt][tmpCase.Hash] = tmpCase.Value;
561
+ }
562
+ }
563
+ const tmpSalted = tmpMetacontroller.createDistinctManifest(_Fixture.InjectableManifest, tmpSalt);
564
+ const tmpViews = tmpMetacontroller.injectManifest(tmpSalted);
565
+ for (const tmpView of tmpViews)
566
+ {
567
+ tmpView.render();
568
+ tmpView.marshalToView();
569
+ }
570
+ }
571
+ tmpPict.providers.DynamicSolver.solveViews();
572
+ tmpPict.providers.DynamicSolver.solveViews();
573
+ tmpMetacontroller.marshalToView();
574
+ return fDone();
575
+ }
576
+ catch (pError)
577
+ {
578
+ return fDone(pError);
579
+ }
580
+ };
581
+ tmpPict.PictApplication.initializeAsync(() => { });
582
+ });
583
+
584
+ test('each copy solves from its own data', () =>
585
+ {
586
+ for (const tmpSalt of _Cases.SALTS)
587
+ {
588
+ for (const [ tmpKey, tmpExpected ] of Object.entries(_Cases.COPIES[tmpSalt].Expected))
589
+ {
590
+ const tmpActual = getValue(`${tmpSalt}.${tmpKey}`);
591
+ if (Array.isArray(tmpExpected))
592
+ {
593
+ Expect((tmpActual || []).map((pValue) => Number(pValue)), `${tmpSalt}.${tmpKey}`).to.deep.equal(tmpExpected.map((pValue) => Number(pValue)));
594
+ }
595
+ else if (typeof(tmpExpected) === 'number')
596
+ {
597
+ Expect(Number(tmpActual), `${tmpSalt}.${tmpKey}`).to.equal(tmpExpected);
598
+ }
599
+ else
600
+ {
601
+ Expect(tmpActual, `${tmpSalt}.${tmpKey}`).to.equal(tmpExpected);
602
+ }
603
+ }
604
+ }
605
+ });
606
+
607
+ test('a record set solver uses its own row rather than a same-named input', () =>
608
+ {
609
+ for (const tmpSalt of _Cases.SALTS)
610
+ {
611
+ const tmpLines = (getValue(`${tmpSalt}.Rows`) || []).map((pRow) => Number(pRow.Line));
612
+ Expect(tmpLines, `${tmpSalt} record set lines`).to.deep.equal(_Cases.COPIES[tmpSalt].Lines);
613
+ }
614
+ });
615
+
616
+ test('each copy runs its own validation solvers against its own data', () =>
617
+ {
618
+ for (const tmpSalt of _Cases.SALTS)
619
+ {
620
+ const tmpExpected = Number(getValue(`${tmpSalt}.Area`)) + Number(getValue(`${tmpSalt}.Count`));
621
+ Expect(Number(getValue(`${tmpSalt}.CheckedTotal`)), `${tmpSalt}.CheckedTotal`).to.equal(tmpExpected);
622
+ }
623
+ Expect(getValue('CheckedTotal'), 'unsalted CheckedTotal').to.equal(undefined);
624
+ });
625
+
626
+ test('the form holds each copy\'s validation solvers once', () =>
627
+ {
628
+ const tmpExpressions = (_BootedPict.views.PictFormMetacontroller.manifestDescription.ValidationSolvers || [])
629
+ .map((pSolver) => (typeof(pSolver) === 'string') ? pSolver : pSolver.Expression);
630
+ for (const tmpSalt of _Cases.SALTS)
631
+ {
632
+ const tmpOwnExpressions = tmpExpressions.filter((pExpression) => new RegExp(`\\bCheckedTotal_${tmpSalt}\\b`).test(pExpression));
633
+ Expect(tmpOwnExpressions, `${tmpSalt} validation solvers`).to.have.length(1);
634
+ }
635
+ });
636
+
637
+ test('the unsalted root keeps the values the host put there', () =>
638
+ {
639
+ for (const [ tmpKey, tmpValue ] of Object.entries(_Cases.ROOT_DECOYS))
640
+ {
641
+ Expect(JSON.stringify(getValue(tmpKey)), `unsalted root ${tmpKey}`).to.equal(JSON.stringify(tmpValue));
642
+ }
643
+ });
644
+
645
+ test('an injected copy writes nothing of its own to the unsalted root', () =>
646
+ {
647
+ const tmpUndeclaredTargets = solverExpressions(_Fixture.InjectableManifest)
648
+ .map((pExpression) => /^\s*([A-Za-z0-9_$.[\]]+)\s*\??=/.exec(pExpression))
649
+ .filter(Boolean)
650
+ .map((pMatch) => pMatch[1].split(/[.[]/)[0])
651
+ .filter((pName) => !localNames(_Fixture.InjectableManifest).includes(pName));
652
+ const tmpRootKeys = Object.keys(_BootedPict.providers.DataBroker.marshalDestinationObject)
653
+ .filter((pKey) => !_Cases.SALTS.includes(pKey))
654
+ .filter((pKey) => !(pKey in _Cases.ROOT_DECOYS))
655
+ .filter((pKey) => !(pKey in _Cases.KNOWN_ROOT_KEYS))
656
+ .filter((pKey) => !tmpUndeclaredTargets.includes(pKey));
657
+ Expect(tmpRootKeys, `Keys an injected copy left at the unsalted root, beyond the known ones (${_Cases.KNOWN_OPEN.UndeclaredSolverTargets})`).to.deep.equal([]);
658
+ });
659
+
660
+ test('every data tier input holds the data of its own copy', () =>
661
+ {
662
+ const tmpFindings = [];
663
+ for (const tmpCase of _Cases.INPUT_CASES)
664
+ {
665
+ if ((tmpCase.Tier !== 'data') || !tmpCase.Marshals)
666
+ {
667
+ continue;
668
+ }
669
+ for (const tmpSalt of _Cases.SALTS)
670
+ {
671
+ if (!findInput(`${tmpCase.Hash}_${tmpSalt}`))
672
+ {
673
+ tmpFindings.push(`${tmpCase.Registry}: no input for ${tmpCase.Hash}_${tmpSalt}`);
674
+ continue;
675
+ }
676
+ const tmpValue = getValue(`${tmpSalt}.${tmpCase.Hash}`);
677
+ if (String(tmpValue) !== String(tmpCase.Value))
678
+ {
679
+ tmpFindings.push(`${tmpCase.Registry}: ${tmpSalt}.${tmpCase.Hash} holds ${JSON.stringify(tmpValue)}, expected ${JSON.stringify(tmpCase.Value)}`);
680
+ }
681
+ }
682
+ }
683
+ Expect(tmpFindings).to.deep.equal([]);
684
+ });
685
+
686
+ test('writing through the view lands in its own copy and leaves the sibling copy alone', () =>
687
+ {
688
+ const tmpFindings = [];
689
+ const [ tmpSalt, tmpSiblingSalt ] = _Cases.SALTS;
690
+ for (const tmpCase of _Cases.INPUT_CASES)
691
+ {
692
+ if ((tmpCase.Tier !== 'data') || !tmpCase.Accepts)
693
+ {
694
+ continue;
695
+ }
696
+ const tmpFound = findInput(`${tmpCase.Hash}_${tmpSalt}`);
697
+ if (!tmpFound)
698
+ {
699
+ tmpFindings.push(`${tmpCase.Registry}: no input for ${tmpCase.Hash}_${tmpSalt}`);
700
+ continue;
701
+ }
702
+ const tmpSiblingBefore = getValue(`${tmpSiblingSalt}.${tmpCase.Hash}`);
703
+ const tmpWrittenValue = (typeof(tmpCase.Value) === 'number') ? (tmpCase.Value + 1) : `${tmpCase.Value}-written`;
704
+ tmpFound.View.setDataByInput(tmpFound.Input, tmpWrittenValue);
705
+ if (String(getValue(`${tmpSalt}.${tmpCase.Hash}`)) !== String(tmpWrittenValue))
706
+ {
707
+ tmpFindings.push(`${tmpCase.Registry}: the write did not reach ${tmpSalt}.${tmpCase.Hash} (${JSON.stringify(getValue(`${tmpSalt}.${tmpCase.Hash}`))})`);
708
+ }
709
+ if (String(getValue(`${tmpSiblingSalt}.${tmpCase.Hash}`)) !== String(tmpSiblingBefore))
710
+ {
711
+ tmpFindings.push(`${tmpCase.Registry}: writing to ${tmpSalt} changed ${tmpSiblingSalt}.${tmpCase.Hash}`);
712
+ }
713
+ }
714
+ Expect(tmpFindings).to.deep.equal([]);
715
+ });
716
+
717
+ test('a copy re-rendered from its saved data keeps that data', () =>
718
+ {
719
+ const tmpFindings = [];
720
+ const tmpSalt = _Cases.SALTS[0];
721
+ const tmpBefore = JSON.stringify(_BootedPict.providers.DataBroker.marshalDestinationObject[tmpSalt]);
722
+ for (const tmpViewHash of Object.keys(_BootedPict.views))
723
+ {
724
+ const tmpView = _BootedPict.views[tmpViewHash];
725
+ if (tmpView && tmpView.isPictSectionForm && tmpViewHash.endsWith(`_${tmpSalt}`))
726
+ {
727
+ tmpView.render();
728
+ tmpView.marshalToView();
729
+ }
730
+ }
731
+ const tmpAfter = JSON.stringify(_BootedPict.providers.DataBroker.marshalDestinationObject[tmpSalt]);
732
+ if (tmpBefore !== tmpAfter)
733
+ {
734
+ tmpFindings.push('a re-render changed the data of the copy');
735
+ }
736
+ for (const tmpCase of _Cases.INPUT_CASES)
737
+ {
738
+ if ((tmpCase.Tier !== 'data') || !tmpCase.Marshals)
739
+ {
740
+ continue;
741
+ }
742
+ const tmpValue = getValue(`${tmpSalt}.${tmpCase.Hash}`);
743
+ if ((tmpValue === undefined) || (tmpValue === null))
744
+ {
745
+ tmpFindings.push(`${tmpCase.Registry}: ${tmpSalt}.${tmpCase.Hash} was lost by a re-render`);
746
+ }
747
+ }
748
+ Expect(tmpFindings).to.deep.equal([]);
749
+ });
750
+ });
751
+ });