From 0de41ee0874162d1e820528115b67747969d0609 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Mon, 19 Jul 2021 21:42:38 +0200 Subject: [PATCH] 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. --- src/tests/frontend/specs/adminsettings.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/tests/frontend/specs/adminsettings.js b/src/tests/frontend/specs/adminsettings.js index da9904ccd..a2ee02046 100644 --- a/src/tests/frontend/specs/adminsettings.js +++ b/src/tests/frontend/specs/adminsettings.js @@ -21,6 +21,16 @@ describe('Admin > Settings', function () { }); it('Are Settings visible, populated, does save work', async function () { + const save = async () => { + const p = new Promise((resolve) => { + const observer = new MutationObserver(() => { resolve(); observer.disconnect(); }); + observer.observe( + helper.admin$('#response')[0], {attributes: true, childList: false, subtree: false}); + }); + helper.admin$('#saveSettings').click(); + await p; + }; + // save old value const settings = helper.admin$('.settings').val(); const settingsLength = settings.length; @@ -29,10 +39,7 @@ describe('Admin > Settings', function () { helper.admin$('.settings').val((_, text) => `/* test */\n${text}`); await helper.waitForPromise( () => settingsLength + 11 === helper.admin$('.settings').val().length, 5000); - - // saves - helper.admin$('#saveSettings').click(); - await helper.waitForPromise(() => helper.admin$('#response').is(':visible'), 5000); + await save(); // new value for settings.json should now be saved // reset it to the old value @@ -44,9 +51,7 @@ describe('Admin > Settings', function () { // replace the test value with a line break helper.admin$('.settings').val((_, text) => text.replace('/* test */\n', '')); await helper.waitForPromise(() => settingsLength === helper.admin$('.settings').val().length); - - helper.admin$('#saveSettings').click(); // saves - await helper.waitForPromise(() => helper.admin$('#response').is(':visible')); + await save(); // settings should have the old value helper.newAdmin('settings');