mirror of
https://github.com/prymitive/karma
synced 2026-05-07 03:26:52 +00:00
fix(ui): add a test for react-moment
This commit is contained in:
@@ -8,6 +8,8 @@ import { advanceTo, clear } from "jest-date-mock";
|
||||
|
||||
import toDiffableHtml from "diffable-html";
|
||||
|
||||
import Moment from "react-moment";
|
||||
|
||||
import { MockAlert, MockAnnotation, MockAlertGroup } from "__mocks__/Alerts.js";
|
||||
import { AlertStore } from "Stores/AlertStore";
|
||||
import { SilenceFormStore } from "Stores/SilenceFormStore";
|
||||
@@ -208,4 +210,28 @@ describe("<Alert />", () => {
|
||||
.hasClass("border-warning")
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("alert timestamp is updated every minute", () => {
|
||||
jest.useFakeTimers();
|
||||
Moment.startPooledTimer();
|
||||
|
||||
advanceTo(new Date(Date.UTC(2018, 7, 14, 17, 36, 41)));
|
||||
|
||||
const alert = MockedAlert();
|
||||
const group = MockAlertGroup({}, [alert], [], {}, {});
|
||||
const tree = MountedAlert(alert, group, false, false);
|
||||
expect(tree.find("time").text()).toBe("a few seconds ago");
|
||||
|
||||
advanceTo(new Date(Date.UTC(2018, 7, 14, 17, 37, 41)));
|
||||
jest.advanceTimersByTime(61 * 1000);
|
||||
expect(tree.find("time").text()).toBe("a minute ago");
|
||||
|
||||
advanceTo(new Date(Date.UTC(2018, 7, 14, 18, 36, 41)));
|
||||
jest.advanceTimersByTime(61 * 1000);
|
||||
expect(tree.find("time").text()).toBe("an hour ago");
|
||||
|
||||
advanceTo(new Date(Date.UTC(2018, 7, 14, 19, 36, 41)));
|
||||
jest.advanceTimersByTime(61 * 1000);
|
||||
expect(tree.find("time").text()).toBe("2 hours ago");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user