discourse/test/javascripts/lib/bookmark-test.js
Martin Brennan d7f744490a
FEATURE: Decorate topic-level bookmark button with reminder time (#9426)
* Show the correct bookmark with clock icon when topic-level bookmark reminder time is set and show the time of the reminder in the title on hover.
* Add a new bookmark lib and reminder time formatting function to show time with today/tomorrow shorthand for readability. E.g. tomorrow at 8:00am instead of Apr 16 2020 at 8:00am. This only applies to today + tomorrow, future dates are still treated the same.
2020-04-16 09:20:44 +10:00

52 lines
1.4 KiB
JavaScript

import { formattedReminderTime } from "discourse/lib/bookmark";
QUnit.module("lib:bookmark", {
beforeEach() {
// set the current now time for all tests
let now = moment.tz("2020-04-11 08:00:00", "Australia/Brisbane");
sandbox.useFakeTimers(now.valueOf());
}
});
QUnit.test(
"formattedReminderTime works when the reminder time is tomorrow",
assert => {
let reminderAt = "2020-04-12 09:45:00";
let reminderAtDate = moment
.tz(reminderAt, "Australia/Brisbane")
.format("H:mm a");
assert.equal(
formattedReminderTime(reminderAt, "Australia/Brisbane"),
"tomorrow at " + reminderAtDate
);
}
);
QUnit.test(
"formattedReminderTime works when the reminder time is today",
assert => {
let reminderAt = "2020-04-11 09:45:00";
let reminderAtDate = moment
.tz(reminderAt, "Australia/Brisbane")
.format("H:mm a");
assert.equal(
formattedReminderTime(reminderAt, "Australia/Brisbane"),
"today at " + reminderAtDate
);
}
);
QUnit.test(
"formattedReminderTime works when the reminder time is in the future",
assert => {
let reminderAt = "2020-04-15 09:45:00";
let reminderAtDate = moment
.tz(reminderAt, "Australia/Brisbane")
.format("H:mm a");
assert.equal(
formattedReminderTime(reminderAt, "Australia/Brisbane"),
"at Apr 15, 2020 " + reminderAtDate
);
}
);