Skip to content

A platform for community discussion. Free, open, simple.

DEV: Try once more to make acceptance test fake timers work

Martin Brennan0e09c5837f1b
diff --git a/test/javascripts/acceptance/bookmarks-test.js b/test/javascripts/acceptance/bookmarks-test.js
index 88175f53894..6680bfea7dc 100644
--- a/test/javascripts/acceptance/bookmarks-test.js
+++ b/test/javascripts/acceptance/bookmarks-test.js
@@ -1,8 +1,7 @@
import {
acceptance,
loggedInUser,
- fakeTime,
- timeStep
+ acceptanceUseFakeClock
} from "helpers/qunit-helpers";
import pretender from "helpers/create-pretender";
import { parsePostData } from "helpers/create-pretender";
@@ -230,23 +229,16 @@ 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 => {
+test("Editing a bookmark that has a Later Today reminder, and it is before 6pm today", async assert => {
+ await acceptanceUseFakeClock("2020-05-04T13:00:00", async () => {
mockSuccessfulBookmarkPost(assert);
- let clock = fakeTime(
- "2020-05-04T13:00:00",
- loggedInUser().resolvedTimezone(loggedInUser())
- );
- 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());
+ 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"),
+ exists("#bookmark-custom-date > input"),
"it does not show the custom date input"
);
assert.ok(
@@ -254,5 +246,5 @@ QUnit.skip(
"it preselects Later Today"
);
assert.verifySteps(["later_today"]);
- }
-);
+ });
+});
diff --git a/test/javascripts/helpers/qunit-helpers.js b/test/javascripts/helpers/qunit-helpers.js
index 2dd5c793a7e..f196bd03bce 100644
--- a/test/javascripts/helpers/qunit-helpers.js
+++ b/test/javascripts/helpers/qunit-helpers.js
@@ -41,14 +41,30 @@ export function loggedInUser() {
return User.current();
}
-export function fakeTime(timeString, timezone) {
+export function fakeTime(timeString, timezone = null, advanceTime = false) {
let now = moment.tz(timeString, timezone);
- return sandbox.useFakeTimers(now.valueOf());
+ return sandbox.useFakeTimers({
+ now: now.valueOf(),
+ shouldAdvanceTime: advanceTime
+ });
}
-export async function timeStep(clock, fn) {
- fn();
- return await clock.tickAsync(1000);
+export async function acceptanceUseFakeClock(
+ timeString,
+ callback,
+ timezone = null
+) {
+ if (!timezone) {
+ let user = loggedInUser();
+ if (user) {
+ timezone = user.resolvedTimezone(user);
+ } else {
+ timezone = "America/Denver";
+ }
+ }
+ let clock = fakeTime(timeString, timezone, true);
+ await callback();
+ clock.reset();
}
const Plugin = $.fn.modal;