fix(tests): force using UTC so tests don't fail on a non-UTC timezone

This commit is contained in:
Łukasz Mierzwa
2018-12-27 20:24:44 +01:00
parent e24e2daad1
commit 6aed0de5df
3 changed files with 16 additions and 15 deletions

View File

@@ -7,6 +7,7 @@ import { mount } from "enzyme";
import toDiffableHtml from "diffable-html";
import moment from "moment";
import { advanceTo, clear } from "jest-date-mock";
import { AlertStore } from "Stores/AlertStore";
@@ -52,7 +53,7 @@ let alertStore;
let silenceFormStore;
beforeEach(() => {
advanceTo(new Date(2000, 0, 1, 15, 0, 0));
advanceTo(moment.utc([2000, 0, 1, 15, 0, 0]));
alertStore = new AlertStore([]);
alertStore.data.upstreams = {
counters: {
@@ -242,7 +243,7 @@ describe("<SilenceDetails />", () => {
});
it("expired silence endsAt label uses 'danger' class", () => {
advanceTo(new Date(2000, 0, 1, 23, 0, 0));
advanceTo(moment.utc([2000, 0, 1, 23, 0, 0]));
const tree = MountedSilenceDetails(jest.fn());
const endsAt = tree.find("span.badge").at(2);
expect(endsAt.html()).toMatch(/text-danger/);
@@ -259,27 +260,27 @@ describe("<SilenceDetails />", () => {
describe("<SilenceExpiryBadgeWithProgress />", () => {
it("renders with class 'danger' and no progressbar when expired", () => {
advanceTo(new Date(2001, 0, 1, 23, 0, 0));
advanceTo(moment.utc([2001, 0, 1, 23, 0, 0]));
const tree = MountedSilence(alertmanager);
expect(tree.html()).toMatch(/badge-danger/);
expect(tree.text()).toMatch(/Expired a year ago/);
});
it("progressbar uses class 'danger' when > 90%", () => {
advanceTo(new Date(2000, 0, 1, 19, 30, 0));
advanceTo(moment.utc([2000, 0, 1, 19, 30, 0]));
const tree = MountedSilence(alertmanager);
expect(tree.html()).toMatch(/progress-bar bg-danger/);
});
it("progressbar uses class 'danger' when > 75%", () => {
advanceTo(new Date(2000, 0, 1, 17, 45, 0));
advanceTo(moment.utc([2000, 0, 1, 17, 45, 0]));
const tree = MountedSilence(alertmanager);
expect(tree.html()).toMatch(/progress-bar bg-warning/);
});
it("calling calculate() on progress multiple times in a row doesn't change the value", () => {
const startsAt = new Date(2000, 0, 1, 10, 0, 0);
const endsAt = new Date(2000, 0, 1, 20, 0, 0);
const startsAt = moment.utc([2000, 0, 1, 10, 0, 0]);
const endsAt = moment.utc([2000, 0, 1, 20, 0, 0]);
const tree = MountedSilence(alertmanager).find("Silence");
const instance = tree.instance();

View File

@@ -12,8 +12,8 @@ import { PayloadPreview } from ".";
describe("<PayloadPreview />", () => {
it("matches snapshot", () => {
const silenceFormStore = new SilenceFormStore();
silenceFormStore.data.startsAt = moment([2000, 1, 1, 0, 0, 0]);
silenceFormStore.data.endsAt = moment([2000, 1, 1, 1, 0, 0]);
silenceFormStore.data.startsAt = moment.utc([2000, 1, 1, 0, 0, 0]);
silenceFormStore.data.endsAt = moment.utc([2000, 1, 1, 1, 0, 0]);
silenceFormStore.data.createdBy = "me@example.com";
silenceFormStore.data.comment = "PayloadPreview test";

View File

@@ -228,11 +228,11 @@ describe("SilenceFormStore.data", () => {
})
);
expect(store.data.startsAt.toISOString()).toBe(
moment([2000, 0, 1, 0, 0, 0]).toISOString()
expect(store.data.startsAt.utc().toISOString()).toBe(
moment.utc([2000, 0, 1, 0, 0, 0]).toISOString()
);
expect(store.data.endsAt.toISOString()).toBe(
moment([2000, 0, 1, 1, 0, 0]).toISOString()
expect(store.data.endsAt.utc().toISOString()).toBe(
moment.utc([2000, 0, 1, 1, 0, 0]).toISOString()
);
expect(store.data.author).toBe("me@example.com");
@@ -256,8 +256,8 @@ describe("SilenceFormStore.data", () => {
store.data.fillMatchersFromGroup(group);
// add empty matcher so we test empty string rendering
store.data.addEmptyMatcher();
store.data.startsAt = moment([2000, 1, 1, 0, 0, 0]);
store.data.endsAt = moment([2000, 1, 1, 1, 0, 0]);
store.data.startsAt = moment.utc([2000, 1, 1, 0, 0, 0]);
store.data.endsAt = moment.utc([2000, 1, 1, 1, 0, 0]);
store.data.author = "me@example.com";
store.data.comment = "toAlertmanagerPayload test";
expect(store.data.toAlertmanagerPayload).toMatchSnapshot();