pict-section-form 1.3.6 → 1.3.8

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.
@@ -684,6 +684,16 @@ class PictViewDynamicForm extends libPictViewClass
684
684
  {
685
685
  this.finalizeTransaction(tmpTransactionGUID);
686
686
  }
687
+
688
+ // The render that just happened repainted this section's markup without anything the solvers put
689
+ // on it -- the setsectionvisibility / setgroupvisibility hide classes, and any highlight class or
690
+ // inline color. Solvers run before the marshal that triggers most renders, so nothing else puts
691
+ // them back: restore them here, once, for every render path.
692
+ if (this.pict.providers.DynamicFormSolverBehaviors && this.sectionDefinition)
693
+ {
694
+ this.pict.providers.DynamicFormSolverBehaviors.reapplySectionDOMState(this.sectionDefinition.Hash);
695
+ }
696
+
687
697
  return super.onAfterRender(pRenderable);
688
698
  }
689
699
 
@@ -0,0 +1,99 @@
1
+ /*
2
+ `refreshtabularsection` used to re-render the WHOLE section, rebuilding every group's DOM --
3
+ which destroys any widget the user is mid-interaction with. Measured in a Headlight form: a
4
+ select2 picker in a sibling group was torn down and rebuilt on every tabular refresh, blanking
5
+ its tags for ~700ms, and the section's active tab reset with it.
6
+
7
+ renderGroupInPlace re-renders only the group that changed. These tests cover the SAFETY
8
+ contract rather than the happy path: every reason the scoped path cannot run must return false
9
+ -- never throw -- so refreshTabularSection falls back to the original full-section render and
10
+ behaviour is unchanged for anything it cannot handle.
11
+ */
12
+
13
+ const Chai = require('chai');
14
+ const Expect = Chai.expect;
15
+
16
+ const libDynamicFormSolverBehaviors = require('../source/providers/Pict-Provider-DynamicFormSolverBehaviors.js');
17
+
18
+ // The provider without its constructor -- these tests exercise one pure-ish method and only
19
+ // need the few collaborators it touches.
20
+ function buildProvider(pOverrides)
21
+ {
22
+ const tmpProvider = Object.create(libDynamicFormSolverBehaviors.prototype);
23
+ tmpProvider.warnings = [];
24
+ tmpProvider.log = { warn: (pMessage) => tmpProvider.warnings.push(pMessage), error: () => {} };
25
+ tmpProvider.pict = Object.assign(
26
+ {
27
+ providers: { MetatemplateGenerator: { getGroupLayoutProvider: () => ({ generateGroupLayoutTemplate: () => '<div></div>' }) } },
28
+ ContentAssignment: { getElement: () => [ { outerHTML: '<div></div>' } ] },
29
+ TemplateProvider: { addTemplate: () => {} },
30
+ DataProvider: { getDataByAddress: () => ({}) },
31
+ parseTemplateByHash: () => '<div id="GROUP-F1-Grid"></div>',
32
+ },
33
+ pOverrides || {});
34
+ return tmpProvider;
35
+ }
36
+
37
+ function buildView(pOverrides)
38
+ {
39
+ return Object.assign(
40
+ {
41
+ formID: 'F1',
42
+ options: { Hash: 'TestSection', DefaultTemplateRecordAddress: 'AppData.Form' },
43
+ getGroupIndexFromHash: () => 0,
44
+ getGroup: () => ({ Hash: 'Grid', GroupIndex: 0 }),
45
+ onAfterRender: () => true,
46
+ },
47
+ pOverrides || {});
48
+ }
49
+
50
+ suite('Pict-Section-Form - DynamicFormSolverBehaviors group-scoped render', () =>
51
+ {
52
+ test('renders the group in place when everything resolves', () =>
53
+ {
54
+ let tmpRenderedInPlace = false;
55
+ const tmpProvider = buildProvider();
56
+ const tmpView = buildView({ onAfterRender: () => { tmpRenderedInPlace = true; return true; } });
57
+ Expect(tmpProvider.renderGroupInPlace(tmpView, 'Grid')).to.equal(true);
58
+ Expect(tmpRenderedInPlace).to.equal(true);
59
+ });
60
+
61
+ test('falls back when the view is missing or has no formID', () =>
62
+ {
63
+ const tmpProvider = buildProvider();
64
+ Expect(tmpProvider.renderGroupInPlace(null, 'Grid')).to.equal(false);
65
+ Expect(tmpProvider.renderGroupInPlace(buildView({ formID: undefined }), 'Grid')).to.equal(false);
66
+ });
67
+
68
+ test('falls back when the group hash is not in the section', () =>
69
+ {
70
+ const tmpProvider = buildProvider();
71
+ Expect(tmpProvider.renderGroupInPlace(buildView({ getGroupIndexFromHash: () => -1 }), 'Nope')).to.equal(false);
72
+ });
73
+
74
+ test('falls back when the layout provider cannot generate a template', () =>
75
+ {
76
+ const tmpProvider = buildProvider({ providers: { MetatemplateGenerator: { getGroupLayoutProvider: () => ({}) } } });
77
+ Expect(tmpProvider.renderGroupInPlace(buildView(), 'Grid')).to.equal(false);
78
+ });
79
+
80
+ test('falls back when the group element is not in the DOM', () =>
81
+ {
82
+ const tmpProvider = buildProvider({ ContentAssignment: { getElement: () => [] } });
83
+ Expect(tmpProvider.renderGroupInPlace(buildView(), 'Grid')).to.equal(false);
84
+ });
85
+
86
+ test('falls back when the template parses to nothing', () =>
87
+ {
88
+ const tmpProvider = buildProvider({ parseTemplateByHash: () => '' });
89
+ Expect(tmpProvider.renderGroupInPlace(buildView(), 'Grid')).to.equal(false);
90
+ });
91
+
92
+ test('a throwing collaborator is caught, warned, and falls back', () =>
93
+ {
94
+ const tmpProvider = buildProvider({ parseTemplateByHash: () => { throw new Error('boom'); } });
95
+ Expect(tmpProvider.renderGroupInPlace(buildView(), 'Grid')).to.equal(false);
96
+ Expect(tmpProvider.warnings.length).to.equal(1);
97
+ Expect(tmpProvider.warnings[0]).to.contain('falling back');
98
+ });
99
+ });
@@ -45,6 +45,34 @@ function buildPictWithStubs()
45
45
  return new libPict();
