|
1549 | 1549 | // that only 2 controls changed. |
1550 | 1550 | // 3) Refresh all controls before this loop and verify that they |
1551 | 1551 | // 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 | + } |
1553 | 1564 | // Check each control |
1554 | 1565 | for (n = 0, m = controls.length; n < m; n++) { |
1555 | 1566 | // Get the html for the control and remove all spaces and line breaks |
|
1600 | 1611 | app.models.unitTestControls.values = ['abcd', 'xyz']; |
1601 | 1612 | // Refresh two controls |
1602 | 1613 | // 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 | + }); |
1606 | 1620 | } else if (x === 1) { |
1607 | | - app.refreshAllHtmlControls(); |
| 1621 | + app.refreshAllHtmlControls(controlLoopCheck); |
1608 | 1622 | } |
1609 | 1623 | } |
| 1624 | + controlLoopCheck(); |
1610 | 1625 |
|
1611 | 1626 | // Expected Templates to be compiled and downloaded |
1612 | 1627 | // This number should be fixed regardless of how many additional |
|
1818 | 1833 | return 'Error with Element <div id="' + id + '" class=""> - ' + expectedMessage; |
1819 | 1834 | } |
1820 | 1835 |
|
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 |
1822 | 1837 | for (n = 0; n < 2; n++) { |
1823 | 1838 | // Invalid Callback |
1824 | 1839 | expectedMessage = '[callback] was not defined as a [function] when the [DataFormsJS.refreshHtmlControl()] was called'; |
|
0 commit comments