Farmbot-Web-App/frontend/farm_designer/farm_events/__tests__/util_test.ts

33 lines
1.0 KiB
TypeScript
Raw Normal View History

2017-12-16 00:46:04 -07:00
import { maybeWarnAboutMissedTasks } from "../util";
import { fakeFarmEvent } from "../../../__test_support__/fake_state/resources";
2019-02-04 13:54:17 -07:00
import moment from "moment";
2019-07-17 13:38:26 -06:00
import { ExecutableType } from "farmbot/dist/resources/api_resources";
2017-07-20 13:22:52 -06:00
2017-12-16 00:46:04 -07:00
describe("maybeWarnAboutMissedTasks()", () => {
2019-07-17 13:38:26 -06:00
function testWarn(
time: string, executableType: ExecutableType = "Regimen"
): () => void {
2017-12-16 00:46:04 -07:00
const callback = jest.fn();
2019-07-17 13:38:26 -06:00
const fe = fakeFarmEvent(executableType, 1);
2017-12-16 00:46:04 -07:00
fe.body.start_time = "2017-05-21T22:00:00.000";
maybeWarnAboutMissedTasks(fe,
() => callback("missed event warning"),
moment(time))();
2017-12-16 00:46:04 -07:00
return callback;
}
it("warns", () => {
const cb = testWarn("2017-05-21T22:00:00.000");
expect(cb).toHaveBeenCalledWith("missed event warning");
});
2017-12-16 00:46:04 -07:00
it("doesn't warn", () => {
const cb = testWarn("2017-05-01T22:00:00.000");
expect(cb).not.toHaveBeenCalled();
2017-07-20 13:22:52 -06:00
});
2019-07-17 13:38:26 -06:00
it("doesn't warn when not a regimen", () => {
const cb = testWarn("2017-05-21T22:00:00.000", "Sequence");
expect(cb).not.toHaveBeenCalled();
});
2017-07-20 13:22:52 -06:00
});