46
46
  }
47
47
 
48
+ /**
49
+ * Swap window.localStorage for an in-memory shim. jsdom runs on an opaque origin where merely
50
+ * READING window.localStorage throws, so a real round-trip can't be exercised without this.
51
+ *
52
+ * @param {Object} pStore - Backing object for the shim.
53
+ * @return {Function} Restores the original descriptor.
54
+ */
55
+ function withStubbedStorage(pStore)
56
+ {
57
+ let tmpOriginal = Object.getOwnPropertyDescriptor(window, 'localStorage');
58
+ Object.defineProperty(window, 'localStorage',
59
+ {
60
+ configurable: true,
61
+ writable: true,
62
+ value:
63
+ {
64
+ getItem: (pKey) => ((pKey in pStore) ? pStore[pKey] : null),
65
+ setItem: (pKey, pValue) => { pStore[pKey] = String(pValue); },
66
+ removeItem: (pKey) => { delete pStore[pKey]; }
67
+ }
68
+ });
69
+ return () =>
70
+ {
71
+ if (tmpOriginal) Object.defineProperty(window, 'localStorage', tmpOriginal);
72
+ else delete window.localStorage;
73
+ };
74
+ }
75
+
48
76
  suite('Pict-Provider-Input-Diagram', () =>
49
77
  {
50
78
  test('module loads — class + default_configuration exposed', () =>
@@ -172,6 +200,158 @@ suite('Pict-Provider-Input-Diagram', () =>
172
200
  });
173
201
  });
174
202
 
