Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Changelog

* 6.0.5 - Updated translations
* 6.0.5 - Updated translations. Fixed duplicate alerts being created when the Save button was clicked several times while saving
* 6.0.4 - 2026-11-30 - Improved validation of the alert ID in `CustomAlerts.getAlert`, `CustomAlerts.editAlert`, `CustomAlerts.deleteAlert` and `CustomAlerts.getValuesForAlertInPast`; a non-integer alert ID is now rejected with HTTP 400. Answered requests for another user's alert with HTTP 404, the same as for a missing alert, instead of HTTP 403, except for a superuser, who can list every user's alerts and is still answered with HTTP 403. Removed alerts left behind by a deleted user when a new user is created with the same login
* 6.0.3 - 2026-11-23 - Updated translations
* 6.0.2 - 2026-11-09 - Answered requests for a missing alert with HTTP 404 and for another user's alert with HTTP 403, instead of HTTP 200 with an error message or HTTP 500. Answered requests with invalid alert settings with HTTP 400, instead of HTTP 200 with an error message or HTTP 500
Expand Down
88 changes: 88 additions & 0 deletions tests/UI/CustomAlerts_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,92 @@ describe("CustomAlerts", function () {
await page.waitForNetworkIdle();
await page.waitForFunction('$(".pageWrap td:contains(\'Test Alert 1 changed\')").length == 0');
});

async function countAlertsNamed(name) {
return page.evaluate(function (alertName) {
return $('.pageWrap tbody tr td.name').filter(function () {
return $(this).text().trim() === alertName;
}).length;
}, name);
}

// picks the first option of a select field whose label contains the given text
async function selectOption(select, label) {
await page.evaluate(function (selector) {
$(selector).closest('.select-wrapper').find('input.select-dropdown').click();
}, select);
await page.waitForTimeout(350); // wait for animation
await page.evaluate(function (selector, text) {
$(selector).closest('.select-wrapper').find('ul.dropdown-content li:not(.disabled) span').filter(function () {
return $(this).children().length === 0 && $(this).text().trim() !== '' && $(this).text().indexOf(text) !== -1;
}).first().closest('li').click();
}, select, label);
await page.keyboard.press('Escape');
await page.waitForTimeout(350); // wait for animation
}

async function openNewAlertForm(name) {
await page.goto("?" + generalParams + "&module=CustomAlerts&action=addNewAlert");
await page.waitForNetworkIdle();
await page.type('#alertName', name);
await selectOption('#report_mediums', 'Email');
await page.click('#report_email_me + span');
await selectOption('#metricCondition', '');
await page.type('#metricValue', '10');
// the fields only pass the typed values on 50ms after the last key
await page.waitForTimeout(250);
}

// saves the form, but holds back the redirect to the list, so the form stays open after the request finished
async function saveWithoutLeavingPage() {
await page.evaluate(function () {
window.piwikHelper.redirectToUrl = function (url) {
window.redirectAfterSave = url;
};
});
await page.click('.matomo-save-button input');
await page.waitForFunction('!!window.redirectAfterSave');
}

it('should create only one alert when save is clicked several times in a row', async function () {
await openNewAlertForm('Rapid Click Alert');

// clicking again before the button re-renders as disabled must not send another request
await Promise.all([
page.waitForNavigation(),
page.evaluate(function () {
var button = $('.matomo-save-button input')[0];
button.click();
button.click();
button.click();
}),
]);
await page.waitForNetworkIdle();

expect(await countAlertsNamed('Rapid Click Alert')).to.equal(1);
});

it('should keep save disabled after the alert was saved until the page has changed', async function () {
await openNewAlertForm('Slow Redirect Alert');

await saveWithoutLeavingPage();

expect(await page.evaluate('$(".matomo-save-button input").is(":disabled")')).to.equal(true);
});

it('should enable save again when the saved form is restored with the back button', async function () {
await openNewAlertForm('Restored Form Alert');

await saveWithoutLeavingPage();

expect(await page.evaluate('$(".matomo-save-button input").is(":disabled")')).to.equal(true);

// what the browser fires when it shows the page again from the back/forward cache
await page.evaluate(function () {
window.dispatchEvent(new PageTransitionEvent('pageshow', { persisted: true }));
});
await page.waitForFunction('!$(".matomo-save-button input").is(":disabled")');

expect(await page.evaluate('$(".matomo-save-button input").is(":disabled")')).to.equal(false);
});
});
Loading
Loading