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.
- package/docs/Injection_Conformance.md +137 -0
- package/docs/_sidebar.md +1 -0
- package/docs/input_providers/012-tab-group-selector.md +3 -1
- package/docs/input_providers/013-tab-section-selector.md +3 -1
- package/package.json +6 -5
- package/source/providers/Pict-Provider-DynamicFormSolverBehaviors.js +73 -5
- package/source/providers/Pict-Provider-DynamicSolver.js +20 -2
- package/source/providers/inputs/Pict-Provider-Input-TabGroupSelector.js +42 -3
- package/source/providers/inputs/Pict-Provider-Input-TabSectionSelector.js +42 -3
- package/source/views/Pict-View-Form-Metacontroller.js +685 -90
- package/test/Pict-Provider-DynamicFormSolverBehaviors-OrdinalScope_tests.js +105 -0
- package/test/Pict-Provider-Input-TabGroupSelector-TabHashValidation_tests.js +178 -0
- package/test/Pict-Provider-Input-TabSectionSelector-TabHashValidation_tests.js +193 -0
- package/test/Pict-View-Form-Metacontroller-DistinctManifest_tests.js +410 -0
- package/test/PictSectionForm-Injection-Conformance_tests.js +751 -0
- package/test/browser/Injection-Conformance-Differential-Scenario.js +346 -0
- package/test/browser/Injection-Conformance-EdgeCase-Scenario.js +168 -0
- package/test/browser/Injection-Conformance-Harness-Driver.js +538 -0
- package/test/browser/Injection-Conformance-Harness-Runner.js +487 -0
- package/test/browser/Injection-Conformance-Reconstitution-Scenario.js +191 -0
- package/test/browser/Injection-Conformance-Standalone-Scenario.js +114 -0
- package/test/fixtures/injection/Injection-Fixture-Cases.js +203 -0
- package/test/fixtures/injection/Injection-Fixture-Manifest.json +366 -0
- package/types/source/providers/Pict-Provider-DynamicFormSolverBehaviors.d.ts +110 -1
- package/types/source/providers/Pict-Provider-DynamicFormSolverBehaviors.d.ts.map +1 -1
- package/types/source/providers/Pict-Provider-DynamicSolver.d.ts.map +1 -1
- package/types/source/providers/Pict-Provider-DynamicTabularData.d.ts +17 -1
- package/types/source/providers/Pict-Provider-DynamicTabularData.d.ts.map +1 -1
- package/types/source/providers/Pict-Provider-InputExtension.d.ts +31 -0
- package/types/source/providers/Pict-Provider-InputExtension.d.ts.map +1 -1
- package/types/source/providers/inputs/Pict-Provider-Input-Chart-CSS.d.ts +16 -0
- package/types/source/providers/inputs/Pict-Provider-Input-Chart-CSS.d.ts.map +1 -0
- package/types/source/providers/inputs/Pict-Provider-Input-Chart.d.ts +47 -0
- package/types/source/providers/inputs/Pict-Provider-Input-Chart.d.ts.map +1 -1
- package/types/source/providers/inputs/Pict-Provider-Input-Diagram.d.ts +86 -0
- package/types/source/providers/inputs/Pict-Provider-Input-Diagram.d.ts.map +1 -1
- package/types/source/providers/inputs/Pict-Provider-Input-ObjectEditor.d.ts +128 -0
- package/types/source/providers/inputs/Pict-Provider-Input-ObjectEditor.d.ts.map +1 -0
- package/types/source/providers/inputs/Pict-Provider-Input-PreciseNumber.d.ts.map +1 -1
- package/types/source/providers/inputs/Pict-Provider-Input-TabGroupSelector.d.ts +10 -1
- package/types/source/providers/inputs/Pict-Provider-Input-TabGroupSelector.d.ts.map +1 -1
- package/types/source/providers/inputs/Pict-Provider-Input-TabSectionSelector.d.ts +10 -1
- package/types/source/providers/inputs/Pict-Provider-Input-TabSectionSelector.d.ts.map +1 -1
- package/types/source/providers/layouts/Pict-Layout-Tabular.d.ts +76 -4
- package/types/source/providers/layouts/Pict-Layout-Tabular.d.ts.map +1 -1
- package/types/source/views/Pict-View-DynamicForm.d.ts.map +1 -1
- package/types/source/views/Pict-View-Form-Metacontroller.d.ts +63 -2
- package/types/source/views/Pict-View-Form-Metacontroller.d.ts.map +1 -1
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Injection conformance, browser tier: the differential scenario.
|
|
3
|
+
|
|
4
|
+
Differential scenario: works for any manifest, no expected values needed. One phase per page load; the
|
|
5
|
+
node runner (Injection-Conformance-Harness-Runner.js runDifferential) compares the phases:
|
|
6
|
+
|
|
7
|
+
host no injection -- the unsalted root as the host leaves it
|
|
8
|
+
pair copy A (seeded numeric data), then copy B (no data)
|
|
9
|
+
solo-a copy A alone, same data
|
|
10
|
+
solo-b copy B alone
|
|
11
|
+
|
|
12
|
+
A copy that reads or writes anything outside its own subtree computes differently next to a sibling than
|
|
13
|
+
alone, or changes the unsalted root.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const NUMERIC_DATA_TYPES = [ 'Number', 'PreciseNumber', 'Integer', 'Float' ];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @param {any} pValue
|
|
20
|
+
* @return {any}
|
|
21
|
+
*/
|
|
22
|
+
function cloneData(pValue)
|
|
23
|
+
{
|
|
24
|
+
return (pValue === undefined) ? undefined : JSON.parse(JSON.stringify(pValue));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Deterministic value in [1, 91) for an address, so every phase seeds identical data.
|
|
29
|
+
*
|
|
30
|
+
* @param {number} pSeed
|
|
31
|
+
* @param {string} pAddress
|
|
32
|
+
* @return {number}
|
|
33
|
+
*/
|
|
34
|
+
function seededValue(pSeed, pAddress)
|
|
35
|
+
{
|
|
36
|
+
let tmpHash = 2166136261 ^ pSeed;
|
|
37
|
+
const tmpText = `${pSeed}:${pAddress}`;
|
|
38
|
+
for (let i = 0; i < tmpText.length; i++)
|
|
39
|
+
{
|
|
40
|
+
tmpHash ^= tmpText.charCodeAt(i);
|
|
41
|
+
tmpHash = Math.imul(tmpHash, 16777619);
|
|
42
|
+
}
|
|
43
|
+
return 1 + ((tmpHash >>> 0) % 9000) / 100;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @param {Record<string, any>} pDescriptor
|
|
48
|
+
* @return {boolean}
|
|
49
|
+
*/
|
|
50
|
+
function isNumericDescriptor(pDescriptor)
|
|
51
|
+
{
|
|
52
|
+
return Boolean(pDescriptor) && NUMERIC_DATA_TYPES.includes(pDescriptor.DataType);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Seed data for a manifest: every rendered numeric input and `RowCount` rows for each record set group.
|
|
57
|
+
*
|
|
58
|
+
* @param {Record<string, any>} pManifest
|
|
59
|
+
* @param {{ Seed?: number, RowCount?: number }} pFill
|
|
60
|
+
* @return {Record<string, any>} address (unsalted) -> value
|
|
61
|
+
*/
|
|
62
|
+
function buildFill(pManifest, pFill)
|
|
63
|
+
{
|
|
64
|
+
const tmpSeed = (pFill && typeof pFill.Seed === 'number') ? pFill.Seed : 1;
|
|
65
|
+
const tmpRowCount = (pFill && typeof pFill.RowCount === 'number') ? pFill.RowCount : 3;
|
|
66
|
+
const tmpValues = {};
|
|
67
|
+
for (const [ tmpKey, tmpDescriptor ] of Object.entries(pManifest.Descriptors || {}))
|
|
68
|
+
{
|
|
69
|
+
if (!tmpDescriptor || !tmpDescriptor.PictForm || !tmpDescriptor.PictForm.Section || !isNumericDescriptor(tmpDescriptor))
|
|
70
|
+
{
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const tmpAddress = tmpDescriptor.DataAddress || tmpKey;
|
|
74
|
+
tmpValues[tmpAddress] = seededValue(tmpSeed, tmpAddress);
|
|
75
|
+
}
|
|
76
|
+
for (const tmpSection of pManifest.Sections || [])
|
|
77
|
+
{
|
|
78
|
+
for (const tmpGroup of tmpSection.Groups || [])
|
|
79
|
+
{
|
|
80
|
+
const tmpRowManifest = (pManifest.ReferenceManifests || {})[tmpGroup.RecordManifest];
|
|
81
|
+
if (!tmpGroup.RecordSetAddress || !tmpRowManifest)
|
|
82
|
+
{
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const tmpRows = [];
|
|
86
|
+
for (let r = 0; r < tmpRowCount; r++)
|
|
87
|
+
{
|
|
88
|
+
const tmpRow = {};
|
|
89
|
+
for (const [ tmpColumnKey, tmpColumn ] of Object.entries(tmpRowManifest.Descriptors || {}))
|
|
90
|
+
{
|
|
91
|
+
if (isNumericDescriptor(tmpColumn))
|
|
92
|
+
{
|
|
93
|
+
const tmpColumnAddress = tmpColumn.DataAddress || tmpColumnKey;
|
|
94
|
+
setPath(tmpRow, tmpColumnAddress, seededValue(tmpSeed, `${tmpGroup.RecordSetAddress}[${r}].${tmpColumnAddress}`));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
tmpRows.push(tmpRow);
|
|
98
|
+
}
|
|
99
|
+
tmpValues[tmpGroup.RecordSetAddress] = tmpRows;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return tmpValues;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Sets a dotted path (no array segments) on a plain object.
|
|
107
|
+
*
|
|
108
|
+
* @param {Record<string, any>} pObject
|
|
109
|
+
* @param {string} pPath
|
|
110
|
+
* @param {any} pValue
|
|
111
|
+
*/
|
|
112
|
+
function setPath(pObject, pPath, pValue)
|
|
113
|
+
{
|
|
114
|
+
const tmpParts = pPath.split('.');
|
|
115
|
+
let tmpCursor = pObject;
|
|
116
|
+
for (let i = 0; i < tmpParts.length - 1; i++)
|
|
117
|
+
{
|
|
118
|
+
if ((typeof tmpCursor[tmpParts[i]] !== 'object') || (tmpCursor[tmpParts[i]] === null))
|
|
119
|
+
{
|
|
120
|
+
tmpCursor[tmpParts[i]] = {};
|
|
121
|
+
}
|
|
122
|
+
tmpCursor = tmpCursor[tmpParts[i]];
|
|
123
|
+
}
|
|
124
|
+
tmpCursor[tmpParts[tmpParts.length - 1]] = pValue;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Section solver assignment targets that no descriptor (or record set address) covers. Solvers write these
|
|
129
|
+
* straight into the marshal destination under their unsalted name.
|
|
130
|
+
*
|
|
131
|
+
* @param {any} pExpressionParser
|
|
132
|
+
* @param {Record<string, any>} pManifest
|
|
133
|
+
* @return {Array<string>} the uncovered top-level names
|
|
134
|
+
*/
|
|
135
|
+
function findUndeclaredSolverTargets(pExpressionParser, pManifest)
|
|
136
|
+
{
|
|
137
|
+
const tmpKnown = new Set();
|
|
138
|
+
for (const [ tmpKey, tmpDescriptor ] of Object.entries(pManifest.Descriptors || {}))
|
|
139
|
+
{
|
|
140
|
+
tmpKnown.add(tmpDescriptor.DataAddress || tmpKey);
|
|
141
|
+
if (tmpDescriptor.Hash)
|
|
142
|
+
{
|
|
143
|
+
tmpKnown.add(tmpDescriptor.Hash);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
for (const tmpSection of pManifest.Sections || [])
|
|
147
|
+
{
|
|
148
|
+
for (const tmpGroup of tmpSection.Groups || [])
|
|
149
|
+
{
|
|
150
|
+
if (tmpGroup.RecordSetAddress)
|
|
151
|
+
{
|
|
152
|
+
tmpKnown.add(tmpGroup.RecordSetAddress);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const isCovered = (pTarget) =>
|
|
157
|
+
{
|
|
158
|
+
if (tmpKnown.has(pTarget))
|
|
159
|
+
{
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
for (let i = pTarget.length - 1; i > 0; i--)
|
|
163
|
+
{
|
|
164
|
+
if (((pTarget[i] === '.') || (pTarget[i] === '[')) && tmpKnown.has(pTarget.substring(0, i)))
|
|
165
|
+
{
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return false;
|
|
170
|
+
};
|
|
171
|
+
const tmpUndeclared = new Set();
|
|
172
|
+
for (const tmpSection of pManifest.Sections || [])
|
|
173
|
+
{
|
|
174
|
+
for (const tmpSolver of tmpSection.Solvers || [])
|
|
175
|
+
{
|
|
176
|
+
const tmpExpression = (typeof tmpSolver === 'string') ? tmpSolver : (tmpSolver && tmpSolver.Expression);
|
|
177
|
+
if (typeof tmpExpression !== 'string')
|
|
178
|
+
{
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const tmpResult = {};
|
|
182
|
+
try
|
|
183
|
+
{
|
|
184
|
+
pExpressionParser.tokenize(tmpExpression, tmpResult);
|
|
185
|
+
}
|
|
186
|
+
catch (pError)
|
|
187
|
+
{
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
const tmpTokens = tmpResult.OriginalRawTokens || [];
|
|
191
|
+
if ((tmpTokens.length > 1) && ((tmpTokens[1] === '=') || (tmpTokens[1] === '?=')) && !isCovered(tmpTokens[0]))
|
|
192
|
+
{
|
|
193
|
+
tmpUndeclared.add(tmpTokens[0].split(/[.[]/)[0]);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return Array.from(tmpUndeclared);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* @param {import('./Injection-Conformance-Harness-Driver.js').HarnessContext} pContext
|
|
202
|
+
* @param {Record<string, any>} pSalted - the manifest as injected
|
|
203
|
+
* @param {string} pSalt
|
|
204
|
+
*/
|
|
205
|
+
function checkInjectedManifest(pContext, pSalted, pSalt)
|
|
206
|
+
{
|
|
207
|
+
for (const [ tmpKey, tmpDescriptor ] of Object.entries(pSalted.Descriptors || {}))
|
|
208
|
+
{
|
|
209
|
+
const tmpPictForm = tmpDescriptor.PictForm || {};
|
|
210
|
+
if (Array.isArray(tmpPictForm.TabSectionSet))
|
|
211
|
+
{
|
|
212
|
+
const tmpMissing = tmpPictForm.TabSectionSet.filter((pHash) => !pContext.getSectionView(pHash));
|
|
213
|
+
pContext.check(`${pSalt}: ${tmpKey} TabSectionSet names rendered sections`, tmpMissing.length === 0, tmpMissing);
|
|
214
|
+
}
|
|
215
|
+
if (Array.isArray(tmpPictForm.TabGroupSet))
|
|
216
|
+
{
|
|
217
|
+
const tmpView = pContext.getSectionView(tmpPictForm.Section);
|
|
218
|
+
const tmpGroups = (tmpView && tmpView.sectionDefinition && Array.isArray(tmpView.sectionDefinition.Groups)) ? tmpView.sectionDefinition.Groups.map((pGroup) => pGroup.Hash) : [];
|
|
219
|
+
const tmpMissing = tmpPictForm.TabGroupSet.filter((pHash) => !tmpGroups.includes(pHash));
|
|
220
|
+
pContext.check(`${pSalt}: ${tmpKey} TabGroupSet names groups of its section`, tmpMissing.length === 0, tmpMissing);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* @param {import('./Injection-Conformance-Harness-Driver.js').HarnessContext} pContext
|
|
227
|
+
* @param {Record<string, any>} pOriginal
|
|
228
|
+
* @param {Record<string, any>} pSalted
|
|
229
|
+
* @param {string} pSalt
|
|
230
|
+
* @return {Record<string, any>}
|
|
231
|
+
*/
|
|
232
|
+
function snapshotCopy(pContext, pOriginal, pSalted, pSalt)
|
|
233
|
+
{
|
|
234
|
+
const tmpHidden = {};
|
|
235
|
+
for (const tmpSection of pOriginal.Sections || [])
|
|
236
|
+
{
|
|
237
|
+
tmpHidden[tmpSection.Hash] = pContext.isSectionHidden(`${tmpSection.Hash}_${pSalt}`);
|
|
238
|
+
for (const tmpGroup of tmpSection.Groups || [])
|
|
239
|
+
{
|
|
240
|
+
tmpHidden[`${tmpSection.Hash}/${tmpGroup.Hash}`] = pContext.isGroupHidden(`${tmpSection.Hash}_${pSalt}`, `${tmpGroup.Hash}_${pSalt}`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
const tmpCharts = {};
|
|
244
|
+
for (const [ tmpKey, tmpDescriptor ] of Object.entries(pSalted.Descriptors || {}))
|
|
245
|
+
{
|
|
246
|
+
if (tmpDescriptor.PictForm && (tmpDescriptor.PictForm.InputType === 'Chart'))
|
|
247
|
+
{
|
|
248
|
+
tmpCharts[tmpDescriptor.OriginalHash || tmpDescriptor.OriginalDataAddress || tmpKey] = pContext.getChartData(tmpDescriptor.Hash || tmpKey);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return { Data: cloneData(pContext.marshalDestinationObject[pSalt]), Hidden: tmpHidden, Charts: tmpCharts };
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* @param {import('./Injection-Conformance-Harness-Driver.js').HarnessContext} pContext
|
|
256
|
+
* @return {Promise<void>}
|
|
257
|
+
*/
|
|
258
|
+
async function run(pContext)
|
|
259
|
+
{
|
|
260
|
+
const tmpConfig = pContext.config;
|
|
261
|
+
const [ tmpSaltA, tmpSaltB ] = tmpConfig.Salts;
|
|
262
|
+
await pContext.boot({ HostManifest: tmpConfig.HostManifest, MarshalDestination: tmpConfig.MarshalDestination, InitialAppData: tmpConfig.InitialAppData });
|
|
263
|
+
|
|
264
|
+
const tmpParser = pContext.pict.instantiateServiceProviderIfNotExists('ExpressionParser');
|
|
265
|
+
// Each salt can carry a manifest of its own, so two different manifests can be injected side by side the
|
|
266
|
+
// way a host form holds several; one manifest for every salt is the same-manifest case.
|
|
267
|
+
const tmpManifests = {};
|
|
268
|
+
const tmpFills = {};
|
|
269
|
+
const tmpUndeclaredBySalt = {};
|
|
270
|
+
for (let i = 0; i < tmpConfig.Salts.length; i++)
|
|
271
|
+
{
|
|
272
|
+
const tmpSalt = tmpConfig.Salts[i];
|
|
273
|
+
let tmpSaltManifest = Array.isArray(tmpConfig.Manifests) ? tmpConfig.Manifests[i] : tmpConfig.Manifest;
|
|
274
|
+
const tmpUndeclaredForSalt = findUndeclaredSolverTargets(tmpParser, tmpSaltManifest);
|
|
275
|
+
tmpUndeclaredBySalt[tmpSalt] = tmpUndeclaredForSalt;
|
|
276
|
+
if (tmpConfig.DeclareUndeclaredSolverTargets)
|
|
277
|
+
{
|
|
278
|
+
tmpSaltManifest = cloneData(tmpSaltManifest);
|
|
279
|
+
for (const tmpTarget of tmpUndeclaredForSalt)
|
|
280
|
+
{
|
|
281
|
+
tmpSaltManifest.Descriptors[tmpTarget] = { Name: tmpTarget, Hash: tmpTarget, DataAddress: tmpTarget };
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
tmpManifests[tmpSalt] = tmpSaltManifest;
|
|
285
|
+
tmpFills[tmpSalt] = buildFill(tmpSaltManifest, tmpConfig.Fill || {});
|
|
286
|
+
}
|
|
287
|
+
const tmpManifest = tmpManifests[tmpConfig.Salts[0]];
|
|
288
|
+
const tmpUndeclared = [];
|
|
289
|
+
for (const tmpSaltTargets of Object.values(tmpUndeclaredBySalt))
|
|
290
|
+
{
|
|
291
|
+
for (const tmpTarget of tmpSaltTargets)
|
|
292
|
+
{
|
|
293
|
+
if (!tmpUndeclared.includes(tmpTarget))
|
|
294
|
+
{
|
|
295
|
+
tmpUndeclared.push(tmpTarget);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
pContext.info.UndeclaredSolverTargets = tmpUndeclared;
|
|
300
|
+
const tmpFill = tmpFills[tmpSaltA];
|
|
301
|
+
pContext.info.FilledAddresses = Object.keys(tmpFill).length;
|
|
302
|
+
const tmpInjections = { 'host': [], 'pair': [ tmpSaltA, tmpSaltB ], 'solo-a': [ tmpSaltA ], 'solo-b': [ tmpSaltB ] }[tmpConfig.Phase];
|
|
303
|
+
if (!tmpInjections)
|
|
304
|
+
{
|
|
305
|
+
throw new Error(`Unknown differential phase [${tmpConfig.Phase}].`);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const tmpMarshal = pContext.marshalDestinationObject;
|
|
309
|
+
const tmpCopies = {};
|
|
310
|
+
for (const tmpSalt of tmpInjections)
|
|
311
|
+
{
|
|
312
|
+
if (tmpSalt === tmpSaltA)
|
|
313
|
+
{
|
|
314
|
+
tmpMarshal[tmpSalt] = tmpMarshal[tmpSalt] || {};
|
|
315
|
+
for (const [ tmpAddress, tmpValue ] of Object.entries(tmpFill))
|
|
316
|
+
{
|
|
317
|
+
pContext.pict.manifest.setValueAtAddress(tmpMarshal[tmpSalt], tmpAddress, cloneData(tmpValue));
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
const tmpInjection = await pContext.inject(tmpManifests[tmpSalt], tmpSalt);
|
|
321
|
+
tmpCopies[tmpSalt] = tmpInjection.Salted;
|
|
322
|
+
if (tmpConfig.Phase === 'pair')
|
|
323
|
+
{
|
|
324
|
+
checkInjectedManifest(pContext, tmpInjection.Salted, tmpSalt);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
await pContext.solve();
|
|
328
|
+
await pContext.solve();
|
|
329
|
+
|
|
330
|
+
const tmpRoot = {};
|
|
331
|
+
for (const [ tmpKey, tmpValue ] of Object.entries(tmpMarshal))
|
|
332
|
+
{
|
|
333
|
+
if ((tmpKey !== tmpSaltA) && (tmpKey !== tmpSaltB))
|
|
334
|
+
{
|
|
335
|
+
tmpRoot[tmpKey] = cloneData(tmpValue);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
const tmpSnapshot = { Root: tmpRoot, Copies: {} };
|
|
339
|
+
for (const tmpSalt of tmpInjections)
|
|
340
|
+
{
|
|
341
|
+
tmpSnapshot.Copies[tmpSalt] = snapshotCopy(pContext, tmpManifests[tmpSalt], tmpCopies[tmpSalt], tmpSalt);
|
|
342
|
+
}
|
|
343
|
+
pContext.snapshots.Differential = tmpSnapshot;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
module.exports = { run: run, buildFill: buildFill, findUndeclaredSolverTargets: findUndeclaredSolverTargets, seededValue: seededValue };
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Injection conformance, browser tier: the edge case scenario.
|
|
3
|
+
|
|
4
|
+
Two salted copies of the fixture manifest in one page, next to a host form that already holds same-named
|
|
5
|
+
data at the unsalted root. Each copy must compute from, show, hide, chart and render only its own data,
|
|
6
|
+
including after it is re-rendered from what was saved.
|
|
7
|
+
|
|
8
|
+
The fixture, the data each copy is given and what each copy should end up holding all come from
|
|
9
|
+
test/fixtures/injection/Injection-Fixture-Cases.js, which the DOM tier reads too.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const _Fixture = require('../fixtures/injection/Injection-Fixture-Manifest.json');
|
|
13
|
+
const _Cases = require('../fixtures/injection/Injection-Fixture-Cases.js');
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {any} pValue
|
|
17
|
+
* @return {any}
|
|
18
|
+
*/
|
|
19
|
+
function cloneData(pValue)
|
|
20
|
+
{
|
|
21
|
+
return (pValue === undefined) ? undefined : JSON.parse(JSON.stringify(pValue));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {Record<string, any>} pMarshalDestinationObject
|
|
26
|
+
* @return {Record<string, any>} the marshal destination without the salted copies
|
|
27
|
+
*/
|
|
28
|
+
function rootWithoutCopies(pMarshalDestinationObject)
|
|
29
|
+
{
|
|
30
|
+
const tmpRoot = {};
|
|
31
|
+
for (const [ tmpKey, tmpValue ] of Object.entries(pMarshalDestinationObject))
|
|
32
|
+
{
|
|
33
|
+
if (!_Cases.SALTS.includes(tmpKey))
|
|
34
|
+
{
|
|
35
|
+
tmpRoot[tmpKey] = cloneData(tmpValue);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return tmpRoot;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {import('./Injection-Conformance-Harness-Driver.js').HarnessContext} pContext
|
|
43
|
+
* @return {Promise<void>}
|
|
44
|
+
*/
|
|
45
|
+
async function run(pContext)
|
|
46
|
+
{
|
|
47
|
+
await pContext.boot({ HostManifest: _Fixture.HostManifest, MarshalDestination: _Cases.MARSHAL_DESTINATION, InitialAppData: { Orchard: cloneData(_Cases.ROOT_DECOYS) } });
|
|
48
|
+
const tmpMarshalDestinationObject = pContext.marshalDestinationObject;
|
|
49
|
+
const tmpRootBefore = rootWithoutCopies(tmpMarshalDestinationObject);
|
|
50
|
+
pContext.checkEqual('host: boots with its own Width at the unsalted root', pContext.getValue('Width'), 1000);
|
|
51
|
+
|
|
52
|
+
for (const tmpSalt of _Cases.SALTS)
|
|
53
|
+
{
|
|
54
|
+
const tmpCopy = _Cases.COPIES[tmpSalt];
|
|
55
|
+
// Seeded before injection, the way a form is opened on data that was saved earlier.
|
|
56
|
+
tmpMarshalDestinationObject[tmpSalt] = cloneData(tmpCopy.Seeded);
|
|
57
|
+
const tmpInjection = await pContext.inject(_Fixture.InjectableManifest, tmpSalt);
|
|
58
|
+
pContext.check(`${tmpSalt}: every section of the manifest rendered`, tmpInjection.Views.length === _Fixture.InjectableManifest.Sections.length, tmpInjection.Views.map((pView) => pView.Hash));
|
|
59
|
+
}
|
|
60
|
+
for (const tmpSalt of _Cases.SALTS)
|
|
61
|
+
{
|
|
62
|
+
for (const [ tmpHash, tmpValue ] of Object.entries(_Cases.COPIES[tmpSalt].Entered))
|
|
63
|
+
{
|
|
64
|
+
pContext.check(`${tmpSalt}: typed ${tmpHash} into its own input`, pContext.enterValue(`${tmpHash}_${tmpSalt}`, tmpValue), `no element for ${tmpHash}_${tmpSalt}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
await pContext.solve();
|
|
68
|
+
await pContext.solve();
|
|
69
|
+
|
|
70
|
+
for (const tmpSalt of _Cases.SALTS)
|
|
71
|
+
{
|
|
72
|
+
const tmpCopy = _Cases.COPIES[tmpSalt];
|
|
73
|
+
for (const [ tmpKey, tmpExpected ] of Object.entries(tmpCopy.Expected))
|
|
74
|
+
{
|
|
75
|
+
pContext.checkEqual(`${tmpSalt}: ${tmpKey}`, pContext.getValue(`${tmpSalt}.${tmpKey}`), tmpExpected);
|
|
76
|
+
}
|
|
77
|
+
pContext.checkEqual(`${tmpSalt}: a record set solver uses its own row rather than the same-named input`, (pContext.getValue(`${tmpSalt}.Rows`) || []).map((pRow) => pRow.Line), tmpCopy.Lines);
|
|
78
|
+
pContext.checkEqual(`${tmpSalt}: FromScratch reads its own undeclared solver target`, pContext.getValue(`${tmpSalt}.FromScratch`), tmpCopy.FromScratch, 'open');
|
|
79
|
+
pContext.checkEqual(`${tmpSalt}: an injected manifest's ValidationSolvers run against its own data`, pContext.getValue(`${tmpSalt}.CheckedTotal`), Number(pContext.getValue(`${tmpSalt}.Area`)) + Number(pContext.getValue(`${tmpSalt}.Count`)));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Section visibility driven by a solver
|
|
83
|
+
for (const tmpSalt of _Cases.SALTS)
|
|
84
|
+
{
|
|
85
|
+
pContext.checkEqual(`${tmpSalt}: SetSectionVisibility acts on its own Extras section`, pContext.isSectionHidden(`Extras_${tmpSalt}`), _Cases.COPIES[tmpSalt].ExtrasHidden);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Tab section and tab group selectors: defaults, then a switch in one copy only
|
|
89
|
+
for (const tmpSalt of _Cases.SALTS)
|
|
90
|
+
{
|
|
91
|
+
pContext.checkEqual(`${tmpSalt}: the default tab shows its own TabTwo`, pContext.isSectionHidden(`TabTwo_${tmpSalt}`), false);
|
|
92
|
+
pContext.checkEqual(`${tmpSalt}: the default tab hides its own TabOne`, pContext.isSectionHidden(`TabOne_${tmpSalt}`), true);
|
|
93
|
+
pContext.checkEqual(`${tmpSalt}: the default group tab shows its own GroupB`, pContext.isGroupHidden(`Grouped_${tmpSalt}`, `GroupB_${tmpSalt}`), false);
|
|
94
|
+
pContext.checkEqual(`${tmpSalt}: the default group tab hides its own GroupA`, pContext.isGroupHidden(`Grouped_${tmpSalt}`, `GroupA_${tmpSalt}`), true);
|
|
95
|
+
}
|
|
96
|
+
const [ tmpFirstSalt, tmpSecondSalt ] = _Cases.SALTS;
|
|
97
|
+
pContext.check(`${tmpFirstSalt}: its TabOne tab is in the DOM`, pContext.clickTab(`TabPicker_${tmpFirstSalt}`, `TabOne_${tmpFirstSalt}`));
|
|
98
|
+
pContext.check(`${tmpFirstSalt}: its GroupA tab is in the DOM`, pContext.clickTab(`GroupPicker_${tmpFirstSalt}`, `GroupA_${tmpFirstSalt}`));
|
|
99
|
+
await pContext.wait(20);
|
|
100
|
+
pContext.checkEqual(`${tmpFirstSalt}: switching tabs shows its own TabOne`, pContext.isSectionHidden(`TabOne_${tmpFirstSalt}`), false);
|
|
101
|
+
pContext.checkEqual(`${tmpFirstSalt}: switching tabs hides its own TabTwo`, pContext.isSectionHidden(`TabTwo_${tmpFirstSalt}`), true);
|
|
102
|
+
pContext.checkEqual(`${tmpFirstSalt}: the tab selector stores its own section hash`, pContext.getValue(`${tmpFirstSalt}.TabPicker`), `TabOne_${tmpFirstSalt}`);
|
|
103
|
+
pContext.checkEqual(`${tmpSecondSalt}: its TabOne stays hidden when the other copy switches tabs`, pContext.isSectionHidden(`TabOne_${tmpSecondSalt}`), true);
|
|
104
|
+
pContext.checkEqual(`${tmpSecondSalt}: its TabTwo stays shown when the other copy switches tabs`, pContext.isSectionHidden(`TabTwo_${tmpSecondSalt}`), false);
|
|
105
|
+
pContext.checkEqual(`${tmpFirstSalt}: switching group tabs shows its own GroupA`, pContext.isGroupHidden(`Grouped_${tmpFirstSalt}`, `GroupA_${tmpFirstSalt}`), false);
|
|
106
|
+
pContext.checkEqual(`${tmpFirstSalt}: switching group tabs hides its own GroupB`, pContext.isGroupHidden(`Grouped_${tmpFirstSalt}`, `GroupB_${tmpFirstSalt}`), true);
|
|
107
|
+
pContext.checkEqual(`${tmpSecondSalt}: its GroupA stays hidden when the other copy switches group tabs`, pContext.isGroupHidden(`Grouped_${tmpSecondSalt}`, `GroupA_${tmpSecondSalt}`), true);
|
|
108
|
+
pContext.checkEqual(`${tmpSecondSalt}: its GroupB stays shown when the other copy switches group tabs`, pContext.isGroupHidden(`Grouped_${tmpSecondSalt}`, `GroupB_${tmpSecondSalt}`), false);
|
|
109
|
+
|
|
110
|
+
// Charts
|
|
111
|
+
for (const tmpSalt of _Cases.SALTS)
|
|
112
|
+
{
|
|
113
|
+
const tmpChart = pContext.getChartData(`LineChart_${tmpSalt}`);
|
|
114
|
+
if (pContext.check(`${tmpSalt}: its chart rendered`, tmpChart !== null))
|
|
115
|
+
{
|
|
116
|
+
const tmpExpected = _Cases.COPIES[tmpSalt].Chart;
|
|
117
|
+
pContext.checkEqual(`${tmpSalt}: chart labels come from its own rows`, tmpChart.Labels, tmpExpected.Labels);
|
|
118
|
+
pContext.checkEqual(`${tmpSalt}: the first chart dataset comes from its own rows`, (tmpChart.Datasets[0] || {}).Data, tmpExpected.Line);
|
|
119
|
+
pContext.checkEqual(`${tmpSalt}: the second chart dataset comes from its own solved values`, (tmpChart.Datasets[1] || {}).Data, tmpExpected.Scaled);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// A templated input renders its template when the section renders, so this is the read-back-from-saved
|
|
124
|
+
// -data path: re-render the copy and the template has to show that copy's values.
|
|
125
|
+
for (const tmpSalt of _Cases.SALTS)
|
|
126
|
+
{
|
|
127
|
+
pContext.rerenderSection(`Composed_${tmpSalt}`);
|
|
128
|
+
}
|
|
129
|
+
await pContext.wait(20);
|
|
130
|
+
for (const tmpSalt of _Cases.SALTS)
|
|
131
|
+
{
|
|
132
|
+
const tmpSummary = pContext.querySection(`Composed_${tmpSalt}`, '.crate-summary');
|
|
133
|
+
pContext.checkEqual(`${tmpSalt}: its templated input re-renders from its own saved data`, tmpSummary ? tmpSummary.textContent.trim() : null, _Cases.COPIES[tmpSalt].Summary);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// A trigger group, driven by a real change event in one copy only
|
|
137
|
+
const tmpSiblingEchoBefore = pContext.getValue(`${tmpSecondSalt}.Echo`);
|
|
138
|
+
const tmpSiblingMirrorBefore = pContext.getValue(`${tmpSecondSalt}.Mirror`);
|
|
139
|
+
pContext.check(`${tmpFirstSalt}: typed Source into its own input`, pContext.enterValue(`Source_${tmpFirstSalt}`, 6));
|
|
140
|
+
await pContext.wait(100);
|
|
141
|
+
pContext.checkEqual(`${tmpFirstSalt}: its trigger group PostSolvers write Echo inside its own copy`, pContext.getValue(`${tmpFirstSalt}.Echo`), 60);
|
|
142
|
+
pContext.checkEqual(`${tmpFirstSalt}: its trigger group PreSolvers run inside its own copy`, pContext.getValue(`${tmpFirstSalt}.EchoStamp`), 6);
|
|
143
|
+
pContext.checkEqual(`${tmpFirstSalt}: its TriggerAddress autofills Mirror from its own Source`, pContext.getValue(`${tmpFirstSalt}.Mirror`), 6);
|
|
144
|
+
const tmpEchoElement = pContext.getInputElement(`Echo_${tmpFirstSalt}`);
|
|
145
|
+
pContext.checkEqual(`${tmpFirstSalt}: MarshalOnComplete re-marshals its own section`, tmpEchoElement ? tmpEchoElement.value : null, 60);
|
|
146
|
+
const tmpSiblingMirror = pContext.getValue(`${tmpSecondSalt}.Mirror`);
|
|
147
|
+
pContext.check(`${tmpSecondSalt}: Mirror is only ever autofilled from its own Source`, (tmpSiblingMirror == null) || (tmpSiblingMirror === '') || (Number(tmpSiblingMirror) === Number(tmpSiblingMirrorBefore)) || (Number(tmpSiblingMirror) === 2), { Actual: tmpSiblingMirror, Before: tmpSiblingMirrorBefore });
|
|
148
|
+
const tmpSiblingEcho = pContext.getValue(`${tmpSecondSalt}.Echo`);
|
|
149
|
+
pContext.check(`${tmpSecondSalt}: Echo is only ever computed from its own Source`, (tmpSiblingEcho == null) || (tmpSiblingEcho === '') || (Number(tmpSiblingEcho) === Number(tmpSiblingEchoBefore)) || (Number(tmpSiblingEcho) === 20), { Actual: tmpSiblingEcho, Before: tmpSiblingEchoBefore });
|
|
150
|
+
// The trigger group hash carries the copy's salt, so a change in one copy cannot run the other's group.
|
|
151
|
+
pContext.check(`${tmpSecondSalt}: its trigger group does not run when the other copy changes`, String(tmpSiblingEcho) === String(tmpSiblingEchoBefore), { Actual: tmpSiblingEcho, Before: tmpSiblingEchoBefore });
|
|
152
|
+
|
|
153
|
+
// The unsalted root
|
|
154
|
+
const tmpRootAfter = rootWithoutCopies(tmpMarshalDestinationObject);
|
|
155
|
+
for (const [ tmpKey, tmpValue ] of Object.entries(tmpRootBefore))
|
|
156
|
+
{
|
|
157
|
+
pContext.check(`unsalted root: ${tmpKey} is unchanged`, JSON.stringify(tmpRootAfter[tmpKey]) === JSON.stringify(tmpValue), { Before: tmpValue, After: tmpRootAfter[tmpKey] });
|
|
158
|
+
}
|
|
159
|
+
const tmpNewKeys = Object.keys(tmpRootAfter).filter((pKey) => !(pKey in tmpRootBefore));
|
|
160
|
+
const tmpUndeclaredKeys = tmpNewKeys.filter((pKey) => (pKey in _Cases.KNOWN_ROOT_KEYS) && (_Cases.KNOWN_ROOT_KEYS[pKey].Severity === 'open'));
|
|
161
|
+
const tmpBenignKeys = tmpNewKeys.filter((pKey) => (pKey in _Cases.KNOWN_ROOT_KEYS) && (_Cases.KNOWN_ROOT_KEYS[pKey].Severity === 'benign'));
|
|
162
|
+
const tmpUnexpectedKeys = tmpNewKeys.filter((pKey) => !(pKey in _Cases.KNOWN_ROOT_KEYS) && (pKey !== 'Scratch'));
|
|
163
|
+
pContext.check('unsalted root: an injected copy adds no keys of its own', tmpUnexpectedKeys.length === 0, tmpUnexpectedKeys.map((pKey) => `${pKey}=${JSON.stringify(tmpRootAfter[pKey])}`));
|
|
164
|
+
pContext.check('unsalted root: an undeclared solver target stays inside its copy', (tmpUndeclaredKeys.length === 0) && !tmpNewKeys.includes('Scratch'), { Keys: tmpUndeclaredKeys.concat(tmpNewKeys.includes('Scratch') ? [ 'Scratch' ] : []), Reason: _Cases.KNOWN_OPEN.UndeclaredSolverTargets }, 'open');
|
|
165
|
+
pContext.info.BenignRootKeys = tmpBenignKeys;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
module.exports = { run: run };
|