FEATURE: Show a confirmation modal when "Dismiss all" would dismiss an important notification (#14935)

* Show a confirmation when dismiss all will dismiss an important notification
This commit is contained in:
Natalie Tay
2021-11-17 09:44:30 +08:00
committed by GitHub
parent 515acb8fc4
commit c61d47e6f4
3 changed files with 107 additions and 1 deletions
@@ -0,0 +1,79 @@
import { click, visit } from "@ember/test-helpers";
import {
acceptance,
exists,
query,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
import pretender from "../helpers/create-pretender";
acceptance("Dismiss notification confirmation", function (needs) {
needs.user();
test("does not show modal when no high priority notifications", async function (assert) {
pretender.put("/notifications/mark-read", () => {
return [200, { "Content-Type": "application/json" }, { success: true }];
});
await visit("/");
await click(".current-user");
await click(".notifications-dismiss");
assert.notOk(exists(".bootbox.modal"));
});
test("shows confirmation modal", async function (assert) {
updateCurrentUser({
unread_high_priority_notifications: 2,
});
await visit("/");
await click(".current-user");
await click(".notifications-dismiss");
assert.ok(exists(".bootbox.modal"));
assert.strictEqual(
query(".bootbox.modal .modal-body").innerText,
"You have 2 important notifications, are you sure you would like to dismiss?"
);
await click(".bootbox.modal .btn-default");
});
test("marks unread when confirm and closes modal", async function (assert) {
updateCurrentUser({
unread_high_priority_notifications: 2,
});
await visit("/");
await click(".current-user");
await click(".notifications-dismiss");
assert.strictEqual(
query(".bootbox.modal .btn-primary span").innerText,
"Confirm"
);
pretender.put("/notifications/mark-read", () => {
return [200, { "Content-Type": "application/json" }, { success: true }];
});
await click(".bootbox.modal .btn-primary");
assert.notOk(exists(".bootbox.modal"));
});
test("marks unread when cancel and closes modal", async function (assert) {
updateCurrentUser({
unread_high_priority_notifications: 2,
});
await visit("/");
await click(".current-user");
await click(".notifications-dismiss");
assert.strictEqual(
query(".bootbox.modal .btn-default span").innerText,
"Cancel"
);
await click(".bootbox.modal .btn-default");
assert.notOk(exists(".bootbox.modal"));
});
});