mirror of
https://github.com/discourse/discourse.git
synced 2024-12-14 10:13:41 +08:00
7e303f9320
Update sinon.js to 9.0.2 to access async fake timers https://sinonjs.org/releases/v9.0.2/fake-timers/ which can then be used with acceptance tests (previously useFakeTimers didn't work with await, e.g. for visit). Fix the bookmark acceptance test that was time based to use these new fake timers. Add a fakeTime function that uses moment and the provided date string + timezone to freeze time using useFakeTimers and return a clock. Add a timeStep function that accepts a clock from fakeTime and a function to run. Once the function is run we call clock.tickAsync(1000) to progress the fake clock forward 1s to progress promises/callbacks.
55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
import { formattedReminderTime } from "discourse/lib/bookmark";
|
|
import { fakeTime } from "helpers/qunit-helpers";
|
|
|
|
QUnit.module("lib:bookmark", {
|
|
beforeEach() {
|
|
fakeTime("2020-04-11 08:00:00", "Australia/Brisbane");
|
|
},
|
|
|
|
afterEach() {
|
|
sandbox.restore();
|
|
}
|
|
});
|
|
|
|
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
|
|
);
|
|
}
|
|
);
|