203
+ // --- slot targeting -------------------------------------------------------------------------
204
+ // A host template that gives the hidden <input> id="{RawHTMLID}" (it has to, if it wants the
205
+ // provider's value write-back to find it) used to steal every mode class off the display slot,
206
+ // which silently killed the open editor's sizing. The slot must win.
207
+
208
+ test('_setSlotModeClass flags the DISPLAY SLOT, not a same-id hidden input', () =>
209
+ {
210
+ let tmpPict = buildPictWithStubs();
211
+ let tmpProvider = new libDiagramInput(tmpPict, {}, 'Pict-Input-Diagram');
212
+
213
+ document.body.innerHTML =
214
+ '<input type="hidden" id="ArchDiagram-input">' +
215
+ '<div id="DISPLAY-FOR-ArchDiagram-input" class="pict-section-form-diagram"></div>';
216
+
217
+ tmpProvider._setSlotModeClass(_StubInput, 'edit');
218
+
219
+ let tmpSlot = document.getElementById('DISPLAY-FOR-ArchDiagram-input');
220
+ let tmpHidden = document.getElementById('ArchDiagram-input');
221
+ Expect(tmpSlot.classList.contains('pict-section-form-diagram-edit')).to.equal(true);
222
+ Expect(tmpSlot.classList.contains('mode-edit')).to.equal(true);
223
+ Expect(tmpHidden.classList.contains('pict-section-form-diagram-edit')).to.equal(false);
224
+
225
+ tmpProvider._setSlotModeClass(_StubInput, 'view');
226
+ Expect(tmpSlot.classList.contains('mode-view')).to.equal(true);
227
+ Expect(tmpSlot.classList.contains('pict-section-form-diagram-edit')).to.equal(false);
228
+ document.body.innerHTML = '';
229
+ });
230
+
231
+ // --- editor height --------------------------------------------------------------------------
232
+
233
+ test('_normalizeHeight coerces numbers and numeric strings to px, passes CSS lengths through', () =>
234
+ {
235
+ let tmpProvider = new libDiagramInput(buildPictWithStubs(), {}, 'Pict-Input-Diagram');
236
+ Expect(tmpProvider._normalizeHeight(640)).to.equal('640px');
237
+ Expect(tmpProvider._normalizeHeight('640')).to.equal('640px');
238
+ Expect(tmpProvider._normalizeHeight('640px')).to.equal('640px');
239
+ Expect(tmpProvider._normalizeHeight(' 40rem ')).to.equal('40rem');
240
+ Expect(tmpProvider._normalizeHeight('')).to.equal('');
241
+ Expect(tmpProvider._normalizeHeight(null)).to.equal('');
242
+ Expect(tmpProvider._normalizeHeight(0)).to.equal('');
243
+ });
244
+
245
+ test('storage access that throws degrades to the descriptor Height', () =>
246
+ {
247
+ // jsdom serves an opaque origin, so even READING window.localStorage throws a SecurityError —
248
+ // the same shape as Safari private mode. Nothing here may propagate that.
249
+ let tmpProvider = new libDiagramInput(buildPictWithStubs(), {}, 'Pict-Input-Diagram');
250
+ let tmpInput = JSON.parse(JSON.stringify(_StubInput));
251
+ tmpInput.PictForm.Diagram.Height = '480px';
252
+
253
+ Expect(tmpProvider._readStoredHeight(tmpInput)).to.equal('');
254
+ Expect(tmpProvider._writeStoredHeight(tmpInput, '720px')).to.equal(false);
255
+ Expect(tmpProvider._resolveEditorHeight(tmpInput)).to.equal('480px');
256
+ });
257
+
258
+ test('_resolveEditorHeight prefers a stored height over the descriptor Height', () =>
259
+ {
260
+ let tmpProvider = new libDiagramInput(buildPictWithStubs(), {}, 'Pict-Input-Diagram');
261
+ let tmpInput = JSON.parse(JSON.stringify(_StubInput));
262
+ tmpInput.PictForm.Diagram.Height = '480px';
263
+
264
+ let tmpStore = {};
265
+ let tmpRestore = withStubbedStorage(tmpStore);
266
+ try
267
+ {
268
+ Expect(tmpProvider._resolveEditorHeight(tmpInput)).to.equal('480px');
269
+
270
+ tmpProvider._writeStoredHeight(tmpInput, '720px');
271
+ Expect(tmpProvider._resolveEditorHeight(tmpInput)).to.equal('720px');
272
+
273
+ // and with neither, the stylesheet stays in charge
274
+ delete tmpInput.PictForm.Diagram.Height;
275
+ window.localStorage.removeItem(tmpProvider._heightStorageKey(tmpInput));
276
+ Expect(tmpProvider._resolveEditorHeight(tmpInput)).to.equal('');
277
+ }
278
+ finally { tmpRestore(); }
279
+ });
280
+
281
+ test('_applyEditorHeight sets the CSS variable and _clearEditorHeight strips edit sizing', () =>
282
+ {
283
+ let tmpProvider = new libDiagramInput(buildPictWithStubs(), {}, 'Pict-Input-Diagram');
284
+ let tmpInput = JSON.parse(JSON.stringify(_StubInput));
285
+ tmpInput.PictForm.Diagram.Height = '600px';
286
+
287
+ document.body.innerHTML = '<div id="DISPLAY-FOR-ArchDiagram-input"></div>';
288
+ let tmpSlot = document.getElementById('DISPLAY-FOR-ArchDiagram-input');
289
+
290
+ // jsdom's CSSStyleDeclaration silently DROPS custom properties, so read them off a spy rather
291
+ // than off the element — the assertion is about what the provider asks for.
292
+ let tmpSet = [];
293
+ let tmpRemoved = [];
294
+ tmpSlot.style.setProperty = (pName, pValue) => tmpSet.push([pName, pValue]);
295
+ tmpSlot.style.removeProperty = (pName) => tmpRemoved.push(pName);
296
+
297
+ tmpProvider._applyEditorHeight(tmpInput);
298
+ Expect(tmpSet).to.deep.equal([['--pict-diagram-height', '600px']]);
299
+ // any inline height left by an earlier drag has to go, or the variable never applies
300
+ Expect(tmpRemoved).to.deep.equal(['height']);
301
+
302
+ // dropping to view must not leave the static view pinned to the dragged size
303
+ tmpRemoved.length = 0;
304
+ tmpProvider._clearEditorHeight(tmpInput);
305
+ Expect(tmpRemoved).to.deep.equal(['height', 'width', '--pict-diagram-height']);
306
+ document.body.innerHTML = '';
307
+ });
308
+
309
+ test('_captureEditorHeight remembers a dragged height, and ONLY a dragged one', () =>
310
+ {
311
+ let tmpProvider = new libDiagramInput(buildPictWithStubs(), {}, 'Pict-Input-Diagram');
312
+ let tmpInput = JSON.parse(JSON.stringify(_StubInput));
313
+ tmpInput.PictForm.Diagram.Height = '480px';
314
+
315
+ document.body.innerHTML = '<div id="DISPLAY-FOR-ArchDiagram-input"></div>';
316
+ let tmpSlot = document.getElementById('DISPLAY-FOR-ArchDiagram-input');
317
+
318
+ let tmpStore = {};
319
+ let tmpRestore = withStubbedStorage(tmpStore);
320
+ try
321
+ {
322
+ // No inline height — the descriptor's value is not the user's decision and must not stick.
323
+ Expect(tmpProvider._captureEditorHeight(tmpInput)).to.equal(false);
324
+ Expect(tmpProvider._resolveEditorHeight(tmpInput)).to.equal('480px');
325
+
326
+ // The grip writes an inline height; that IS a decision.
327
+ tmpSlot.style.height = '820px';
328
+ Expect(tmpProvider._captureEditorHeight(tmpInput)).to.equal(true);
329
+ Expect(tmpProvider._resolveEditorHeight(tmpInput)).to.equal('820px');
330
+ }
331
+ finally { tmpRestore(); document.body.innerHTML = ''; }
332
+ });
333
+
334
+ test('_buildEditorOptions defaults FormFactor to pointer and honours a descriptor override', () =>
335
+ {
336
+ let tmpPict = buildPictWithStubs();
337
+ let tmpProvider = new libDiagramInput(tmpPict, {}, 'Pict-Input-Diagram');
338
+ let tmpInput = JSON.parse(JSON.stringify(_StubInput));
339
+
340
+ Expect(tmpProvider._buildEditorOptions(tmpInput, '', {}).FormFactor).to.equal('pointer');
341
+
342
+ tmpInput.PictForm.Diagram.FormFactor = 'auto';
343
+ Expect(tmpProvider._buildEditorOptions(tmpInput, '', {}).FormFactor).to.equal('auto');
344
+ });
345
+
346
+ test('the open-editor CSS drives height from a variable and ships the resize grip', () =>
347
+ {
348
+ let tmpCSS = require('../source/providers/inputs/Pict-Provider-Input-Diagram-CSS.js');
349
+ Expect(tmpCSS).to.contain('--pict-diagram-height');
350
+ Expect(tmpCSS).to.contain('resize: vertical');
351
+ // a min-height on the inner chain would fight the grip on the way down
352
+ Expect(/\.pict-section-form-diagram-edit[^{]*\{[^}]*min-height:\s*420px/.test(tmpCSS)).to.equal(false);
353
+ });
354
+
175
355
  test('themeifySVG re-export is callable from the main module entry', () =>
176
356
  {
177
357
  Expect(typeof libFormMain.themeifySVG).to.equal('function');
@@ -696,6 +696,225 @@ suite('PictSectionForm Tabular Features', () =>
696
696
  }, fDone);
697
697
  });
