mirror of
https://github.com/discourse/discourse.git
synced 2024-12-15 02:33:42 +08:00
d7f744490a
* 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.
52 lines
1.4 KiB
JavaScript
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
|
|
);
|
|
}
|
|
);
|