Skip to content

Commit 0de41ee

Browse files
webzwo0irhansen
authored andcommitted
adminsettings test: Fix save detection race condition
Use MutationObserver to detect if a saveProgress event was received, which will trigger an animation. Before this, `helper.admin$('#response').is(':visible')` was true after the page loaded and before clicking the Save button, so there was a possibility that after clicking Save, but before sending the socketio message to the server, the visibility is checked and returns true, so the page gets reloaded before the changed settings have been saved.
1 parent bb0ca91 commit 0de41ee

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/tests/frontend/specs/adminsettings.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ describe('Admin > Settings', function () {
2121
});
2222

2323
it('Are Settings visible, populated, does save work', async function () {
24+
const save = async () => {
25+
const p = new Promise((resolve) => {
26+
const observer = new MutationObserver(() => { resolve(); observer.disconnect(); });
27+
observer.observe(
28+
helper.admin$('#response')[0], {attributes: true, childList: false, subtree: false});
29+
});
30+
helper.admin$('#saveSettings').click();
31+
await p;
32+
};
33+
2434
// save old value
2535
const settings = helper.admin$('.settings').val();
2636
const settingsLength = settings.length;
@@ -29,10 +39,7 @@ describe('Admin > Settings', function () {
2939
helper.admin$('.settings').val((_, text) => `/* test */\n${text}`);
3040
await helper.waitForPromise(
3141
() => settingsLength + 11 === helper.admin$('.settings').val().length, 5000);
32-
33-
// saves
34-
helper.admin$('#saveSettings').click();
35-
await helper.waitForPromise(() => helper.admin$('#response').is(':visible'), 5000);
42+
await save();
3643

3744
// new value for settings.json should now be saved
3845
// reset it to the old value
@@ -44,9 +51,7 @@ describe('Admin > Settings', function () {
4451
// replace the test value with a line break
4552
helper.admin$('.settings').val((_, text) => text.replace('/* test */\n', ''));
4653
await helper.waitForPromise(() => settingsLength === helper.admin$('.settings').val().length);
47-
48-
helper.admin$('#saveSettings').click(); // saves
49-
await helper.waitForPromise(() => helper.admin$('#response').is(':visible'));
54+
await save();
5055

5156
// settings should have the old value
5257
helper.newAdmin('settings');

0 commit comments

Comments
 (0)