pict-section-form 1.4.1 → 1.4.2
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/package.json
CHANGED
|
@@ -106,7 +106,7 @@ class PictDynamicFormsInformary extends libPictProvider
|
|
|
106
106
|
const tmpFormElements = this.getFormElements(pFormHash);
|
|
107
107
|
|
|
108
108
|
// Optional Filters (so we don't just blindly do the whole form)
|
|
109
|
-
const tmpDatum = (pDatum
|
|
109
|
+
const tmpDatum = (pDatum == null) ? false : pDatum;
|
|
110
110
|
const tmpRecordIndex = (typeof(pRecordIndex) === 'number') ? String(pRecordIndex) : pRecordIndex;
|
|
111
111
|
|
|
112
112
|
// Enumerate the form elements, and put data in them for each address
|
|
@@ -107,5 +107,87 @@ suite(
|
|
|
107
107
|
);
|
|
108
108
|
}
|
|
109
109
|
);
|
|
110
|
+
|
|
111
|
+
suite(
|
|
112
|
+
'marshalFormToData honours the datum and record index filters',
|
|
113
|
+
() =>
|
|
114
|
+
{
|
|
115
|
+
const buildElement = (pAttributes) =>
|
|
116
|
+
{
|
|
117
|
+
return { getAttribute: (pName) => (pName in pAttributes ? pAttributes[pName] : null) };
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// A form with two plain inputs and a two-row recordset; the browser holds a value for each.
|
|
121
|
+
const buildHarness = () =>
|
|
122
|
+
{
|
|
123
|
+
const tmpPict = new libPict({ Product: 'MockInformary', ProductVersion: '1.0.0' });
|
|
124
|
+
tmpPict.addProviderSingleton('Informary', libInformary.default_configuration, libInformary);
|
|
125
|
+
const tmpInformary = tmpPict.providers.Informary;
|
|
126
|
+
const tmpElements = [
|
|
127
|
+
buildElement({ 'data-i-datum': 'Title' }),
|
|
128
|
+
buildElement({ 'data-i-datum': 'Author' }),
|
|
129
|
+
buildElement({ 'data-i-datum': 'Price', 'data-i-container': 'Editions', 'data-i-index': '0' }),
|
|
130
|
+
buildElement({ 'data-i-datum': 'Price', 'data-i-container': 'Editions', 'data-i-index': '1' })
|
|
131
|
+
];
|
|
132
|
+
const tmpBrowserValues = {};
|
|
133
|
+
tmpBrowserValues[tmpInformary.getContentBrowserAddress('Shelf', 'Title')] = 'Browser Title';
|
|
134
|
+
tmpBrowserValues[tmpInformary.getContentBrowserAddress('Shelf', 'Author')] = 'Browser Author';
|
|
135
|
+
tmpBrowserValues[tmpInformary.getContentBrowserAddress('Shelf', 'Price', 'Editions', '0')] = 'Browser Price 0';
|
|
136
|
+
tmpBrowserValues[tmpInformary.getContentBrowserAddress('Shelf', 'Price', 'Editions', '1')] = 'Browser Price 1';
|
|
137
|
+
tmpInformary.getFormElements = () => tmpElements;
|
|
138
|
+
tmpPict.ContentAssignment.readContent = (pAddress) => tmpBrowserValues[pAddress];
|
|
139
|
+
const tmpWrites = [];
|
|
140
|
+
const tmpManifest = { setValueAtAddress: (pData, pAddress, pValue) => { tmpWrites.push(pAddress); pData[pAddress] = pValue; } };
|
|
141
|
+
return { informary: tmpInformary, manifest: tmpManifest, writes: tmpWrites };
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
test(
|
|
145
|
+
'with no datum, every element is copied back',
|
|
146
|
+
(fDone) =>
|
|
147
|
+
{
|
|
148
|
+
const tmpHarness = buildHarness();
|
|
149
|
+
tmpHarness.informary.marshalFormToData({}, 'Shelf', tmpHarness.manifest);
|
|
150
|
+
Expect(tmpHarness.writes).to.deep.equal([ 'Title', 'Author', 'Editions[0].Price', 'Editions[1].Price' ]);
|
|
151
|
+
fDone();
|
|
152
|
+
}
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
test(
|
|
156
|
+
'with a datum, only that element is copied back (a stale value elsewhere in the form is left alone)',
|
|
157
|
+
(fDone) =>
|
|
158
|
+
{
|
|
159
|
+
const tmpHarness = buildHarness();
|
|
160
|
+
const tmpData = { Author: 'Value set by a solver' };
|
|
161
|
+
tmpHarness.informary.marshalFormToData(tmpData, 'Shelf', tmpHarness.manifest, 'Title');
|
|
162
|
+
Expect(tmpHarness.writes).to.deep.equal([ 'Title' ]);
|
|
163
|
+
Expect(tmpData.Title).to.equal('Browser Title');
|
|
164
|
+
Expect(tmpData.Author).to.equal('Value set by a solver');
|
|
165
|
+
fDone();
|
|
166
|
+
}
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
test(
|
|
170
|
+
'with a datum and a record index, only that row of that column is copied back',
|
|
171
|
+
(fDone) =>
|
|
172
|
+
{
|
|
173
|
+
const tmpHarness = buildHarness();
|
|
174
|
+
tmpHarness.informary.marshalFormToData({}, 'Shelf', tmpHarness.manifest, 'Price', 1);
|
|
175
|
+
Expect(tmpHarness.writes).to.deep.equal([ 'Editions[1].Price' ]);
|
|
176
|
+
fDone();
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
test(
|
|
181
|
+
'a null datum is treated as no filter',
|
|
182
|
+
(fDone) =>
|
|
183
|
+
{
|
|
184
|
+
const tmpHarness = buildHarness();
|
|
185
|
+
tmpHarness.informary.marshalFormToData({}, 'Shelf', tmpHarness.manifest, null);
|
|
186
|
+
Expect(tmpHarness.writes.length).to.equal(4);
|
|
187
|
+
fDone();
|
|
188
|
+
}
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
);
|
|
110
192
|
}
|
|
111
193
|
);
|