Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 5ad8c46

Browse files
committed
webui: Improved approach to ensure the desired status message is shown
1 parent f6f8382 commit 5ad8c46

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

cypress/e2e/1-webui/live_execute_sql.cy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ describe('live execute', () => {
8585
cy.get('[data-cy="formatsqlbtn"]').click()
8686

8787
// Verify the changed text
88+
cy.wait(waitTime)
8889
cy.get('[data-cy="usersqltext"]').should('contain',
8990
'CREATE TABLE\n' +
9091
' livetest1 (field1 INTEGER, field2 TEXT, field3 INTEGER)')

webui/templates/execute.html

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<span class="caret"></span>
2020
</button>
2121
<ul uib-dropdown-menu class="dropdown-menu" role="menu">
22-
<li ng-repeat="exec in execNames" role="menuitem" ng-click="changeExec(exec)" data-cy="exec-{{ exec }}">
22+
<li ng-repeat="exec in execNames" role="menuitem" ng-click="changeExec(exec, true)" data-cy="exec-{{ exec }}">
2323
<a href="">{{ exec }}</a>
2424
</li>
2525
</ul>
@@ -144,20 +144,22 @@ <h4 style="color: {{ statusMessageColour }};" data-cy="statusmsg">&nbsp;{{ statu
144144
};
145145

146146
// Change to a newly selected SQL statement
147-
$scope.changeExec = function(newExec) {
147+
$scope.changeExec = function(newExec, updateMsg) {
148148
// Retrieve the newly chosen SQL statement from the server
149149
$http.get("/x/execget/[[ .DB.Info.Owner ]]/[[ .DB.Info.Database ]]?sqlname="+newExec).then(
150150
function success(response) {
151-
// Clear any existing status message
152-
$scope.statusMessage = "";
151+
if (updateMsg) {
152+
// Clear any existing status message
153+
$scope.statusMessage = "";
154+
}
153155

154156
// Apply the retrieved information
155157
document.getElementById("savename").value = newExec;
156158
$scope.selectedName = newExec;
157159

158160
// We include '.textContent' here now because Cypress (v12.3.0) *refuses* to return the correct
159-
// data if '.value' is used. Instead, Cypress returns old data which of course fails every test
160-
// using it. Everything else (Chromium, FF, etc) is totally fine, returning the correct data.
161+
// data if just '.value' is used. Instead, Cypress returns old data which of course fails every
162+
// test using it. Everything else (Chromium, FF, etc) is totally fine, returning the correct data.
161163
// Cypress itself even *visually displays* the correct data that it should be returning. But no,
162164
// the actual .should() call done by Cypress returns *old* (incorrect) data, causing failures.
163165
// WTF? :(
@@ -167,17 +169,19 @@ <h4 style="color: {{ statusMessageColour }};" data-cy="statusmsg">&nbsp;{{ statu
167169
updateSQL();
168170

169171
}, function failure(response) {
170-
// Retrieving statement text failed, so display the returned error message
171-
$scope.statusMessageColour = "red";
172-
$scope.statusMessage = nowString() + "Retrieving saved SQL failed: " + response.data;
172+
if (updateMsg) {
173+
// Retrieving statement text failed, so display the returned error message
174+
$scope.statusMessageColour = "red";
175+
$scope.statusMessage = nowString() + "Retrieving saved SQL failed: " + response.data;
176+
}
173177
}
174178
)
175179
}
176180

177181
// If there are saved SQL statements but none of them is named "default", then change the Saved SQL drop down
178182
// selector to use the first one
179183
if (($scope.execNames.length > 0) && (!$scope.execNames.includes("default"))) {
180-
$scope.changeExec($scope.execNames[0]);
184+
$scope.changeExec($scope.execNames[0], true);
181185
}
182186

183187
// Deletes a saved SQL statement
@@ -207,12 +211,7 @@ <h4 style="color: {{ statusMessageColour }};" data-cy="statusmsg">&nbsp;{{ statu
207211
let newSelected = $scope.execNames[0];
208212
$scope.selectedName = newSelected;
209213
document.getElementById("savename").value = newSelected;
210-
$scope.changeExec(newSelected);
211-
212-
// We need to set the status message here too, otherwise the ~async changeExec() above
213-
// can overwrite it
214-
$scope.statusMessageColour = "green";
215-
$scope.statusMessage = nowString() + "SQL statement '" + name + "' deleted";
214+
$scope.changeExec(newSelected, false);
216215
}
217216
}
218217

0 commit comments

Comments
 (0)