DEV: Extract a test helper in local-dates (#29196)
This commit is contained in:
parent
c1325dbe13
commit
29ac39cf41
|
@ -0,0 +1,21 @@
|
|||
import sinon from "sinon";
|
||||
|
||||
const PARIS = "Europe/Paris";
|
||||
|
||||
export default function freezeTime({ date, timezone }, cb) {
|
||||
date = date || "2020-01-22 10:34";
|
||||
const newTimezone = timezone || PARIS;
|
||||
const previousZone = moment.tz.guess();
|
||||
const now = moment.tz(date, newTimezone).valueOf();
|
||||
|
||||
sinon.useFakeTimers(now);
|
||||
sinon.stub(moment.tz, "guess");
|
||||
moment.tz.guess.returns(newTimezone);
|
||||
moment.tz.setDefault(newTimezone);
|
||||
|
||||
cb();
|
||||
|
||||
moment.tz.guess.returns(previousZone);
|
||||
moment.tz.setDefault(previousZone);
|
||||
sinon.restore();
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
import { setupTest } from "ember-qunit";
|
||||
import { module, test } from "qunit";
|
||||
import freezeTime from "../helpers/freeze-time";
|
||||
import { applyLocalDates } from "../initializers/discourse-local-dates";
|
||||
import { freezeTime } from "./local-date-builder-test";
|
||||
|
||||
module("Unit | discourse-local-dates", function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import QUnit, { module, test } from "qunit";
|
||||
import sinon from "sinon";
|
||||
import I18n from "discourse-i18n";
|
||||
import freezeTime from "../helpers/freeze-time";
|
||||
import LocalDateBuilder from "../lib/local-date-builder";
|
||||
|
||||
const UTC = "Etc/UTC";
|
||||
|
@ -12,24 +12,6 @@ const LAGOS = "Africa/Lagos";
|
|||
const LONDON = "Europe/London";
|
||||
const SINGAPORE = "Asia/Singapore";
|
||||
|
||||
export function freezeTime({ date, timezone }, cb) {
|
||||
date = date || "2020-01-22 10:34";
|
||||
const newTimezone = timezone || PARIS;
|
||||
const previousZone = moment.tz.guess();
|
||||
const now = moment.tz(date, newTimezone).valueOf();
|
||||
|
||||
sinon.useFakeTimers(now);
|
||||
sinon.stub(moment.tz, "guess");
|
||||
moment.tz.guess.returns(newTimezone);
|
||||
moment.tz.setDefault(newTimezone);
|
||||
|
||||
cb();
|
||||
|
||||
moment.tz.guess.returns(previousZone);
|
||||
moment.tz.setDefault(previousZone);
|
||||
sinon.restore();
|
||||
}
|
||||
|
||||
QUnit.assert.buildsCorrectDate = function (options, expected, message) {
|
||||
const localTimezone = options.localTimezone || PARIS;
|
||||
delete options.localTimezone;
|
||||
|
|
Loading…
Reference in New Issue