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.
109 lines
3.2 KiB
JavaScript
109 lines
3.2 KiB
JavaScript
import {
|
|
acceptance,
|
|
exists,
|
|
queryAll,
|
|
} from "discourse/tests/helpers/qunit-helpers";
|
|
import { click, visit } from "@ember/test-helpers";
|
|
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
|
import { test } from "qunit";
|
|
|
|
acceptance("User notification schedule", function (needs) {
|
|
needs.user();
|
|
|
|
test("the schedule interface is hidden until enabled", async function (assert) {
|
|
await visit("/u/eviltrout/preferences/notifications");
|
|
|
|
assert.ok(
|
|
!exists(".notification-schedule-table"),
|
|
"notification schedule is hidden"
|
|
);
|
|
await click(".control-group.notification-schedule input");
|
|
assert.ok(
|
|
exists(".notification-schedule-table"),
|
|
"notification schedule is visible"
|
|
);
|
|
});
|
|
|
|
test("By default every day is selected 8:00am - 5:00pm", async function (assert) {
|
|
await visit("/u/eviltrout/preferences/notifications");
|
|
await click(".control-group.notification-schedule input");
|
|
|
|
[
|
|
"Monday",
|
|
"Tuesday",
|
|
"Wednesday",
|
|
"Thursday",
|
|
"Friday",
|
|
"Saturday",
|
|
"Sunday",
|
|
].forEach((day) => {
|
|
assert.equal(
|
|
selectKit(`.day.${day} .starts-at .combobox`).header().label(),
|
|
"8:00 AM",
|
|
"8am is selected"
|
|
);
|
|
assert.equal(
|
|
selectKit(`.day.${day} .starts-at .combobox`).header().value(),
|
|
"480",
|
|
"8am is 480"
|
|
);
|
|
assert.equal(
|
|
selectKit(`.day.${day} .ends-at .combobox`).header().label(),
|
|
"5:00 PM",
|
|
"5am is selected"
|
|
);
|
|
assert.equal(
|
|
selectKit(`.day.${day} .ends-at .combobox`).header().value(),
|
|
"1020",
|
|
"5pm is 1020"
|
|
);
|
|
});
|
|
});
|
|
|
|
test("If 'none' is selected for the start time, end time dropdown is removed", async function (assert) {
|
|
await visit("/u/eviltrout/preferences/notifications");
|
|
await click(".control-group.notification-schedule input");
|
|
|
|
await selectKit(".day.Monday .combobox").expand();
|
|
await selectKit(".day.Monday .combobox").selectRowByValue(-1);
|
|
|
|
assert.equal(
|
|
selectKit(".day.Monday .starts-at .combobox").header().value(),
|
|
"-1",
|
|
"set monday input to none"
|
|
);
|
|
assert.equal(
|
|
selectKit(".day.Monday .starts-at .combobox").header().label(),
|
|
"None",
|
|
"set monday label to none"
|
|
);
|
|
assert.equal(
|
|
queryAll(".day.Monday .select-kit.single-select").length,
|
|
1,
|
|
"The end time input is hidden"
|
|
);
|
|
});
|
|
|
|
test("If start time is after end time, end time gets bumped 30 minutes past start time", async function (assert) {
|
|
await visit("/u/eviltrout/preferences/notifications");
|
|
await click(".control-group.notification-schedule input");
|
|
|
|
await selectKit(".day.Tuesday .starts-at .combobox").expand();
|
|
await selectKit(".day.Tuesday .starts-at .combobox").selectRowByValue(
|
|
"1350"
|
|
);
|
|
|
|
assert.equal(
|
|
selectKit(".day.Tuesday .ends-at .combobox").header().value(),
|
|
"1380",
|
|
"End time is 30 past start time"
|
|
);
|
|
|
|
await selectKit(".day.Tuesday .ends-at .combobox").expand();
|
|
assert.ok(
|
|
!selectKit(".day.Tuesday .ends-at .combobox").rowByValue(1350).exists(),
|
|
"End time options are limited to + 30 past start time"
|
|
);
|
|
});
|
|
});
|