Skip to content

Commit 9974a3f

Browse files
committed
💡 Update Tests and App for nested HTML controls
1 parent 7a01cbe commit 9974a3f

3 files changed

Lines changed: 23 additions & 12 deletions

File tree

js/DataFormsJS.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,7 +2155,7 @@
21552155
* reference a template. This can be used by controller functions to easily
21562156
* update only part of a page.
21572157
*
2158-
* @param {HTMLElement} control
2158+
* @param {HTMLElement|string} control
21592159
* @param {function|undefined} callback
21602160
* @param {object|undefined} model If undefined then [app.activeModel] is used
21612161
*/
@@ -2245,10 +2245,6 @@
22452245
}));
22462246
});
22472247
}
2248-
if (promises.length === 0 && callback !== undefined) {
2249-
callback();
2250-
return;
2251-
}
22522248
Promise.all(promises).finally(function () {
22532249
if (callback !== undefined) {
22542250
callback();

js/DataFormsJS.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/js/unit-testing.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,18 @@
15491549
// that only 2 controls changed.
15501550
// 3) Refresh all controls before this loop and verify that they
15511551
// were all updated.
1552-
for (x = 0; x < 3; x++) {
1552+
//
1553+
// A recursive function is used that mimics the following for loop:
1554+
// for (x = 0; x < 3; x++) {
1555+
// The reason is because `app.refreshHtmlControl(control, callback)` is async
1556+
// using a callback so for correct event order a callback must be used.
1557+
//
1558+
x = -1;
1559+
function controlLoopCheck() {
1560+
x++;
1561+
if (x === 3) {
1562+
return;
1563+
}
15531564
// Check each control
15541565
for (n = 0, m = controls.length; n < m; n++) {
15551566
// Get the html for the control and remove all spaces and line breaks
@@ -1600,13 +1611,17 @@
16001611
app.models.unitTestControls.values = ['abcd', 'xyz'];
16011612
// Refresh two controls
16021613
// One by passing a string for the id value and the
1603-
// other by passing an HTMLElement
1604-
app.refreshHtmlControl(document.querySelector('#controls .control-2'));
1605-
app.refreshHtmlControl('downloaded-control');
1614+
// other by passing an HTMLElement. `refreshHtmlControl()` is async
1615+
// using a callback so wait for each control and then recursively
1616+
// call this function again when complete.
1617+
app.refreshHtmlControl(document.querySelector('#controls .control-2'), function() {
1618+
app.refreshHtmlControl('downloaded-control', controlLoopCheck);
1619+
});
16061620
} else if (x === 1) {
1607-
app.refreshAllHtmlControls();
1621+
app.refreshAllHtmlControls(controlLoopCheck);
16081622
}
16091623
}
1624+
controlLoopCheck();
16101625

16111626
// Expected Templates to be compiled and downloaded
16121627
// This number should be fixed regardless of how many additional
@@ -1818,7 +1833,7 @@
18181833
return 'Error with Element &lt;div id="' + id + '" class=""&gt; - ' + expectedMessage;
18191834
}
18201835

1821-
// Run errors twice, once by refering to string ID and once directly with element
1836+
// Run errors twice, once by referring to string ID and once directly with element
18221837
for (n = 0; n < 2; n++) {
18231838
// Invalid Callback
18241839
expectedMessage = '[callback] was not defined as a [function] when the [DataFormsJS.refreshHtmlControl()] was called';

0 commit comments

Comments
 (0)