mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Upgrade sinon and fix time based bookmark tests (#9647)
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.
This commit is contained in:
@@ -1,8 +1,18 @@
|
||||
import { acceptance, loggedInUser } from "helpers/qunit-helpers";
|
||||
import {
|
||||
acceptance,
|
||||
loggedInUser,
|
||||
fakeTime,
|
||||
timeStep
|
||||
} from "helpers/qunit-helpers";
|
||||
import pretender from "helpers/create-pretender";
|
||||
import { parsePostData } from "helpers/create-pretender";
|
||||
|
||||
acceptance("Bookmarking", { loggedIn: true });
|
||||
acceptance("Bookmarking", {
|
||||
loggedIn: true,
|
||||
afterEach() {
|
||||
sandbox.restore();
|
||||
}
|
||||
});
|
||||
|
||||
function handleRequest(assert, request) {
|
||||
const data = parsePostData(request.requestBody);
|
||||
@@ -196,25 +206,26 @@ test("Editing a bookmark", async assert => {
|
||||
assert.verifySteps(["tomorrow"]);
|
||||
});
|
||||
|
||||
QUnit.skip(
|
||||
"Editing a bookmark that has a Later Today reminder, and it is before 6pm today",
|
||||
async assert => {
|
||||
// This test needs to mock the current time. sandbox.useFakeTimers() seems to break the `visit` step
|
||||
|
||||
mockSuccessfulBookmarkPost(assert);
|
||||
await visit("/t/internationalization-localization/280");
|
||||
await openBookmarkModal();
|
||||
await fillIn("input#bookmark-name", "Test name");
|
||||
await click("#tap_tile_later_today");
|
||||
await openEditBookmarkModal();
|
||||
assert.not(
|
||||
exists("#bookmark-custon-date > input"),
|
||||
"it does not show the custom date input"
|
||||
);
|
||||
assert.ok(
|
||||
exists("#tap_tile_later_today.active"),
|
||||
"it preselects Later Today"
|
||||
);
|
||||
assert.verifySteps(["later_today"]);
|
||||
}
|
||||
);
|
||||
test("Editing a bookmark that has a Later Today reminder, and it is before 6pm today", async assert => {
|
||||
mockSuccessfulBookmarkPost(assert);
|
||||
let clock = fakeTime(
|
||||
"2020-05-04T13:00:00",
|
||||
loggedInUser().resolvedTimezone()
|
||||
);
|
||||
await timeStep(clock, () =>
|
||||
visit("/t/internationalization-localization/280")
|
||||
);
|
||||
await timeStep(clock, () => openBookmarkModal());
|
||||
await timeStep(clock, () => fillIn("input#bookmark-name", "Test name"));
|
||||
await timeStep(clock, () => click("#tap_tile_later_today"));
|
||||
await timeStep(clock, () => openEditBookmarkModal());
|
||||
assert.not(
|
||||
exists("#bookmark-custon-date > input"),
|
||||
"it does not show the custom date input"
|
||||
);
|
||||
assert.ok(
|
||||
exists("#tap_tile_later_today.active"),
|
||||
"it preselects Later Today"
|
||||
);
|
||||
assert.verifySteps(["later_today"]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user