more farm event tests
This commit is contained in:
parent
327444b6bf
commit
3ed462a13f
13
webpack/farm_designer/__tests__/util_test.ts
Normal file
13
webpack/farm_designer/__tests__/util_test.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
|
||||
import { executableType } from "../util";
|
||||
|
||||
describe("executableType", () => {
|
||||
it("handles expected values", () => {
|
||||
expect(executableType("Sequence")).toEqual("Sequence");
|
||||
expect(executableType("Regimen")).toEqual("Regimen");
|
||||
});
|
||||
|
||||
it("throws when given bad data", () => {
|
||||
expect(() => executableType("Nope")).toThrowError();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,41 @@
|
|||
import { mapStateToPropsAddEdit } from "../map_state_to_props_add_edit";
|
||||
import { fakeState } from "../../../__test_support__/fake_state";
|
||||
import * as moment from "moment";
|
||||
|
||||
describe("mapStateToPropsAddEdit()", () => {
|
||||
const {
|
||||
executableOptions,
|
||||
handleTime,
|
||||
} = mapStateToPropsAddEdit(fakeState());
|
||||
|
||||
it("handleTime(): start_time", () => {
|
||||
const e = {
|
||||
currentTarget: { value: "10:54", name: "start_time" }
|
||||
} as React.SyntheticEvent<HTMLInputElement>;
|
||||
const result = handleTime(e, "2017-05-21T22:00:00.000");
|
||||
expect(result).toContain("54");
|
||||
});
|
||||
|
||||
it("handleTime(): end_time", () => {
|
||||
const e = {
|
||||
currentTarget: { value: "10:53", name: "end_time" }
|
||||
} as React.SyntheticEvent<HTMLInputElement>;
|
||||
const result = handleTime(e, "2017-05-21T22:00:00.000");
|
||||
expect(result).toContain("53");
|
||||
});
|
||||
|
||||
it("executableOptions", () => {
|
||||
expect(executableOptions).toEqual(expect.arrayContaining([
|
||||
{
|
||||
headingId: "Regimen",
|
||||
label: expect.stringContaining("Regimen: "),
|
||||
value: expect.any(Number)
|
||||
},
|
||||
{
|
||||
headingId: "Sequence",
|
||||
label: expect.stringContaining("Sequence: "),
|
||||
value: expect.any(Number)
|
||||
}
|
||||
]));
|
||||
});
|
||||
});
|
|
@ -1,13 +1,29 @@
|
|||
import { maybeWarnAboutMissedTasks } from "../util";
|
||||
import { fakeFarmEvent } from "../../../__test_support__/fake_state/resources";
|
||||
import { fakeState } from "../../../__test_support__/fake_state";
|
||||
import * as moment from "moment";
|
||||
|
||||
import { executableType } from "../../util";
|
||||
|
||||
describe("executableType", () => {
|
||||
it("handles expected values", () => {
|
||||
expect(executableType("Sequence")).toEqual("Sequence");
|
||||
expect(executableType("Regimen")).toEqual("Regimen");
|
||||
describe("maybeWarnAboutMissedTasks()", () => {
|
||||
beforeEach(function () {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it("throws when given bad data", () => {
|
||||
expect(() => executableType("Nope")).toThrowError();
|
||||
function testWarn(time: string): () => void {
|
||||
const callback = jest.fn();
|
||||
const fe = fakeFarmEvent("Regimen", 1);
|
||||
fe.body.start_time = "2017-05-21T22:00:00.000";
|
||||
maybeWarnAboutMissedTasks(fe,
|
||||
() => callback("missed event warning"),
|
||||
moment(time))(jest.fn(), fakeState);
|
||||
return callback;
|
||||
}
|
||||
it("warns", () => {
|
||||
const cb = testWarn("2017-05-21T22:00:00.000");
|
||||
expect(cb).toHaveBeenCalledWith("missed event warning");
|
||||
});
|
||||
|
||||
it("doesn't warn", () => {
|
||||
const cb = testWarn("2017-05-01T22:00:00.000");
|
||||
expect(cb).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -13,13 +13,14 @@ import * as moment from "moment";
|
|||
*
|
||||
* This function warns the user when "task loss" may occur.
|
||||
*/
|
||||
export function maybeWarnAboutMissedTasks(tfe: TaggedFarmEvent, cb: Function) {
|
||||
export function maybeWarnAboutMissedTasks(
|
||||
tfe: TaggedFarmEvent, cb: Function, now = moment()) {
|
||||
return function (dispatch: Function, getState: GetState) {
|
||||
const fe = tfe.body;
|
||||
// STEP 1: Only do this check if it is a Regimen -
|
||||
// sequences don't have this issue.
|
||||
if (fe.executable_type === "Regimen") {
|
||||
const NOW = moment();
|
||||
const NOW = now;
|
||||
const START_TIME = moment(fe.start_time);
|
||||
const TIMEFMT = "YYYY-MM-DD";
|
||||
|
||||
|
|
Loading…
Reference in a new issue