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,410 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Unit tests for PictFormMetacontroller.createDistinctManifest / rewriteSolverExpression.
|
|
3
|
+
|
|
4
|
+
Injecting the same manifest more than once salts its hashes and nests its addresses, so every reference
|
|
5
|
+
the manifest makes to itself has to be translated too -- and every reference it makes to something
|
|
6
|
+
outside itself has to be left alone. Exercised against a stub `this` so no form has to be mounted.
|
|
7
|
+
|
|
8
|
+
Expressions are compared as token lists so the tests do not depend on recomposition spacing.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// This is temporary, but enables unit tests
|
|
12
|
+
const libBrowserEnv = require('browser-env');
|
|
13
|
+
libBrowserEnv();
|
|
14
|
+
|
|
15
|
+
const Chai = require('chai');
|
|
16
|
+
const Expect = Chai.expect;
|
|
17
|
+
|
|
18
|
+
const libPict = require('pict');
|
|
19
|
+
|
|
20
|
+
const libMetacontroller = require('../source/views/Pict-View-Form-Metacontroller.js');
|
|
21
|
+
const libDynamicFormSolverBehaviors = require('../source/providers/Pict-Provider-DynamicFormSolverBehaviors.js');
|
|
22
|
+
|
|
23
|
+
const _EdgeCaseManifests = require('./fixtures/injection/Injection-Fixture-Manifest.json');
|
|
24
|
+
|
|
25
|
+
const SALT = 's';
|
|
26
|
+
const MARSHAL_DESTINATION = 'AppData.Orchard';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A metacontroller with just enough wiring for manifest salting.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} [pMarshalDestination]
|
|
32
|
+
* @return {any}
|
|
33
|
+
*/
|
|
34
|
+
function buildMetacontroller(pMarshalDestination)
|
|
35
|
+
{
|
|
36
|
+
const tmpPict = new libPict({ Product: 'DistinctManifestTests', LogStreams: [ { streamtype: 'console', level: 'fatal' } ] });
|
|
37
|
+
tmpPict.addProvider('DynamicFormSolverBehaviors', {}, libDynamicFormSolverBehaviors);
|
|
38
|
+
const tmpExpressionParser = tmpPict.instantiateServiceProviderIfNotExists('ExpressionParser');
|
|
39
|
+
tmpPict.providers.DynamicFormSolverBehaviors.injectBehaviors(tmpExpressionParser);
|
|
40
|
+
tmpPict.providers.DataBroker.marshalDestination = pMarshalDestination || 'AppData';
|
|
41
|
+
|
|
42
|
+
const tmpMetacontroller = Object.create(libMetacontroller.prototype);
|
|
43
|
+
tmpMetacontroller.pict = tmpPict;
|
|
44
|
+
tmpMetacontroller.fable = tmpPict;
|
|
45
|
+
tmpMetacontroller.log = tmpPict.log;
|
|
46
|
+
tmpMetacontroller.options = {};
|
|
47
|
+
return tmpMetacontroller;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param {any} pMetacontroller
|
|
52
|
+
* @param {string} pExpression
|
|
53
|
+
* @return {Array<string>}
|
|
54
|
+
*/
|
|
55
|
+
function tokensOf(pMetacontroller, pExpression)
|
|
56
|
+
{
|
|
57
|
+
const tmpResult = {};
|
|
58
|
+
pMetacontroller.pict.instantiateServiceProviderIfNotExists('ExpressionParser').tokenize(pExpression, tmpResult);
|
|
59
|
+
return Array.from(tmpResult.OriginalRawTokens);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
suite('PictFormMetacontroller distinct manifests', () =>
|
|
63
|
+
{
|
|
64
|
+
suite('rewriteSolverExpression', () =>
|
|
65
|
+
{
|
|
66
|
+
const _HashTranslation = { Width: `Width_${SALT}`, Depth: `Depth_${SALT}` };
|
|
67
|
+
const _AddressTranslation = { Width: `${SALT}.Width`, Height: `${SALT}.Height`, Rows: `${SALT}.Rows`, QtyList: `${SALT}.QtyList`, RowCount: `${SALT}.RowCount`, Crate: `${SALT}.Crate`, Measure: `Measure_${SALT}`, Slopes: `${SALT}.Slopes` };
|
|
68
|
+
const _PrefixTranslation = { Width: `${SALT}.Width`, Height: `${SALT}.Height`, Rows: `${SALT}.Rows`, QtyList: `${SALT}.QtyList`, RowCount: `${SALT}.RowCount`, Crate: `${SALT}.Crate`, Slopes: `${SALT}.Slopes` };
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @param {any} pMetacontroller
|
|
72
|
+
* @param {string} pExpression
|
|
73
|
+
* @param {Record<string, any>} [pOptions]
|
|
74
|
+
* @return {string}
|
|
75
|
+
*/
|
|
76
|
+
function rewrite(pMetacontroller, pExpression, pOptions)
|
|
77
|
+
{
|
|
78
|
+
return pMetacontroller.rewriteSolverExpression(pExpression, _HashTranslation, _AddressTranslation, Object.assign({ PrefixAddressTranslation: _PrefixTranslation }, pOptions));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @param {any} pMetacontroller
|
|
83
|
+
* @param {string} pExpression
|
|
84
|
+
* @param {string} pExpected
|
|
85
|
+
* @param {Record<string, any>} [pOptions]
|
|
86
|
+
*/
|
|
87
|
+
function expectRewrite(pMetacontroller, pExpression, pExpected, pOptions)
|
|
88
|
+
{
|
|
89
|
+
Expect(tokensOf(pMetacontroller, rewrite(pMetacontroller, pExpression, pOptions))).to.deep.equal(tokensOf(pMetacontroller, pExpected), pExpression);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
test('translates exact symbol and state address references (unchanged behavior)', () =>
|
|
93
|
+
{
|
|
94
|
+
const tmpMetacontroller = buildMetacontroller();
|
|
95
|
+
expectRewrite(tmpMetacontroller, 'Area = Width * Height', `Area = Width_${SALT} * ${SALT}.Height`);
|
|
96
|
+
expectRewrite(tmpMetacontroller, 'Area = {Width} + 1', `Area = {${SALT}.Width} + 1`);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('translates a reference that only starts with a local address', () =>
|
|
100
|
+
{
|
|
101
|
+
const tmpMetacontroller = buildMetacontroller();
|
|
102
|
+
expectRewrite(tmpMetacontroller, 'A = Rows.length', `A = ${SALT}.Rows.length`);
|
|
103
|
+
expectRewrite(tmpMetacontroller, 'A = Rows[0].Line', `A = ${SALT}.Rows[0].Line`);
|
|
104
|
+
expectRewrite(tmpMetacontroller, 'A = SUM(Rows[].Line)', `A = SUM(${SALT}.Rows[].Line)`);
|
|
105
|
+
expectRewrite(tmpMetacontroller, 'A = {Rows[1].Line}', `A = {${SALT}.Rows[1].Line}`);
|
|
106
|
+
expectRewrite(tmpMetacontroller, 'A = Crate.Items.length', `A = ${SALT}.Crate.Items.length`);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('leaves a longer name that merely starts with a local name alone', () =>
|
|
110
|
+
{
|
|
111
|
+
const tmpMetacontroller = buildMetacontroller();
|
|
112
|
+
expectRewrite(tmpMetacontroller, 'A = WidthMaximum + HeightMax', 'A = WidthMaximum + HeightMax');
|
|
113
|
+
expectRewrite(tmpMetacontroller, 'A = RowsTotal.length', 'A = RowsTotal.length');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('translates marshal-destination-prefixed addresses, including partial references', () =>
|
|
117
|
+
{
|
|
118
|
+
const tmpMetacontroller = buildMetacontroller(MARSHAL_DESTINATION);
|
|
119
|
+
expectRewrite(tmpMetacontroller, 'A = GETVALUE("AppData.Orchard.Width")', `A = GETVALUE("AppData.Orchard.${SALT}.Width")`);
|
|
120
|
+
expectRewrite(tmpMetacontroller, 'A = GETVALUE("AppData.Orchard.Rows[1].Qty")', `A = GETVALUE("AppData.Orchard.${SALT}.Rows[1].Qty")`);
|
|
121
|
+
expectRewrite(tmpMetacontroller, 'A = {AppData.Orchard.Height}', `A = {AppData.Orchard.${SALT}.Height}`);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('translates string parameters that name a section or an input', () =>
|
|
125
|
+
{
|
|
126
|
+
const tmpMetacontroller = buildMetacontroller();
|
|
127
|
+
expectRewrite(tmpMetacontroller, 'SetSectionVisibility("Measure", 1)', `SetSectionVisibility("Measure_${SALT}", 1)`);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('leaves string literals that are not address parameters alone', () =>
|
|
131
|
+
{
|
|
132
|
+
const tmpMetacontroller = buildMetacontroller();
|
|
133
|
+
expectRewrite(tmpMetacontroller, 'L = IF(Width, ">", 3.5, "Width", "Narrow")', `L = IF(Width_${SALT}, ">", 3.5, "Width", "Narrow")`);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('leaves references that are not local to the manifest alone', () =>
|
|
137
|
+
{
|
|
138
|
+
const tmpMetacontroller = buildMetacontroller();
|
|
139
|
+
expectRewrite(tmpMetacontroller, 'A = Width * HostRate', `A = Width_${SALT} * HostRate`);
|
|
140
|
+
expectRewrite(tmpMetacontroller, 'SetSectionVisibility("Overview", 1)', 'SetSectionVisibility("Overview", 1)');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('leaves MAP iteration variables alone and translates what they iterate over', () =>
|
|
144
|
+
{
|
|
145
|
+
const tmpMetacontroller = buildMetacontroller();
|
|
146
|
+
expectRewrite(tmpMetacontroller, 'D = MAP VAR Qty FROM QtyList : Qty * 2', `D = MAP VAR Qty FROM ${SALT}.QtyList : Qty * 2`);
|
|
147
|
+
expectRewrite(tmpMetacontroller, 'S = MAP VAR r FROM Rows : r.Qty * Width', `S = MAP VAR r FROM ${SALT}.Rows : r.Qty * Width_${SALT}`);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('leaves a MAP iteration variable alone even when a local address shares its name', () =>
|
|
151
|
+
{
|
|
152
|
+
const tmpMetacontroller = buildMetacontroller();
|
|
153
|
+
expectRewrite(tmpMetacontroller, 'D = MAP VAR Width FROM QtyList : Width * 2', `D = MAP VAR Width FROM ${SALT}.QtyList : Width * 2`);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test('leaves the MAP prev_ variable alone', () =>
|
|
157
|
+
{
|
|
158
|
+
const tmpMetacontroller = buildMetacontroller();
|
|
159
|
+
expectRewrite(tmpMetacontroller, 'P = MAP VAR Slopes FROM Slopes : Slopes - prev_Slopes', `P = MAP VAR Slopes FROM ${SALT}.Slopes : Slopes - prev_Slopes`);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test('leaves SERIES loop variables alone and translates the range', () =>
|
|
163
|
+
{
|
|
164
|
+
const tmpMetacontroller = buildMetacontroller();
|
|
165
|
+
expectRewrite(tmpMetacontroller, 'T = SERIES FROM 1 TO RowCount : n * Width', `T = SERIES FROM 1 TO ${SALT}.RowCount : n * Width_${SALT}`);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('translates the MULTIROWMAP row set but not the per-row property it reads', () =>
|
|
169
|
+
{
|
|
170
|
+
const tmpMetacontroller = buildMetacontroller();
|
|
171
|
+
expectRewrite(tmpMetacontroller, 'M = MULTIROWMAP ROWS FROM Rows VAR Width FROM Width OFFSET 1 : Width * 2', `M = MULTIROWMAP ROWS FROM ${SALT}.Rows VAR Width FROM Width OFFSET 1 : Width * 2`);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test('a record set solver reads its row, so only absolute references are translated', () =>
|
|
175
|
+
{
|
|
176
|
+
const tmpMetacontroller = buildMetacontroller(MARSHAL_DESTINATION);
|
|
177
|
+
expectRewrite(tmpMetacontroller, 'Line = Width * Height', 'Line = Width * Height', { RowRelative: true });
|
|
178
|
+
expectRewrite(tmpMetacontroller, 'Line = GETVALUE("AppData.Orchard.Width")', `Line = GETVALUE("AppData.Orchard.${SALT}.Width")`, { RowRelative: true });
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test('returns the original expression when nothing is translated', () =>
|
|
182
|
+
{
|
|
183
|
+
const tmpMetacontroller = buildMetacontroller();
|
|
184
|
+
Expect(rewrite(tmpMetacontroller, 'A = B + C')).to.equal('A = B + C');
|
|
185
|
+
Expect(rewrite(tmpMetacontroller, '')).to.equal('');
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
suite('createDistinctManifest', () =>
|
|
190
|
+
{
|
|
191
|
+
/**
|
|
192
|
+
* @return {{ Metacontroller: any, Manifest: Record<string, any>, Salted: Record<string, any> }}
|
|
193
|
+
*/
|
|
194
|
+
function saltEdgeCaseManifest()
|
|
195
|
+
{
|
|
196
|
+
const tmpMetacontroller = buildMetacontroller(MARSHAL_DESTINATION);
|
|
197
|
+
const tmpManifest = JSON.parse(JSON.stringify(_EdgeCaseManifests.InjectableManifest));
|
|
198
|
+
const tmpSalted = tmpMetacontroller.createDistinctManifest(tmpManifest, SALT);
|
|
199
|
+
return { Metacontroller: tmpMetacontroller, Manifest: tmpManifest, Salted: tmpSalted };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* @param {Record<string, any>} pSalted
|
|
204
|
+
* @param {string} pOriginalHash
|
|
205
|
+
* @return {Record<string, any>}
|
|
206
|
+
*/
|
|
207
|
+
function descriptorByOriginalHash(pSalted, pOriginalHash)
|
|
208
|
+
{
|
|
209
|
+
return Object.values(pSalted.Descriptors).find((pDescriptor) => pDescriptor.OriginalHash === pOriginalHash);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* @param {Record<string, any>} pSalted
|
|
214
|
+
* @param {string} pSectionHash
|
|
215
|
+
* @return {Record<string, any>}
|
|
216
|
+
*/
|
|
217
|
+
function sectionByOriginalHash(pSalted, pSectionHash)
|
|
218
|
+
{
|
|
219
|
+
return pSalted.Sections.find((pSection) => pSection.OriginalHash === pSectionHash);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
test('salts section, group and input hashes and nests data addresses (unchanged behavior)', () =>
|
|
223
|
+
{
|
|
224
|
+
const { Salted } = saltEdgeCaseManifest();
|
|
225
|
+
Expect(sectionByOriginalHash(Salted, 'Measure').Hash).to.equal(`Measure_${SALT}`);
|
|
226
|
+
Expect(sectionByOriginalHash(Salted, 'Measure').Groups[0].Hash).to.equal(`MeasureGroup_${SALT}`);
|
|
227
|
+
Expect(Salted.Descriptors[`${SALT}.Width`]).to.be.an('object');
|
|
228
|
+
Expect(Salted.Descriptors[`${SALT}.Width`].Hash).to.equal(`Width_${SALT}`);
|
|
229
|
+
Expect(Salted.Descriptors[`${SALT}.Width`].PictForm.Section).to.equal(`Measure_${SALT}`);
|
|
230
|
+
Expect(sectionByOriginalHash(Salted, 'Measure').Groups[1].RecordSetAddress).to.equal(`${SALT}.Rows`);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test('does not modify the manifest it was given', () =>
|
|
234
|
+
{
|
|
235
|
+
const { Manifest } = saltEdgeCaseManifest();
|
|
236
|
+
Expect(Manifest).to.deep.equal(_EdgeCaseManifests.InjectableManifest);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test('translates tab section sets and their default tab', () =>
|
|
240
|
+
{
|
|
241
|
+
const { Salted } = saltEdgeCaseManifest();
|
|
242
|
+
const tmpTabPicker = descriptorByOriginalHash(Salted, 'TabPicker');
|
|
243
|
+
Expect(tmpTabPicker.PictForm.TabSectionSet).to.deep.equal([ `TabOne_${SALT}`, `TabTwo_${SALT}` ]);
|
|
244
|
+
Expect(tmpTabPicker.PictForm.DefaultTabSectionHash).to.equal(`TabTwo_${SALT}`);
|
|
245
|
+
Expect(tmpTabPicker.PictForm.TabSectionNames).to.deep.equal([ 'One', 'Two' ]);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
test('translates tab group sets and their default tab', () =>
|
|
249
|
+
{
|
|
250
|
+
const { Salted } = saltEdgeCaseManifest();
|
|
251
|
+
const tmpGroupPicker = descriptorByOriginalHash(Salted, 'GroupPicker');
|
|
252
|
+
Expect(tmpGroupPicker.PictForm.TabGroupSet).to.deep.equal([ `GroupA_${SALT}`, `GroupB_${SALT}` ]);
|
|
253
|
+
Expect(tmpGroupPicker.PictForm.DefaultTabGroupHash).to.equal(`GroupB_${SALT}`);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
test('leaves a tab that names a section outside the manifest alone', () =>
|
|
257
|
+
{
|
|
258
|
+
const tmpMetacontroller = buildMetacontroller(MARSHAL_DESTINATION);
|
|
259
|
+
const tmpManifest = JSON.parse(JSON.stringify(_EdgeCaseManifests.InjectableManifest));
|
|
260
|
+
tmpManifest.Descriptors.TabPicker.PictForm.TabSectionSet = [ 'TabOne', 'Overview' ];
|
|
261
|
+
const tmpSalted = tmpMetacontroller.createDistinctManifest(tmpManifest, SALT);
|
|
262
|
+
Expect(descriptorByOriginalHash(tmpSalted, 'TabPicker').PictForm.TabSectionSet).to.deep.equal([ `TabOne_${SALT}`, 'Overview' ]);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test('translates chart label and dataset solvers', () =>
|
|
266
|
+
{
|
|
267
|
+
const { Metacontroller, Salted } = saltEdgeCaseManifest();
|
|
268
|
+
const tmpChart = descriptorByOriginalHash(Salted, 'LineChart');
|
|
269
|
+
Expect(tokensOf(Metacontroller, tmpChart.PictForm.ChartLabelsSolver)).to.deep.equal(tokensOf(Metacontroller, `flatten(${SALT}.Rows[].Qty)`));
|
|
270
|
+
Expect(tokensOf(Metacontroller, tmpChart.PictForm.ChartDatasetsSolvers[0].DataSolver)).to.deep.equal(tokensOf(Metacontroller, `flatten(${SALT}.Rows[].Line)`));
|
|
271
|
+
Expect(tokensOf(Metacontroller, tmpChart.PictForm.ChartDatasetsSolvers[1].DataSolver)).to.deep.equal(tokensOf(Metacontroller, `flatten(Scaled_${SALT})`));
|
|
272
|
+
Expect(tmpChart.PictForm.ChartDatasetsSolvers[1].Label).to.equal('Scaled');
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
test('translates trigger group solvers, trigger addresses and marshal targets', () =>
|
|
276
|
+
{
|
|
277
|
+
const { Metacontroller, Salted } = saltEdgeCaseManifest();
|
|
278
|
+
const tmpSource = descriptorByOriginalHash(Salted, 'Source');
|
|
279
|
+
const tmpTriggerGroup = tmpSource.PictForm.AutofillTriggerGroup[0];
|
|
280
|
+
Expect(tokensOf(Metacontroller, tmpTriggerGroup.PostSolvers[0])).to.deep.equal(tokensOf(Metacontroller, `Echo_${SALT} = Source_${SALT} * 10`));
|
|
281
|
+
Expect(tmpTriggerGroup.MarshalOnComplete.Section).to.equal(`Composed_${SALT}`);
|
|
282
|
+
Expect(tmpTriggerGroup.MarshalOnComplete.Input).to.equal(`Echo_${SALT}`);
|
|
283
|
+
Expect(tmpTriggerGroup.TriggerGroupHash).to.equal(`CrateEcho_${SALT}`);
|
|
284
|
+
const tmpMirror = descriptorByOriginalHash(Salted, 'Mirror');
|
|
285
|
+
Expect(tmpMirror.PictForm.AutofillTriggerGroup[0].TriggerAddress).to.equal(`AppData.Orchard.${SALT}.Source`);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
test('translates local addresses inside templated input templates', () =>
|
|
289
|
+
{
|
|
290
|
+
const { Salted } = saltEdgeCaseManifest();
|
|
291
|
+
const tmpSummary = descriptorByOriginalHash(Salted, 'Summary');
|
|
292
|
+
Expect(tmpSummary.PictForm.Template).to.contain(`{~D:Record.Data.${SALT}.Width~}`);
|
|
293
|
+
Expect(tmpSummary.PictForm.Template).to.contain(`{~D:AppData.Orchard.${SALT}.Height~}`);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
test('leaves record set solvers relative to their row', () =>
|
|
297
|
+
{
|
|
298
|
+
const { Salted } = saltEdgeCaseManifest();
|
|
299
|
+
const tmpGroup = sectionByOriginalHash(Salted, 'Measure').Groups[1];
|
|
300
|
+
Expect(tmpGroup.RecordSetSolvers[0]).to.equal('Line = Qty * Price');
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test('translates section solvers in both string and object form, keeping ordinals', () =>
|
|
304
|
+
{
|
|
305
|
+
const { Metacontroller, Salted } = saltEdgeCaseManifest();
|
|
306
|
+
const tmpSolvers = sectionByOriginalHash(Salted, 'Measure').Solvers;
|
|
307
|
+
Expect(typeof tmpSolvers[0]).to.equal('string');
|
|
308
|
+
Expect(tokensOf(Metacontroller, tmpSolvers[0])).to.deep.equal(tokensOf(Metacontroller, `Area_${SALT} = Width_${SALT} * Height_${SALT}`));
|
|
309
|
+
Expect(tmpSolvers[1].Ordinal).to.equal(3);
|
|
310
|
+
Expect(tokensOf(Metacontroller, tmpSolvers[1].Expression)).to.deep.equal(tokensOf(Metacontroller, `AreaScaled_${SALT} = Area_${SALT} * HostRate`));
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
test('salts every trigger group hash the manifest declares, in each carrier', () =>
|
|
314
|
+
{
|
|
315
|
+
const { Salted } = saltEdgeCaseManifest();
|
|
316
|
+
Expect(descriptorByOriginalHash(Salted, 'Source').PictForm.AutofillTriggerGroup[0].TriggerGroupHash).to.equal(`CrateEcho_${SALT}`);
|
|
317
|
+
Expect(descriptorByOriginalHash(Salted, 'Mirror').PictForm.AutofillTriggerGroup[0].TriggerGroupHash).to.equal(`CrateEcho_${SALT}`);
|
|
318
|
+
Expect(descriptorByOriginalHash(Salted, 'Lookup').PictForm.TemplatedEntityLookup.TriggerGroupHash).to.equal(`CrateEcho_${SALT}`);
|
|
319
|
+
Expect(descriptorByOriginalHash(Salted, 'Bundled').PictForm.EntityBundleTriggerGroup).to.equal(`CrateEcho_${SALT}`);
|
|
320
|
+
Expect(Salted.ReferenceManifests.CrateRow.Descriptors.Tally.PictForm.TabularTriggerGroup[0].TriggerGroupHash).to.equal(`CrateRowTally_${SALT}`);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
test('leaves a trigger group the manifest declares shared alone, salting the rest', () =>
|
|
324
|
+
{
|
|
325
|
+
const tmpMetacontroller = buildMetacontroller(MARSHAL_DESTINATION);
|
|
326
|
+
const tmpManifest = JSON.parse(JSON.stringify(_EdgeCaseManifests.InjectableManifest));
|
|
327
|
+
tmpManifest.SharedTriggerGroups = [ 'CrateEcho' ];
|
|
328
|
+
const tmpSalted = tmpMetacontroller.createDistinctManifest(tmpManifest, SALT);
|
|
329
|
+
Expect(descriptorByOriginalHash(tmpSalted, 'Source').PictForm.AutofillTriggerGroup[0].TriggerGroupHash).to.equal('CrateEcho');
|
|
330
|
+
Expect(descriptorByOriginalHash(tmpSalted, 'Bundled').PictForm.EntityBundleTriggerGroup).to.equal('CrateEcho');
|
|
331
|
+
Expect(tmpSalted.ReferenceManifests.CrateRow.Descriptors.Tally.PictForm.TabularTriggerGroup[0].TriggerGroupHash).to.equal(`CrateRowTally_${SALT}`);
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
test('two salts of the same manifest share no addresses or hashes', () =>
|
|
335
|
+
{
|
|
336
|
+
const tmpMetacontroller = buildMetacontroller(MARSHAL_DESTINATION);
|
|
337
|
+
const tmpFirst = tmpMetacontroller.createDistinctManifest(_EdgeCaseManifests.InjectableManifest, 'alpha');
|
|
338
|
+
const tmpSecond = tmpMetacontroller.createDistinctManifest(_EdgeCaseManifests.InjectableManifest, 'alphabeta');
|
|
339
|
+
const tmpFirstAddresses = new Set(Object.keys(tmpFirst.Descriptors));
|
|
340
|
+
const tmpShared = Object.keys(tmpSecond.Descriptors).filter((pAddress) => tmpFirstAddresses.has(pAddress));
|
|
341
|
+
Expect(tmpShared).to.deep.equal([]);
|
|
342
|
+
const tmpFirstHashes = new Set(Object.values(tmpFirst.Descriptors).map((pDescriptor) => pDescriptor.Hash));
|
|
343
|
+
const tmpSharedHashes = Object.values(tmpSecond.Descriptors).map((pDescriptor) => pDescriptor.Hash).filter((pHash) => tmpFirstHashes.has(pHash));
|
|
344
|
+
Expect(tmpSharedHashes).to.deep.equal([]);
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
suite('buildManifestTranslations', () =>
|
|
349
|
+
{
|
|
350
|
+
test('translates one salted copy', () =>
|
|
351
|
+
{
|
|
352
|
+
const tmpMetacontroller = buildMetacontroller(MARSHAL_DESTINATION);
|
|
353
|
+
const tmpSalted = tmpMetacontroller.createDistinctManifest(_EdgeCaseManifests.InjectableManifest, 'alpha');
|
|
354
|
+
const { HashTranslation, AddressTranslation } = tmpMetacontroller.buildManifestTranslations(tmpSalted);
|
|
355
|
+
Expect(HashTranslation.Width).to.equal('Width_alpha');
|
|
356
|
+
Expect(AddressTranslation.Width).to.equal('alpha.Width');
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
test('warns when handed a manifest holding more than one copy, rather than collapsing silently', () =>
|
|
360
|
+
{
|
|
361
|
+
const tmpMetacontroller = buildMetacontroller(MARSHAL_DESTINATION);
|
|
362
|
+
const tmpFirst = tmpMetacontroller.createDistinctManifest(_EdgeCaseManifests.InjectableManifest, 'alpha');
|
|
363
|
+
const tmpSecond = tmpMetacontroller.createDistinctManifest(_EdgeCaseManifests.InjectableManifest, 'beta');
|
|
364
|
+
const tmpMerged = { Sections: tmpFirst.Sections.concat(tmpSecond.Sections), Descriptors: Object.assign({}, tmpFirst.Descriptors, tmpSecond.Descriptors) };
|
|
365
|
+
const tmpWarnings = [];
|
|
366
|
+
tmpMetacontroller.pict.log.warn = (pMessage) =>
|
|
367
|
+
{
|
|
368
|
+
tmpWarnings.push(pMessage);
|
|
369
|
+
};
|
|
370
|
+
const { HashTranslation } = tmpMetacontroller.buildManifestTranslations(tmpMerged);
|
|
371
|
+
Expect(tmpWarnings.length, 'a merged manifest cannot say what a name became').to.equal(1);
|
|
372
|
+
Expect(tmpWarnings[0]).to.contain('more than one injected copy');
|
|
373
|
+
Expect(HashTranslation.Width).to.equal('Width_beta');
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
suite('mergeValidationSolvers', () =>
|
|
378
|
+
{
|
|
379
|
+
test('appends the validation solvers of each salted copy after the form\'s own, in order', () =>
|
|
380
|
+
{
|
|
381
|
+
const tmpMetacontroller = buildMetacontroller(MARSHAL_DESTINATION);
|
|
382
|
+
const tmpForm = { ValidationSolvers: [ 'CrateCount = 1' ] };
|
|
383
|
+
const tmpFirst = tmpMetacontroller.createDistinctManifest(_EdgeCaseManifests.InjectableManifest, 'alpha');
|
|
384
|
+
const tmpSecond = tmpMetacontroller.createDistinctManifest(_EdgeCaseManifests.InjectableManifest, 'alphabeta');
|
|
385
|
+
Expect(tmpMetacontroller.mergeValidationSolvers(tmpForm, tmpFirst)).to.equal(1);
|
|
386
|
+
Expect(tmpMetacontroller.mergeValidationSolvers(tmpForm, tmpSecond)).to.equal(1);
|
|
387
|
+
Expect(tmpForm.ValidationSolvers).to.deep.equal([ 'CrateCount = 1' ].concat(tmpFirst.ValidationSolvers, tmpSecond.ValidationSolvers));
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
test('adding the same copy again does not add its validation solvers twice', () =>
|
|
391
|
+
{
|
|
392
|
+
const tmpMetacontroller = buildMetacontroller(MARSHAL_DESTINATION);
|
|
393
|
+
const tmpForm = { };
|
|
394
|
+
const tmpSalted = tmpMetacontroller.createDistinctManifest(_EdgeCaseManifests.InjectableManifest, SALT);
|
|
395
|
+
tmpSalted.ValidationSolvers.push({ Ordinal: 2, Expression: 'Checked = 1' });
|
|
396
|
+
Expect(tmpMetacontroller.mergeValidationSolvers(tmpForm, tmpSalted)).to.equal(2);
|
|
397
|
+
Expect(tmpMetacontroller.mergeValidationSolvers(tmpForm, tmpSalted)).to.equal(0);
|
|
398
|
+
Expect(tmpForm.ValidationSolvers).to.deep.equal(tmpSalted.ValidationSolvers);
|
|
399
|
+
Expect(tmpForm.ValidationSolvers[1]).to.not.equal(tmpSalted.ValidationSolvers[1]);
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
test('leaves the form alone when the added manifest has no validation solvers', () =>
|
|
403
|
+
{
|
|
404
|
+
const tmpMetacontroller = buildMetacontroller(MARSHAL_DESTINATION);
|
|
405
|
+
const tmpForm = { };
|
|
406
|
+
Expect(tmpMetacontroller.mergeValidationSolvers(tmpForm, { Descriptors: { } })).to.equal(0);
|
|
407
|
+
Expect(tmpForm).to.deep.equal({ });
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
});
|