* Use `sinon` instead of `sandbox` and require an import. * You need to import `currentURL` to use it.
48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
import sinon from "sinon";
|
|
import { test, module } from "qunit";
|
|
import { formattedReminderTime } from "discourse/lib/bookmark";
|
|
import { fakeTime } from "discourse/tests/helpers/qunit-helpers";
|
|
|
|
module("lib:bookmark", {
|
|
beforeEach() {
|
|
fakeTime("2020-04-11 08:00:00", "Australia/Brisbane");
|
|
},
|
|
|
|
afterEach() {
|
|
sinon.restore();
|
|
},
|
|
});
|
|
|
|
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
|
|
);
|
|
});
|
|
|
|
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
|
|
);
|
|
});
|
|
|
|
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
|
|
);
|
|
});
|