This adds a new table UserNotificationSchedules which stores monday-friday start and ends times that each user would like to receive notifications (with a Boolean enabled to remove the use of the schedule). There is then a background job that runs every day and creates do_not_disturb_timings for each user with an enabled notification schedule. The job schedules timings 2 days in advance. The job is designed so that it can be run at any point in time, and it will not create duplicate records. When a users saves their notification schedule, the schedule processing service will run and schedule do_not_disturb_timings. If the user should be in DND due to their schedule, the user will immediately be put in DND (message bus publishes this state). The UI for a user's notification schedule is in user -> preferences -> notifications. By default every day is 8am - 5pm when first enabled.
71 lines
1.9 KiB
JavaScript
71 lines
1.9 KiB
JavaScript
import {
|
|
acceptance,
|
|
exists,
|
|
queryAll,
|
|
updateCurrentUser,
|
|
} from "discourse/tests/helpers/qunit-helpers";
|
|
import { click, visit } from "@ember/test-helpers";
|
|
import { test } from "qunit";
|
|
|
|
acceptance("Do not disturb", function (needs) {
|
|
needs.user();
|
|
needs.pretender((server, helper) => {
|
|
server.post("/do-not-disturb.json", () => {
|
|
let now = new Date();
|
|
now.setHours(now.getHours() + 1);
|
|
return helper.response({ ends_at: now });
|
|
});
|
|
server.delete("/do-not-disturb.json", () =>
|
|
helper.response({ success: true })
|
|
);
|
|
});
|
|
|
|
test("when turned off, it is turned on from modal", async function (assert) {
|
|
updateCurrentUser({ do_not_disturb_until: null });
|
|
|
|
await visit("/");
|
|
await click(".header-dropdown-toggle.current-user");
|
|
await click(".menu-links-row .user-preferences-link");
|
|
|
|
await click(".do-not-disturb");
|
|
|
|
assert.ok(exists(".do-not-disturb-modal"), "modal to choose time appears");
|
|
|
|
let tiles = queryAll(".do-not-disturb-tile");
|
|
assert.ok(tiles.length === 4, "There are 4 duration choices");
|
|
|
|
await click(tiles[0]);
|
|
|
|
assert.ok(
|
|
queryAll(".do-not-disturb-modal")[0].style.display === "none",
|
|
"modal is hidden"
|
|
);
|
|
|
|
assert.ok(
|
|
exists(".header-dropdown-toggle .do-not-disturb-background"),
|
|
"moon icon is present in header"
|
|
);
|
|
});
|
|
|
|
test("when turned on, it can be turned off", async function (assert) {
|
|
let now = new Date();
|
|
now.setHours(now.getHours() + 1);
|
|
updateCurrentUser({ do_not_disturb_until: now });
|
|
|
|
await visit("/");
|
|
await click(".header-dropdown-toggle.current-user");
|
|
await click(".menu-links-row .user-preferences-link");
|
|
assert.equal(
|
|
queryAll(".do-not-disturb .relative-date")[0].textContent,
|
|
"1h"
|
|
);
|
|
|
|
await click(".do-not-disturb");
|
|
|
|
assert.ok(
|
|
queryAll(".do-not-disturb-background").length === 0,
|
|
"The active moon icons are removed"
|
|
);
|
|
});
|
|
});
|