698
698
 
699
+ /*
700
+ The <section> and <div> that carry a section's and a group's hide class are emitted BY the
701
+ section template, so every render regenerates them without whatever setsectionvisibility /
702
+ setgroupvisibility applied. Solvers run BEFORE the marshal that triggers a DynamicColumns
703
+ re-render, so nothing put it back: a hidden section silently reappeared the moment a source
704
+ row was renamed (reported on MI-BatchSheetCombined -- picking a Source/Name on the Aggregate
705
+ Products table un-hid the CSB worksheets whose columns are generated from it).
706
+ */
707
+ function makeVisibilityApp()
708
+ {
709
+ return makeApplication({
710
+ Hash: 'Grades',
711
+ Layout: 'Tabular',
712
+ RecordSetAddress: 'Grades',
713
+ RecordManifest: 'GradeRowEditor',
714
+ DynamicColumns:
715
+ [
716
+ {
717
+ SourceAddress: 'Assignments',
718
+ HashTemplate: 'Grade_{~D:Record.IDAssignment~}',
719
+ NameTemplate: '{~D:Record.Title~}',
720
+ InformaryDataAddressTemplate: 'Grades.{~D:Record.IDAssignment~}',
721
+ DataType: 'Number',
722
+ PictForm: { InputType: 'Number' }
723
+ }
724
+ ]
725
+ });
726
+ }
727
+
728
+ // Paint the view into a real destination element so #SECTION-<formID> exists to assert on.
729
+ function paintView(pView)
730
+ {
731
+ document.body.innerHTML = `<div id="${String(pView.options.DefaultDestinationAddress).replace(/^#/, '')}"></div>`;
732
+ pView.render();
733
+ }
734
+
735
+ test('A hidden section STAYS hidden across a DynamicColumns re-render', (fDone) =>
736
+ {
737
+ bootstrap(makeVisibilityApp(), (_Pict) =>
738
+ {
739
+ let tmpView = _Pict.views['PictSectionForm-Class'];
740
+ let tmpGroup = tmpView.sectionDefinition.Groups[0];
741
+ let tmpBehaviors = _Pict.providers.DynamicFormSolverBehaviors;
742
+ let fSection = () => document.querySelector(`#SECTION-${tmpView.formID}`);
743
+
744
+ paintView(tmpView);
745
+ Expect(fSection()).to.not.equal(null, 'the section painted');
746
+
747
+ tmpBehaviors.hideSection('Class');
748
+ Expect(fSection().className).to.contain('pict-section-form-hidden-section', 'baseline: section hidden');
749
+
750
+ // Rename a source row: namesChanged, so the Tabular layout re-renders the section mid-marshal.
751
+ _Pict.AppData.Assignments[0].Title = 'Renamed';
752
+ _Pict.providers['Pict-Layout-Tabular'].onDataMarshalToForm(tmpView, tmpGroup);
753
+
754
+ Expect(tmpGroup.supportingManifest.elementDescriptors['Grade_1'].Name).to.equal('Renamed',
755
+ 'the re-render did happen (header label re-baked)');
756
+ Expect(fSection()).to.not.equal(null, 'the section re-painted');
757
+ Expect(fSection().className).to.contain('pict-section-form-hidden-section',
758
+ 'the hide class survived the DynamicColumns re-render');
759
+ }, fDone);
760
+ });
761
+
762
+ test('A section shown again STAYS visible across a DynamicColumns re-render', (fDone) =>
763
+ {
764
+ bootstrap(makeVisibilityApp(), (_Pict) =>
765
+ {
766
+ let tmpView = _Pict.views['PictSectionForm-Class'];
767
+ let tmpGroup = tmpView.sectionDefinition.Groups[0];
768
+ let tmpBehaviors = _Pict.providers.DynamicFormSolverBehaviors;
769
+ let fSection = () => document.querySelector(`#SECTION-${tmpView.formID}`);
770
+
771
+ paintView(tmpView);
772
+ tmpBehaviors.hideSection('Class');
773
+ tmpBehaviors.showSection('Class');
774
+
775
+ _Pict.AppData.Assignments[0].Title = 'Renamed';
776
+ _Pict.providers['Pict-Layout-Tabular'].onDataMarshalToForm(tmpView, tmpGroup);
777
+
778
+ Expect(fSection().className).to.not.contain('pict-section-form-hidden-section',
779
+ 'a re-shown section must not be re-hidden by the restore');
780
+ }, fDone);
781
+ });
782
+
783
+ test('A hidden GROUP stays hidden across renderGroupInPlace', (fDone) =>
784
+ {
785
+ bootstrap(makeVisibilityApp(), (_Pict) =>
786
+ {
787
+ let tmpView = _Pict.views['PictSectionForm-Class'];
788
+ let tmpBehaviors = _Pict.providers.DynamicFormSolverBehaviors;
789
+ let fGroup = () => document.querySelector(`#GROUP-${tmpView.formID}-Grades`);
790
+
791
+ paintView(tmpView);
792
+ Expect(fGroup()).to.not.equal(null, 'the group painted');
793
+
794
+ tmpBehaviors.hideGroup('Class', 'Grades');
795
+ Expect(fGroup().className).to.contain('pict-section-form-hidden-group', 'baseline: group hidden');
796
+
797
+ // renderGroupInPlace swaps the group element's outerHTML for freshly parsed template
798
+ // output, which carries only the manifest CSSClass -- the hide class has to be restored.
799
+ Expect(tmpBehaviors.renderGroupInPlace(tmpView, 'Grades')).to.equal(true, 'scoped render ran');
800
+
801
+ Expect(fGroup()).to.not.equal(null, 'the group re-painted');
802
+ Expect(fGroup().className).to.contain('pict-section-form-hidden-group',
803
+ 'the group hide class survived the in-place group render');
804
+ }, fDone);
805
+ });
806
+
807
+ /*
808
+ Highlight classes and inline colors land on rows and cells the section template regenerates,
809
+ so they die on the same renders the hide class did. MI-BatchSheetCombined hides rows inside
810
+ its CSB tables with highlighttabularrow(..., "is-hidden"), which is the same defect one layer
811
+ down: the row would come back visible on a Source/Name change.
812
+ */
813
+ test('A tabular row highlight survives a DynamicColumns re-render', (fDone) =>
814
+ {
815
+ bootstrap(makeVisibilityApp(), (_Pict) =>
816
+ {
817
+ let tmpView = _Pict.views['PictSectionForm-Class'];
818
+ let tmpGroup = tmpView.sectionDefinition.Groups[0];
819
+ let tmpBehaviors = _Pict.providers.DynamicFormSolverBehaviors;
820
+ let fRow = () => document.querySelector(`#GROUP-${tmpView.formID}-Grades tr[data-tabular-row-index="1"]`);
821
+
822
+ paintView(tmpView);
823
+ Expect(fRow()).to.not.equal(null, 'the row painted');
824
+
825
+ tmpBehaviors.highlightTabularRow('Class', 'Grades', 1, 1, 'is-flagged');
826
+ Expect(fRow().className).to.contain('is-flagged', 'baseline: row highlighted');
827
+
828
+ _Pict.AppData.Assignments[0].Title = 'Renamed';
829
+ _Pict.providers['Pict-Layout-Tabular'].onDataMarshalToForm(tmpView, tmpGroup);
830
+
831
+ Expect(fRow()).to.not.equal(null, 'the row re-painted');
832
+ Expect(fRow().className).to.contain('is-flagged', 'the highlight survived the re-render');
833
+ }, fDone);
834
+ });
835
+
836
+ test('A highlight that was turned back off stays off across a re-render', (fDone) =>
837
+ {
838
+ bootstrap(makeVisibilityApp(), (_Pict) =>
839
+ {
840
+ let tmpView = _Pict.views['PictSectionForm-Class'];
841
+ let tmpGroup = tmpView.sectionDefinition.Groups[0];
842
+ let tmpBehaviors = _Pict.providers.DynamicFormSolverBehaviors;
843
+ let fRow = () => document.querySelector(`#GROUP-${tmpView.formID}-Grades tr[data-tabular-row-index="1"]`);
844
+
845
+ paintView(tmpView);
846
+ tmpBehaviors.highlightTabularRow('Class', 'Grades', 1, 1, 'is-flagged');
847
+ tmpBehaviors.highlightTabularRow('Class', 'Grades', 1, 0, 'is-flagged');
848
+
849
+ _Pict.AppData.Assignments[0].Title = 'Renamed';
850
+ _Pict.providers['Pict-Layout-Tabular'].onDataMarshalToForm(tmpView, tmpGroup);
851
+
852
+ Expect(fRow().className).to.not.contain('is-flagged', 'a cleared highlight must not come back');
853
+ }, fDone);
854
+ });
855
+
856
+ test('Re-highlighting the same row does not accumulate registry entries', (fDone) =>
857
+ {
858
+ bootstrap(makeVisibilityApp(), (_Pict) =>
859
+ {
860
+ let tmpView = _Pict.views['PictSectionForm-Class'];
861
+ let tmpBehaviors = _Pict.providers.DynamicFormSolverBehaviors;
862
+ paintView(tmpView);
863
+
864
+ for (let i = 0; i < 5; i++)
865
+ {
866
+ tmpBehaviors.highlightTabularRow('Class', 'Grades', 1, 1, 'is-flagged');
867
+ }
868
+ let tmpKeys = Object.keys(tmpBehaviors.decorationState).filter((pKey) => pKey.indexOf('Class::Grades::row::1::is-flagged') === 0);
869
+ Expect(tmpKeys.length).to.equal(1, 'keyed by target, so repeats overwrite');
870
+ }, fDone);
871
+ });
872
+
873
+ test('Decorations recorded against another section are not replayed here', (fDone) =>
874
+ {
875
+ bootstrap(makeVisibilityApp(), (_Pict) =>
876
+ {
877
+ let tmpView = _Pict.views['PictSectionForm-Class'];
878
+ let tmpBehaviors = _Pict.providers.DynamicFormSolverBehaviors;
879
+ paintView(tmpView);
880
+
881
+ let tmpCalls = [];
882
+ let tmpOriginal = tmpBehaviors.highlightTabularRow;
883
+ tmpBehaviors.decorationState['SomeOtherSection::Grid::row::0::is-flagged'] =
884
+ { Section: 'SomeOtherSection', Method: 'highlightTabularRow', Arguments: [ 'SomeOtherSection', 'Grid', 0, 1, 'is-flagged' ] };
885
+ tmpBehaviors.highlightTabularRow = function () { tmpCalls.push(Array.from(arguments)); return true; };
886
+ try
887
+ {
888
+ tmpBehaviors.reapplySectionDecorations('Class');
889
+ }
890
+ finally
891
+ {
892
+ tmpBehaviors.highlightTabularRow = tmpOriginal;
893
+ }
894
+
895
+ Expect(tmpCalls.length).to.equal(0, 'replay is scoped to the rendered section');
896
+ }, fDone);
897
+ });
898
+
899
+ test('A section with no recorded visibility is left exactly as the template rendered it', (fDone) =>
900
+ {
901
+ bootstrap(makeVisibilityApp(), (_Pict) =>
902
+ {
903
+ let tmpView = _Pict.views['PictSectionForm-Class'];
904
+ let tmpGroup = tmpView.sectionDefinition.Groups[0];
905
+ let fSection = () => document.querySelector(`#SECTION-${tmpView.formID}`);
906
+
907
+ paintView(tmpView);
908
+ let tmpBaseline = fSection().className;
909
+
910
+ _Pict.AppData.Assignments[0].Title = 'Renamed';
911
+ _Pict.providers['Pict-Layout-Tabular'].onDataMarshalToForm(tmpView, tmpGroup);
912
+
913
+ Expect(fSection().className).to.equal(tmpBaseline,
914
+ 'forms that never call the visibility solvers are untouched');
915
+ }, fDone);
916
+ });
917
+
699
918
  test('Steady-state re-run reports neither changed nor namesChanged', (fDone) =>
700
919
  {
701
920
  let App = makeApplication({