Merge pull request #338 from prymitive/test-tz

feat(tests): run tests using non-UTC time zone
This commit is contained in:
Łukasz Mierzwa
2018-12-27 21:16:54 +01:00
committed by GitHub
4 changed files with 27 additions and 15 deletions
+11
View File
@@ -35,6 +35,17 @@ jobs:
after_success:
- bash <(curl -s https://codecov.io/bash) -F ui -s ui
# duplicate js test but with a different time zone, to ensure that tests/code work with non-UTC time zone
- stage: Test
<<: *DEFAULTS_JS
env:
- DESC="Test JavaScript code with Pacific/Easter time zone"
- NODE_ENV=test
- TZ=Pacific/Easter
script: make test-js
after_success:
- bash <(curl -s https://codecov.io/bash) -F ui -s ui
- stage: Lint
<<: *DEFAULTS_JS
env:
@@ -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();
@@ -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";
+6 -6
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();