adminsettings test: 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.
fix-adminupdateplugins
webzwo0i 2021-07-19 21:42:38 +02:00
parent ef829960ca
commit e4c9731441
1 changed files with 23 additions and 2 deletions

View File

@ -3,6 +3,19 @@
describe('Admin > Settings', function () {
this.timeout(480000);
let savedProgressReceived;
let observer;
// observes the #response element' attributes for changes
const observerJob = () => {
savedProgressReceived = false;
const observerCallback = (mutations, observer) => {
savedProgressReceived = true;
};
observer = new MutationObserver(observerCallback);
observer.observe(helper.admin$('#response')[0],
{attributes: true, childList: false, subtree: false});
};
before(async function () {
let success = false;
$.ajax({
@ -20,6 +33,7 @@ describe('Admin > Settings', function () {
() => helper.admin$ && helper.admin$('.settings').val().length > 0, 5000);
});
it('Are Settings visible, populated, does save work', async function () {
// save old value
const settings = helper.admin$('.settings').val();
@ -30,9 +44,14 @@ describe('Admin > Settings', function () {
await helper.waitForPromise(
() => settingsLength + 11 === helper.admin$('.settings').val().length, 5000);
observerJob();
// saves
helper.admin$('#saveSettings').click();
await helper.waitForPromise(() => helper.admin$('#response').is(':visible'), 5000);
await helper.waitForPromise(() => savedProgressReceived, 5000);
// reset because we need to call it again later on
savedProgressReceived = false;
observer.disconnect();
// new value for settings.json should now be saved
// reset it to the old value
@ -45,8 +64,10 @@ describe('Admin > Settings', function () {
helper.admin$('.settings').val((_, text) => text.replace('/* test */\n', ''));
await helper.waitForPromise(() => settingsLength === helper.admin$('.settings').val().length);
observerJob();
helper.admin$('#saveSettings').click(); // saves
await helper.waitForPromise(() => helper.admin$('#response').is(':visible'));
await helper.waitForPromise(() => savedProgressReceived, 5000);
observer.disconnect();
// settings should have the old value
helper.newAdmin('settings');