pict-section-form 1.3.13 → 1.3.14
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/input_providers/012-tab-group-selector.md +3 -1
- package/docs/input_providers/013-tab-section-selector.md +3 -1
- package/package.json +1 -1
- package/source/providers/inputs/Pict-Provider-Input-TabGroupSelector.js +42 -3
- package/source/providers/inputs/Pict-Provider-Input-TabSectionSelector.js +42 -3
- package/test/Pict-Provider-Input-TabGroupSelector-TabHashValidation_tests.js +178 -0
- package/test/Pict-Provider-Input-TabSectionSelector-TabHashValidation_tests.js +193 -0
|
@@ -84,7 +84,7 @@ Fallback default tab when value is empty:
|
|
|
84
84
|
1. Generates tab button HTML
|
|
85
85
|
2. Assigns to container element
|
|
86
86
|
3. Applies CSS snippets for show/hide behavior
|
|
87
|
-
4. Sets default tab
|
|
87
|
+
4. Sets the default tab: the stored value (unless `DefaultFromData` is false), else `DefaultTabGroupHash`, else the first tab. Hashes not in `TabGroupSet` are skipped.
|
|
88
88
|
|
|
89
89
|
### setCSSSnippets
|
|
90
90
|
|
|
@@ -98,6 +98,8 @@ Core method that:
|
|
|
98
98
|
3. Updates tab button styling
|
|
99
99
|
4. Updates input value
|
|
100
100
|
|
|
101
|
+
Returns `true` once the tab is shown, and `false` without changing anything if the view, input or `TabGroupSet` is missing or the hash is not in `TabGroupSet`.
|
|
102
|
+
|
|
101
103
|
## Example: Complete Configuration
|
|
102
104
|
|
|
103
105
|
```json
|
|
@@ -84,7 +84,7 @@ Fallback default section when value is empty:
|
|
|
84
84
|
1. Resolves section hashes to view hashes via metacontroller
|
|
85
85
|
2. Generates tab button HTML
|
|
86
86
|
3. Applies CSS for visibility control
|
|
87
|
-
4. Sets default section
|
|
87
|
+
4. Sets the default section: the stored value (unless `DefaultFromData` is false), else `DefaultTabSectionHash`, else the first section. Hashes not in `TabSectionSet` are skipped.
|
|
88
88
|
|
|
89
89
|
### getViewHash
|
|
90
90
|
|
|
@@ -99,6 +99,8 @@ Core method that:
|
|
|
99
99
|
3. Updates tab button styling
|
|
100
100
|
4. Updates input value
|
|
101
101
|
|
|
102
|
+
Returns `true` once the section is shown, and `false` without changing anything if the view, input, `TabSectionSet` or section view is missing or the hash is not in `TabSectionSet`.
|
|
103
|
+
|
|
102
104
|
## Example: Multi-Page Form
|
|
103
105
|
|
|
104
106
|
```json
|
package/package.json
CHANGED
|
@@ -70,12 +70,26 @@ class CustomInputHandler extends libPictSectionInputExtension
|
|
|
70
70
|
return `#GROUP-${pView.formID}-${pGroupHash}`;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Is this tab group hash actually one of the input's tabs?
|
|
75
|
+
*
|
|
76
|
+
* @param {Object} pInput - The input object.
|
|
77
|
+
* @param {string} pTabGroupHash - The tab group hash to test.
|
|
78
|
+
*
|
|
79
|
+
* @return {boolean}
|
|
80
|
+
*/
|
|
81
|
+
isTabInSet(pInput, pTabGroupHash)
|
|
82
|
+
{
|
|
83
|
+
let tmpTabSet = pInput?.PictForm?.TabGroupSet;
|
|
84
|
+
return !!pTabGroupHash && Array.isArray(tmpTabSet) && (tmpTabSet.indexOf(pTabGroupHash) > -1);
|
|
85
|
+
}
|
|
86
|
+
|
|
73
87
|
/**
|
|
74
88
|
* @param {string} pViewHash
|
|
75
89
|
* @param {string} pInputHash
|
|
76
90
|
* @param {string} pTabHash
|
|
77
91
|
*
|
|
78
|
-
* @return {boolean}
|
|
92
|
+
* @return {boolean} - true once the tab is shown; false (nothing changed) if the view, input or tab hash is not valid.
|
|
79
93
|
*/
|
|
80
94
|
selectTabByViewHash(pViewHash, pInputHash, pTabHash)
|
|
81
95
|
{
|
|
@@ -101,6 +115,14 @@ class CustomInputHandler extends libPictSectionInputExtension
|
|
|
101
115
|
return false;
|
|
102
116
|
}
|
|
103
117
|
|
|
118
|
+
// A hash that is not in the set matches nothing below, so it would hide EVERY group and leave no
|
|
119
|
+
// tab selected. Refuse it without touching anything; false already means "did not switch".
|
|
120
|
+
if (!this.isTabInSet(tmpInput, pTabHash))
|
|
121
|
+
{
|
|
122
|
+
this.pict.log.warn(`TabSelector input provider was asked for tab [${pTabHash}] on view [${pViewHash}] input [${pInputHash}] but it is not in the TabGroupSet; leaving the current tab selected.`);
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
|
|
104
126
|
for (let i = 0; i < tmpInput.PictForm.TabGroupSet.length; i++)
|
|
105
127
|
{
|
|
106
128
|
let tmpTabGroupHash = tmpInput.PictForm.TabGroupSet[i];
|
|
@@ -166,8 +188,25 @@ class CustomInputHandler extends libPictSectionInputExtension
|
|
|
166
188
|
// TODO: Fix typescript types so this function has an optional rather than required fourth parameter.
|
|
167
189
|
this.pict.ContentAssignment.projectContent('replace', this.getTabSelectorInputHTMLID(pInput.Macro.RawHTMLID), tmpTabGroupSetEntries, 'FixTheTypescriptTypes');
|
|
168
190
|
|
|
169
|
-
// Now set the default tab (or first one)
|
|
170
|
-
|
|
191
|
+
// Now set the default tab (or first one). Take the first candidate that is actually one of this
|
|
192
|
+
// input's tabs, since selectTabByViewHash refuses anything else: a stored value can name a group
|
|
193
|
+
// since renamed or dropped from the manifest, and DefaultTabGroupHash can simply be a typo.
|
|
194
|
+
const tmpTabCandidates = [];
|
|
195
|
+
if (pInput.PictForm?.DefaultFromData !== false)
|
|
196
|
+
{
|
|
197
|
+
tmpTabCandidates.push(pValue);
|
|
198
|
+
}
|
|
199
|
+
tmpTabCandidates.push(pInput.PictForm?.DefaultTabGroupHash);
|
|
200
|
+
|
|
201
|
+
let tmpDefaultTabGroupHash = tmpTabSet[0];
|
|
202
|
+
for (let i = 0; i < tmpTabCandidates.length; i++)
|
|
203
|
+
{
|
|
204
|
+
if (this.isTabInSet(pInput, tmpTabCandidates[i]))
|
|
205
|
+
{
|
|
206
|
+
tmpDefaultTabGroupHash = tmpTabCandidates[i];
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
171
210
|
|
|
172
211
|
this.selectTabByViewHash(pView.Hash, pInput.Hash, tmpDefaultTabGroupHash);
|
|
173
212
|
|
|
@@ -76,12 +76,26 @@ class CustomInputHandler extends libPictSectionInputExtension
|
|
|
76
76
|
return `#Pict-${metaController ? metaController.UUID : this.UUID}-${pTabViewSectionHash}-Wrap`;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Is this tab section hash actually one of the input's tabs?
|
|
81
|
+
*
|
|
82
|
+
* @param {Object} pInput - The input object.
|
|
83
|
+
* @param {string} pTabSectionHash - The tab section hash to test.
|
|
84
|
+
*
|
|
85
|
+
* @return {boolean}
|
|
86
|
+
*/
|
|
87
|
+
isTabInSet(pInput, pTabSectionHash)
|
|
88
|
+
{
|
|
89
|
+
let tmpTabSet = pInput?.PictForm?.TabSectionSet;
|
|
90
|
+
return !!pTabSectionHash && Array.isArray(tmpTabSet) && (tmpTabSet.indexOf(pTabSectionHash) > -1);
|
|
91
|
+
}
|
|
92
|
+
|
|
79
93
|
/**
|
|
80
94
|
* @param {string} pViewHash
|
|
81
95
|
* @param {string} pInputHash
|
|
82
96
|
* @param {string} pTabViewHash
|
|
83
97
|
*
|
|
84
|
-
* @return {boolean}
|
|
98
|
+
* @return {boolean} - true once the section is shown; false (nothing changed) if the view, input or tab hash is not valid.
|
|
85
99
|
*/
|
|
86
100
|
selectTabByViewHash(pViewHash, pInputHash, pTabViewHash)
|
|
87
101
|
{
|
|
@@ -106,6 +120,13 @@ class CustomInputHandler extends libPictSectionInputExtension
|
|
|
106
120
|
this.pict.log.error(`TabSelector input provider tried to switch to view [${pViewHash}] input [${pInputHash}] tab [${pTabViewHash}] but the input did not have a valid TabSectionSet array in the PictForm object!`)
|
|
107
121
|
return false;
|
|
108
122
|
}
|
|
123
|
+
// A hash that is not in the set matches nothing below, so it would hide EVERY section and leave no
|
|
124
|
+
// tab selected. Refuse it without touching anything; false already means "did not switch".
|
|
125
|
+
if (!this.isTabInSet(tmpInput, pTabViewHash))
|
|
126
|
+
{
|
|
127
|
+
this.pict.log.warn(`TabSelector input provider was asked for tab [${pTabViewHash}] on view [${pViewHash}] input [${pInputHash}] but it is not in the TabSectionSet; leaving the current tab selected.`);
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
109
130
|
let tmpTabView = this.pict.views[this.getViewHash(pTabViewHash)];
|
|
110
131
|
if (!tmpTabView)
|
|
111
132
|
{
|
|
@@ -180,8 +201,26 @@ class CustomInputHandler extends libPictSectionInputExtension
|
|
|
180
201
|
// TODO: Fix typescript types so this function has an optional rather than required fourth parameter.
|
|
181
202
|
this.pict.ContentAssignment.projectContent('replace', this.getTabSelectorInputHTMLID(pInput.Macro.RawHTMLID), tmpTabSectionSetEntries, 'FixTheTypescriptTypes');
|
|
182
203
|
|
|
183
|
-
// Now set the default tab (or first one)
|
|
184
|
-
|
|
204
|
+
// Now set the default tab (or first one). Take the first candidate that is actually one of this
|
|
205
|
+
// input's tabs, since selectTabByViewHash refuses anything else: a stored value can name a section
|
|
206
|
+
// since renamed or dropped from the manifest, and DefaultTabSectionHash can simply be a typo.
|
|
207
|
+
const tmpTabCandidates = [];
|
|
208
|
+
if (pInput.PictForm?.DefaultFromData !== false)
|
|
209
|
+
{
|
|
210
|
+
tmpTabCandidates.push(pValue);
|
|
211
|
+
}
|
|
212
|
+
tmpTabCandidates.push(pInput.PictForm?.DefaultTabSectionHash);
|
|
213
|
+
|
|
214
|
+
let tmpDefaultTabSectionHash = tmpTabSet[0];
|
|
215
|
+
for (let i = 0; i < tmpTabCandidates.length; i++)
|
|
216
|
+
{
|
|
217
|
+
if (this.isTabInSet(pInput, tmpTabCandidates[i]))
|
|
218
|
+
{
|
|
219
|
+
tmpDefaultTabSectionHash = tmpTabCandidates[i];
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
185
224
|
this.selectTabByViewHash(pView.Hash, pInput.Hash, tmpDefaultTabSectionHash);
|
|
186
225
|
|
|
187
226
|
return super.onInputInitialize(pView, pGroup, pRow, pInput, pValue, pHTMLTabSelector, pTransactionGUID);
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/*
|
|
2
|
+
A tab group hash that is not in the input's TabGroupSet used to be passed straight through:
|
|
3
|
+
selectTabByViewHash matched nothing, hid EVERY group, and left no tab selected -- a section
|
|
4
|
+
rendering as a tab strip over empty space, with the bad value never repaired.
|
|
5
|
+
|
|
6
|
+
Two ways in, both seen in the field: a stored value naming a group that was later renamed or
|
|
7
|
+
dropped from the manifest, and a typo'd DefaultTabGroupHash. These cover both, plus the
|
|
8
|
+
guarantee that a valid hash still wins over the fallback.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const Chai = require('chai');
|
|
12
|
+
const Expect = Chai.expect;
|
|
13
|
+
|
|
14
|
+
const libTabGroupSelector = require('../source/providers/inputs/Pict-Provider-Input-TabGroupSelector.js');
|
|
15
|
+
|
|
16
|
+
const TAB_SET = [ 'GroupOne', 'GroupTwo' ];
|
|
17
|
+
|
|
18
|
+
// The provider without its constructor -- it injects CSS on construction, which these tests
|
|
19
|
+
// neither need nor want.
|
|
20
|
+
function buildProvider(pInput)
|
|
21
|
+
{
|
|
22
|
+
const tmpProvider = Object.create(libTabGroupSelector.prototype);
|
|
23
|
+
tmpProvider.cssHideClass = 'pict-tab-group-hidden';
|
|
24
|
+
tmpProvider.cssSelectedTabClass = 'pict-tab-group-selectedtab';
|
|
25
|
+
tmpProvider.warnings = [];
|
|
26
|
+
tmpProvider.added = [];
|
|
27
|
+
tmpProvider.removed = [];
|
|
28
|
+
tmpProvider.written = [];
|
|
29
|
+
|
|
30
|
+
const tmpView =
|
|
31
|
+
{
|
|
32
|
+
Hash: 'TestSection',
|
|
33
|
+
formID: 'F1',
|
|
34
|
+
getInputFromHash: () => pInput,
|
|
35
|
+
setDataByInput: (pTheInput, pValue) => tmpProvider.written.push(pValue),
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
tmpProvider.pict =
|
|
39
|
+
{
|
|
40
|
+
views: { TestSection: tmpView },
|
|
41
|
+
log:
|
|
42
|
+
{
|
|
43
|
+
warn: (pMessage) => tmpProvider.warnings.push(pMessage),
|
|
44
|
+
error: (pMessage) => tmpProvider.warnings.push(pMessage),
|
|
45
|
+
},
|
|
46
|
+
ContentAssignment:
|
|
47
|
+
{
|
|
48
|
+
addClass: (pSelector, pClass) => tmpProvider.added.push(`${pSelector}|${pClass}`),
|
|
49
|
+
removeClass: (pSelector, pClass) => tmpProvider.removed.push(`${pSelector}|${pClass}`),
|
|
50
|
+
projectContent: () => true,
|
|
51
|
+
},
|
|
52
|
+
providers: { DynamicInput: { getInputTemplateHash: () => 'TabElementTemplate' } },
|
|
53
|
+
parseTemplateByHash: () => '<li></li>',
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
tmpProvider.view = tmpView;
|
|
57
|
+
return tmpProvider;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function buildInput(pPictFormOverrides)
|
|
61
|
+
{
|
|
62
|
+
return {
|
|
63
|
+
Hash: 'TabInput',
|
|
64
|
+
Macro: { RawHTMLID: 'RAW1' },
|
|
65
|
+
PictForm: Object.assign({ TabGroupSet: TAB_SET.slice() }, pPictFormOverrides || {}),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Which group is visible = the one the hide class was REMOVED from.
|
|
70
|
+
function shownGroup(pProvider)
|
|
71
|
+
{
|
|
72
|
+
const tmpShown = pProvider.removed
|
|
73
|
+
.filter((pEntry) => pEntry.indexOf(`|${pProvider.cssHideClass}`) > -1)
|
|
74
|
+
.map((pEntry) => pEntry.split('|')[0]);
|
|
75
|
+
return tmpShown.length === 1 ? tmpShown[0] : tmpShown;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
suite('Pict-Section-Form - TabGroupSelector tab hash validation', () =>
|
|
79
|
+
{
|
|
80
|
+
suite('isTabInSet', () =>
|
|
81
|
+
{
|
|
82
|
+
test('accepts a member and rejects everything else', () =>
|
|
83
|
+
{
|
|
84
|
+
const tmpProvider = buildProvider();
|
|
85
|
+
const tmpInput = buildInput();
|
|
86
|
+
Expect(tmpProvider.isTabInSet(tmpInput, 'GroupTwo')).to.equal(true);
|
|
87
|
+
Expect(tmpProvider.isTabInSet(tmpInput, 'GroupGone')).to.equal(false);
|
|
88
|
+
Expect(tmpProvider.isTabInSet(tmpInput, '')).to.equal(false);
|
|
89
|
+
Expect(tmpProvider.isTabInSet(tmpInput, undefined)).to.equal(false);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('rejects when the input has no usable TabGroupSet', () =>
|
|
93
|
+
{
|
|
94
|
+
const tmpProvider = buildProvider();
|
|
95
|
+
Expect(tmpProvider.isTabInSet(undefined, 'GroupOne')).to.equal(false);
|
|
96
|
+
Expect(tmpProvider.isTabInSet({ PictForm: {} }, 'GroupOne')).to.equal(false);
|
|
97
|
+
Expect(tmpProvider.isTabInSet({ PictForm: { TabGroupSet: 'GroupOne' } }, 'GroupOne')).to.equal(false);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
suite('selectTabByViewHash', () =>
|
|
102
|
+
{
|
|
103
|
+
test('selects a hash that is in the set and stores it', () =>
|
|
104
|
+
{
|
|
105
|
+
const tmpInput = buildInput();
|
|
106
|
+
const tmpProvider = buildProvider(tmpInput);
|
|
107
|
+
Expect(tmpProvider.selectTabByViewHash('TestSection', 'TabInput', 'GroupTwo')).to.equal(true);
|
|
108
|
+
Expect(shownGroup(tmpProvider)).to.equal('#GROUP-F1-GroupTwo');
|
|
109
|
+
Expect(tmpProvider.written).to.deep.equal([ 'GroupTwo' ]);
|
|
110
|
+
Expect(tmpProvider.warnings).to.deep.equal([]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('refuses a hash that is not in the set and changes nothing', () =>
|
|
114
|
+
{
|
|
115
|
+
const tmpInput = buildInput();
|
|
116
|
+
const tmpProvider = buildProvider(tmpInput);
|
|
117
|
+
Expect(tmpProvider.selectTabByViewHash('TestSection', 'TabInput', 'GroupGone')).to.equal(false);
|
|
118
|
+
Expect(tmpProvider.added).to.deep.equal([]);
|
|
119
|
+
Expect(tmpProvider.removed).to.deep.equal([]);
|
|
120
|
+
Expect(tmpProvider.written).to.deep.equal([]);
|
|
121
|
+
Expect(tmpProvider.warnings.length).to.equal(1);
|
|
122
|
+
Expect(tmpProvider.warnings[0]).to.contain('GroupGone');
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('refuses when TabGroupSet is empty', () =>
|
|
126
|
+
{
|
|
127
|
+
const tmpInput = buildInput({ TabGroupSet: [] });
|
|
128
|
+
const tmpProvider = buildProvider(tmpInput);
|
|
129
|
+
Expect(tmpProvider.selectTabByViewHash('TestSection', 'TabInput', 'GroupOne')).to.equal(false);
|
|
130
|
+
Expect(tmpProvider.written).to.deep.equal([]);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
suite('onInputInitialize tab precedence', () =>
|
|
135
|
+
{
|
|
136
|
+
test('uses the stored value when it is in the set', () =>
|
|
137
|
+
{
|
|
138
|
+
const tmpInput = buildInput({ DefaultTabGroupHash: 'GroupOne' });
|
|
139
|
+
const tmpProvider = buildProvider(tmpInput);
|
|
140
|
+
tmpProvider.onInputInitialize(tmpProvider.view, {}, {}, tmpInput, 'GroupTwo', '#SEL', 'TXN');
|
|
141
|
+
Expect(tmpProvider.written).to.deep.equal([ 'GroupTwo' ]);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('skips a stored value that is no longer a tab and uses DefaultTabGroupHash', () =>
|
|
145
|
+
{
|
|
146
|
+
const tmpInput = buildInput({ DefaultTabGroupHash: 'GroupTwo' });
|
|
147
|
+
const tmpProvider = buildProvider(tmpInput);
|
|
148
|
+
tmpProvider.onInputInitialize(tmpProvider.view, {}, {}, tmpInput, 'GroupRenamedAwayLastRelease', '#SEL', 'TXN');
|
|
149
|
+
Expect(shownGroup(tmpProvider)).to.equal('#GROUP-F1-GroupTwo');
|
|
150
|
+
Expect(tmpProvider.written).to.deep.equal([ 'GroupTwo' ]);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test('skips a typo in DefaultTabGroupHash and uses the first tab', () =>
|
|
154
|
+
{
|
|
155
|
+
const tmpInput = buildInput({ DefaultTabGroupHash: 'GruopTwo' });
|
|
156
|
+
const tmpProvider = buildProvider(tmpInput);
|
|
157
|
+
tmpProvider.onInputInitialize(tmpProvider.view, {}, {}, tmpInput, '', '#SEL', 'TXN');
|
|
158
|
+
Expect(shownGroup(tmpProvider)).to.equal('#GROUP-F1-GroupOne');
|
|
159
|
+
Expect(tmpProvider.written).to.deep.equal([ 'GroupOne' ]);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test('DefaultFromData false still ignores the stored value', () =>
|
|
163
|
+
{
|
|
164
|
+
const tmpInput = buildInput({ DefaultFromData: false, DefaultTabGroupHash: 'GroupTwo' });
|
|
165
|
+
const tmpProvider = buildProvider(tmpInput);
|
|
166
|
+
tmpProvider.onInputInitialize(tmpProvider.view, {}, {}, tmpInput, 'GroupOne', '#SEL', 'TXN');
|
|
167
|
+
Expect(tmpProvider.written).to.deep.equal([ 'GroupTwo' ]);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test('errors out unchanged when TabGroupSet is missing', () =>
|
|
171
|
+
{
|
|
172
|
+
const tmpInput = { Hash: 'TabInput', Macro: { RawHTMLID: 'RAW1' }, PictForm: {} };
|
|
173
|
+
const tmpProvider = buildProvider(tmpInput);
|
|
174
|
+
Expect(tmpProvider.onInputInitialize(tmpProvider.view, {}, {}, tmpInput, 'GroupOne', '#SEL', 'TXN')).to.equal(false);
|
|
175
|
+
Expect(tmpProvider.written).to.deep.equal([]);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
});
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/*
|
|
2
|
+
TabSectionSelector twin of the TabGroupSelector tab hash validation. Same two ways in -- a stored
|
|
3
|
+
value naming a section that was later renamed or dropped from the manifest, and a typo'd
|
|
4
|
+
DefaultTabSectionHash -- but two symptoms, because selectTabByViewHash also requires the section's
|
|
5
|
+
view to exist:
|
|
6
|
+
- no such view: an early return, nothing hidden, every tab section stacked on screen;
|
|
7
|
+
- a real section outside TabSectionSet: EVERY tab section hidden, and the bad value stored.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const Chai = require('chai');
|
|
11
|
+
const Expect = Chai.expect;
|
|
12
|
+
|
|
13
|
+
const libTabSectionSelector = require('../source/providers/inputs/Pict-Provider-Input-TabSectionSelector.js');
|
|
14
|
+
|
|
15
|
+
const TAB_SET = [ 'SectionOne', 'SectionTwo' ];
|
|
16
|
+
|
|
17
|
+
// The provider without its constructor -- it registers CSS on construction, which these tests
|
|
18
|
+
// neither need nor want.
|
|
19
|
+
function buildProvider(pInput)
|
|
20
|
+
{
|
|
21
|
+
const tmpProvider = Object.create(libTabSectionSelector.prototype);
|
|
22
|
+
tmpProvider.cssHideClass = 'pict-tab-section-hidden';
|
|
23
|
+
tmpProvider.cssSelectedTabClass = 'pict-tab-section-selectedtab';
|
|
24
|
+
tmpProvider.warnings = [];
|
|
25
|
+
tmpProvider.added = [];
|
|
26
|
+
tmpProvider.removed = [];
|
|
27
|
+
tmpProvider.written = [];
|
|
28
|
+
|
|
29
|
+
const tmpView =
|
|
30
|
+
{
|
|
31
|
+
Hash: 'NavigationView',
|
|
32
|
+
getInputFromHash: () => pInput,
|
|
33
|
+
setDataByInput: (pTheInput, pValue) => tmpProvider.written.push(pValue),
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
tmpProvider.pict =
|
|
37
|
+
{
|
|
38
|
+
views:
|
|
39
|
+
{
|
|
40
|
+
NavigationView: tmpView,
|
|
41
|
+
PictFormMetacontroller: { UUID: 'MC' },
|
|
42
|
+
// Every section has a view -- Navigation too, though it is not one of the tabs.
|
|
43
|
+
'PictSectionForm-SectionOne': {},
|
|
44
|
+
'PictSectionForm-SectionTwo': {},
|
|
45
|
+
'PictSectionForm-Navigation': {},
|
|
46
|
+
},
|
|
47
|
+
log:
|
|
48
|
+
{
|
|
49
|
+
warn: (pMessage) => tmpProvider.warnings.push(pMessage),
|
|
50
|
+
error: (pMessage) => tmpProvider.warnings.push(pMessage),
|
|
51
|
+
},
|
|
52
|
+
ContentAssignment:
|
|
53
|
+
{
|
|
54
|
+
addClass: (pSelector, pClass) => tmpProvider.added.push(`${pSelector}|${pClass}`),
|
|
55
|
+
removeClass: (pSelector, pClass) => tmpProvider.removed.push(`${pSelector}|${pClass}`),
|
|
56
|
+
projectContent: () => true,
|
|
57
|
+
},
|
|
58
|
+
providers: { DynamicInput: { getInputTemplateHash: () => 'TabElementTemplate' } },
|
|
59
|
+
parseTemplateByHash: () => '<li></li>',
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
tmpProvider.view = tmpView;
|
|
63
|
+
return tmpProvider;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function buildInput(pPictFormOverrides)
|
|
67
|
+
{
|
|
68
|
+
return {
|
|
69
|
+
Hash: 'TabInput',
|
|
70
|
+
Macro: { RawHTMLID: 'RAW1' },
|
|
71
|
+
PictForm: Object.assign({ TabSectionSet: TAB_SET.slice() }, pPictFormOverrides || {}),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Which section is visible = the one the hide class was REMOVED from.
|
|
76
|
+
function shownSection(pProvider)
|
|
77
|
+
{
|
|
78
|
+
const tmpShown = pProvider.removed
|
|
79
|
+
.filter((pEntry) => pEntry.indexOf(`|${pProvider.cssHideClass}`) > -1)
|
|
80
|
+
.map((pEntry) => pEntry.split('|')[0]);
|
|
81
|
+
return tmpShown.length === 1 ? tmpShown[0] : tmpShown;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
suite('Pict-Section-Form - TabSectionSelector tab hash validation', () =>
|
|
85
|
+
{
|
|
86
|
+
suite('isTabInSet', () =>
|
|
87
|
+
{
|
|
88
|
+
test('accepts a member and rejects everything else', () =>
|
|
89
|
+
{
|
|
90
|
+
const tmpProvider = buildProvider();
|
|
91
|
+
const tmpInput = buildInput();
|
|
92
|
+
Expect(tmpProvider.isTabInSet(tmpInput, 'SectionTwo')).to.equal(true);
|
|
93
|
+
Expect(tmpProvider.isTabInSet(tmpInput, 'Navigation')).to.equal(false);
|
|
94
|
+
Expect(tmpProvider.isTabInSet(tmpInput, '')).to.equal(false);
|
|
95
|
+
Expect(tmpProvider.isTabInSet(tmpInput, undefined)).to.equal(false);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('rejects when the input has no usable TabSectionSet', () =>
|
|
99
|
+
{
|
|
100
|
+
const tmpProvider = buildProvider();
|
|
101
|
+
Expect(tmpProvider.isTabInSet(undefined, 'SectionOne')).to.equal(false);
|
|
102
|
+
Expect(tmpProvider.isTabInSet({ PictForm: {} }, 'SectionOne')).to.equal(false);
|
|
103
|
+
Expect(tmpProvider.isTabInSet({ PictForm: { TabSectionSet: 'SectionOne' } }, 'SectionOne')).to.equal(false);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
suite('selectTabByViewHash', () =>
|
|
108
|
+
{
|
|
109
|
+
test('selects a hash that is in the set and stores it', () =>
|
|
110
|
+
{
|
|
111
|
+
const tmpInput = buildInput();
|
|
112
|
+
const tmpProvider = buildProvider(tmpInput);
|
|
113
|
+
Expect(tmpProvider.selectTabByViewHash('NavigationView', 'TabInput', 'SectionTwo')).to.equal(true);
|
|
114
|
+
Expect(shownSection(tmpProvider)).to.equal('#Pict-MC-SectionTwo-Wrap');
|
|
115
|
+
Expect(tmpProvider.written).to.deep.equal([ 'SectionTwo' ]);
|
|
116
|
+
Expect(tmpProvider.warnings).to.deep.equal([]);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('refuses a real section that is not one of the tabs and changes nothing', () =>
|
|
120
|
+
{
|
|
121
|
+
const tmpInput = buildInput();
|
|
122
|
+
const tmpProvider = buildProvider(tmpInput);
|
|
123
|
+
Expect(tmpProvider.selectTabByViewHash('NavigationView', 'TabInput', 'Navigation')).to.equal(false);
|
|
124
|
+
Expect(tmpProvider.added).to.deep.equal([]);
|
|
125
|
+
Expect(tmpProvider.removed).to.deep.equal([]);
|
|
126
|
+
Expect(tmpProvider.written).to.deep.equal([]);
|
|
127
|
+
Expect(tmpProvider.warnings.length).to.equal(1);
|
|
128
|
+
Expect(tmpProvider.warnings[0]).to.contain('Navigation');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('refuses when TabSectionSet is empty', () =>
|
|
132
|
+
{
|
|
133
|
+
const tmpInput = buildInput({ TabSectionSet: [] });
|
|
134
|
+
const tmpProvider = buildProvider(tmpInput);
|
|
135
|
+
Expect(tmpProvider.selectTabByViewHash('NavigationView', 'TabInput', 'SectionOne')).to.equal(false);
|
|
136
|
+
Expect(tmpProvider.written).to.deep.equal([]);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
suite('onInputInitialize tab precedence', () =>
|
|
141
|
+
{
|
|
142
|
+
test('uses the stored value when it is in the set', () =>
|
|
143
|
+
{
|
|
144
|
+
const tmpInput = buildInput({ DefaultTabSectionHash: 'SectionOne' });
|
|
145
|
+
const tmpProvider = buildProvider(tmpInput);
|
|
146
|
+
tmpProvider.onInputInitialize(tmpProvider.view, {}, {}, tmpInput, 'SectionTwo', '#SEL', 'TXN');
|
|
147
|
+
Expect(tmpProvider.written).to.deep.equal([ 'SectionTwo' ]);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('skips a stored section dropped from the manifest and uses DefaultTabSectionHash', () =>
|
|
151
|
+
{
|
|
152
|
+
const tmpInput = buildInput({ DefaultTabSectionHash: 'SectionTwo' });
|
|
153
|
+
const tmpProvider = buildProvider(tmpInput);
|
|
154
|
+
tmpProvider.onInputInitialize(tmpProvider.view, {}, {}, tmpInput, 'SectionDroppedLastRelease', '#SEL', 'TXN');
|
|
155
|
+
Expect(shownSection(tmpProvider)).to.equal('#Pict-MC-SectionTwo-Wrap');
|
|
156
|
+
Expect(tmpProvider.written).to.deep.equal([ 'SectionTwo' ]);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('skips a stored value naming a section that is not a tab and uses the first tab', () =>
|
|
160
|
+
{
|
|
161
|
+
const tmpInput = buildInput();
|
|
162
|
+
const tmpProvider = buildProvider(tmpInput);
|
|
163
|
+
tmpProvider.onInputInitialize(tmpProvider.view, {}, {}, tmpInput, 'Navigation', '#SEL', 'TXN');
|
|
164
|
+
Expect(shownSection(tmpProvider)).to.equal('#Pict-MC-SectionOne-Wrap');
|
|
165
|
+
Expect(tmpProvider.written).to.deep.equal([ 'SectionOne' ]);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('skips a typo in DefaultTabSectionHash and uses the first tab', () =>
|
|
169
|
+
{
|
|
170
|
+
const tmpInput = buildInput({ DefaultTabSectionHash: 'SectoinTwo' });
|
|
171
|
+
const tmpProvider = buildProvider(tmpInput);
|
|
172
|
+
tmpProvider.onInputInitialize(tmpProvider.view, {}, {}, tmpInput, '', '#SEL', 'TXN');
|
|
173
|
+
Expect(shownSection(tmpProvider)).to.equal('#Pict-MC-SectionOne-Wrap');
|
|
174
|
+
Expect(tmpProvider.written).to.deep.equal([ 'SectionOne' ]);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('DefaultFromData false still ignores the stored value', () =>
|
|
178
|
+
{
|
|
179
|
+
const tmpInput = buildInput({ DefaultFromData: false, DefaultTabSectionHash: 'SectionTwo' });
|
|
180
|
+
const tmpProvider = buildProvider(tmpInput);
|
|
181
|
+
tmpProvider.onInputInitialize(tmpProvider.view, {}, {}, tmpInput, 'SectionOne', '#SEL', 'TXN');
|
|
182
|
+
Expect(tmpProvider.written).to.deep.equal([ 'SectionTwo' ]);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test('errors out unchanged when TabSectionSet is missing', () =>
|
|
186
|
+
{
|
|
187
|
+
const tmpInput = { Hash: 'TabInput', Macro: { RawHTMLID: 'RAW1' }, PictForm: {} };
|
|
188
|
+
const tmpProvider = buildProvider(tmpInput);
|
|
189
|
+
Expect(tmpProvider.onInputInitialize(tmpProvider.view, {}, {}, tmpInput, 'SectionOne', '#SEL', 'TXN')).to.equal(false);
|
|
190
|
+
Expect(tmpProvider.written).to.deep.equal([]);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
});
|