2019-01-13 16:39:26 -07:00
|
|
|
jest.mock("../../../history", () => ({ history: { push: jest.fn() } }));
|
|
|
|
|
|
|
|
jest.mock("../../../api/crud", () => ({
|
|
|
|
destroy: jest.fn(),
|
|
|
|
overwrite: jest.fn(),
|
|
|
|
save: jest.fn(),
|
2018-01-12 12:54:37 -07:00
|
|
|
}));
|
|
|
|
|
2017-07-26 14:18:28 -06:00
|
|
|
import * as React from "react";
|
2018-04-20 00:37:20 -06:00
|
|
|
import {
|
2019-02-22 19:09:40 -07:00
|
|
|
fakeFarmEvent, fakeSequence, fakeRegimen, fakePlant
|
2018-04-20 00:37:20 -06:00
|
|
|
} from "../../../__test_support__/fake_state/resources";
|
2019-01-13 16:39:26 -07:00
|
|
|
import { mount, shallow } from "enzyme";
|
2018-01-03 18:50:04 -07:00
|
|
|
import {
|
|
|
|
EditFEForm,
|
|
|
|
EditFEProps,
|
|
|
|
FarmEventViewModel,
|
|
|
|
recombine,
|
2018-04-20 00:37:20 -06:00
|
|
|
destructureFarmEvent,
|
|
|
|
offsetTime
|
2018-01-03 18:50:04 -07:00
|
|
|
} from "../edit_fe_form";
|
2019-01-13 16:39:26 -07:00
|
|
|
import { isString, isFunction } from "lodash";
|
2017-08-16 07:34:50 -06:00
|
|
|
import { repeatOptions } from "../map_state_to_props_add_edit";
|
2019-02-22 19:09:40 -07:00
|
|
|
import { SpecialStatus, ParameterApplication } from "farmbot";
|
2019-02-04 13:54:17 -07:00
|
|
|
import moment from "moment";
|
2018-04-20 00:37:20 -06:00
|
|
|
import { fakeState } from "../../../__test_support__/fake_state";
|
|
|
|
import { history } from "../../../history";
|
2018-12-20 20:18:10 -07:00
|
|
|
import {
|
|
|
|
buildResourceIndex
|
|
|
|
} from "../../../__test_support__/resource_index_builder";
|
2018-12-30 11:57:22 -07:00
|
|
|
import { fakeVariableNameSet } from "../../../__test_support__/fake_variables";
|
2019-01-13 16:39:26 -07:00
|
|
|
import { clickButton } from "../../../__test_support__/helpers";
|
|
|
|
import { destroy } from "../../../api/crud";
|
2019-04-09 23:17:03 -06:00
|
|
|
import { fakeTimeSettings } from "../../../__test_support__/fake_time_settings";
|
2019-06-24 15:39:49 -06:00
|
|
|
import { error, success, warning } from "../../../toast/toast";
|
2018-12-20 20:18:10 -07:00
|
|
|
|
2018-11-24 10:06:06 -07:00
|
|
|
const mockSequence = fakeSequence();
|
2018-12-20 20:18:10 -07:00
|
|
|
|
2017-07-26 13:02:00 -06:00
|
|
|
describe("<FarmEventForm/>", () => {
|
2018-04-05 14:05:54 -06:00
|
|
|
const props = (): EditFEProps => ({
|
2017-07-26 13:30:22 -06:00
|
|
|
deviceTimezone: undefined,
|
|
|
|
executableOptions: [],
|
|
|
|
repeatOptions: [],
|
|
|
|
farmEvent: fakeFarmEvent("Sequence", 12),
|
2018-01-12 12:54:37 -07:00
|
|
|
dispatch: jest.fn(() => Promise.resolve()),
|
2018-11-24 10:06:06 -07:00
|
|
|
findExecutable: jest.fn(() => mockSequence),
|
2017-12-29 10:39:04 -07:00
|
|
|
title: "title",
|
2019-04-09 23:17:03 -06:00
|
|
|
timeSettings: fakeTimeSettings(),
|
2018-04-05 14:05:54 -06:00
|
|
|
autoSyncEnabled: false,
|
2018-12-20 20:18:10 -07:00
|
|
|
shouldDisplay: () => false,
|
|
|
|
resources: buildResourceIndex([]).index,
|
2017-07-26 13:30:22 -06:00
|
|
|
});
|
2017-07-26 14:31:03 -06:00
|
|
|
|
|
|
|
function instance(p: EditFEProps) {
|
2018-04-05 14:05:54 -06:00
|
|
|
return mount(<EditFEForm {...p} />).instance() as EditFEForm;
|
2017-07-26 14:31:03 -06:00
|
|
|
}
|
2017-08-28 05:49:13 -06:00
|
|
|
const context = { form: new EditFEForm(props()) };
|
2017-07-26 13:30:22 -06:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
context.form = new EditFEForm(props());
|
|
|
|
});
|
|
|
|
|
|
|
|
it("sets defaults", () => {
|
|
|
|
expect(context.form.state.fe).toMatchObject({});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("determines if it is a one time event", () => {
|
2017-08-28 05:49:13 -06:00
|
|
|
const i = instance(props());
|
2018-12-30 11:57:22 -07:00
|
|
|
expect(i.repeats).toBe(false);
|
2017-07-26 14:18:28 -06:00
|
|
|
i.mergeState("timeUnit", "daily");
|
|
|
|
i.forceUpdate();
|
2018-12-30 11:57:22 -07:00
|
|
|
expect(i.repeats).toBe(true);
|
2017-07-26 13:30:22 -06:00
|
|
|
});
|
|
|
|
|
2017-07-26 14:20:32 -06:00
|
|
|
it("has a dispatch", () => {
|
2017-08-28 05:49:13 -06:00
|
|
|
const p = props();
|
|
|
|
const i = instance(p);
|
2017-07-26 14:20:32 -06:00
|
|
|
expect(i.dispatch).toBe(p.dispatch);
|
2017-07-26 14:55:55 -06:00
|
|
|
i.dispatch();
|
2017-12-14 16:03:50 -07:00
|
|
|
expect(p.dispatch).toHaveBeenCalledTimes(1);
|
2017-07-26 14:20:32 -06:00
|
|
|
});
|
|
|
|
|
2017-07-26 14:31:03 -06:00
|
|
|
it("has a view model", () => {
|
2017-08-28 05:49:13 -06:00
|
|
|
const p = props();
|
|
|
|
const i = instance(p);
|
2017-07-26 14:31:03 -06:00
|
|
|
i.forceUpdate();
|
2017-08-28 05:49:13 -06:00
|
|
|
const vm = i.viewModel;
|
|
|
|
const KEYS: (keyof FarmEventViewModel)[] = [
|
2017-07-26 14:31:03 -06:00
|
|
|
"startDate",
|
|
|
|
"startTime",
|
|
|
|
"endDate",
|
|
|
|
"endTime",
|
|
|
|
"repeat",
|
|
|
|
"timeUnit",
|
|
|
|
"executable_type",
|
|
|
|
"executable_id",
|
|
|
|
];
|
|
|
|
|
|
|
|
KEYS.map(key => expect(isString(vm[key])).toBe(true));
|
|
|
|
expect(vm.repeat).toEqual("" + p.farmEvent.body.repeat);
|
|
|
|
});
|
2017-07-26 14:55:55 -06:00
|
|
|
|
|
|
|
it("has an executable", () => {
|
2017-08-28 05:49:13 -06:00
|
|
|
const p = props();
|
|
|
|
const i = instance(p);
|
2017-07-26 14:55:55 -06:00
|
|
|
i.forceUpdate();
|
2018-11-24 10:06:06 -07:00
|
|
|
expect(i.executableGet().value).toEqual(mockSequence.body.id);
|
|
|
|
expect(i.executableGet().label).toEqual(mockSequence.body.name);
|
2017-07-26 14:55:55 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
it("sets the executable", () => {
|
2017-08-28 05:49:13 -06:00
|
|
|
const p = props();
|
|
|
|
const i = instance(p);
|
2017-07-26 14:55:55 -06:00
|
|
|
i.forceUpdate();
|
2017-08-05 21:41:25 -06:00
|
|
|
i.executableSet({ value: "wow", label: "hey", headingId: "Sequence" });
|
2017-07-26 14:55:55 -06:00
|
|
|
i.forceUpdate();
|
|
|
|
expect(i.state.fe.executable_type).toEqual("Sequence");
|
|
|
|
expect(i.state.fe.executable_id).toEqual("wow");
|
|
|
|
});
|
|
|
|
|
2018-04-20 00:37:20 -06:00
|
|
|
it("doesn't allow improper changes to the executable", () => {
|
|
|
|
const p = props();
|
|
|
|
p.farmEvent.body.executable_type = "Regimen";
|
|
|
|
const i = instance(p);
|
|
|
|
i.executableSet({ value: "wow", label: "hey", headingId: "Sequence" });
|
|
|
|
expect(error).toHaveBeenCalledWith(
|
2019-06-21 15:43:46 -06:00
|
|
|
"Cannot change between Sequences and Regimens.");
|
2019-04-09 19:52:12 -06:00
|
|
|
expect(history.push).toHaveBeenCalledWith("/app/designer/events");
|
2018-04-20 00:37:20 -06:00
|
|
|
});
|
|
|
|
|
2017-07-26 14:55:55 -06:00
|
|
|
it("gets executable info", () => {
|
2017-08-28 05:49:13 -06:00
|
|
|
const p = props();
|
|
|
|
const i = instance(p);
|
2017-07-26 14:55:55 -06:00
|
|
|
i.forceUpdate();
|
2017-08-28 05:49:13 -06:00
|
|
|
const exe = i.executableGet();
|
2017-07-26 14:55:55 -06:00
|
|
|
expect(exe.label).toBe("fake");
|
2018-11-24 10:06:06 -07:00
|
|
|
expect(exe.value).toBe(mockSequence.body.id);
|
2017-08-05 21:41:25 -06:00
|
|
|
expect(exe.headingId).toBe("Sequence");
|
2017-07-26 14:55:55 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
it("sets a subfield of state.fe", () => {
|
2017-08-28 05:49:13 -06:00
|
|
|
const p = props();
|
|
|
|
const i = instance(p);
|
2017-07-26 14:55:55 -06:00
|
|
|
i.forceUpdate();
|
2017-08-28 06:23:53 -06:00
|
|
|
// tslint:disable-next-line:no-any
|
2017-07-26 14:55:55 -06:00
|
|
|
i.fieldSet("repeat")(({ currentTarget: { value: "4" } } as any));
|
|
|
|
i.forceUpdate();
|
|
|
|
expect(i.state.fe.repeat).toEqual("4");
|
|
|
|
});
|
2017-08-01 07:53:32 -06:00
|
|
|
|
2017-08-23 15:42:41 -06:00
|
|
|
it("sets regimen repeat to `never` as needed", () => {
|
2017-08-28 05:49:13 -06:00
|
|
|
const result = recombine({
|
2018-12-20 20:18:10 -07:00
|
|
|
id: 1,
|
|
|
|
startDate: "2017-08-01",
|
|
|
|
startTime: "08:35",
|
|
|
|
endDate: "2017-08-01",
|
|
|
|
endTime: "08:33",
|
|
|
|
repeat: "1",
|
|
|
|
timeUnit: "daily",
|
|
|
|
executable_type: "Regimen",
|
|
|
|
executable_id: "1",
|
2019-04-09 23:17:03 -06:00
|
|
|
timeSettings: fakeTimeSettings(),
|
2018-12-20 20:18:10 -07:00
|
|
|
body: undefined,
|
2018-04-18 19:00:07 -06:00
|
|
|
}, { forceRegimensToMidnight: false });
|
2017-08-23 15:42:41 -06:00
|
|
|
expect(result.time_unit).toEqual("never");
|
|
|
|
expect(result.time_unit).not.toEqual("daily");
|
|
|
|
});
|
|
|
|
|
2018-04-18 19:00:07 -06:00
|
|
|
it("sets regimen start_time to `00:00` as needed", () => {
|
|
|
|
const result = recombine({
|
2018-12-20 20:18:10 -07:00
|
|
|
id: 1,
|
|
|
|
startDate: "2017-08-01",
|
|
|
|
startTime: "08:35",
|
|
|
|
endDate: "2017-08-01",
|
|
|
|
endTime: "08:33",
|
|
|
|
repeat: "1",
|
|
|
|
timeUnit: "daily",
|
|
|
|
executable_type: "Regimen",
|
|
|
|
executable_id: "1",
|
2019-04-09 23:17:03 -06:00
|
|
|
timeSettings: fakeTimeSettings(),
|
2018-12-20 20:18:10 -07:00
|
|
|
body: undefined,
|
2018-04-18 19:00:07 -06:00
|
|
|
}, { forceRegimensToMidnight: true });
|
|
|
|
expect(result.start_time).toEqual("2017-08-01T00:00:00.000Z");
|
|
|
|
});
|
|
|
|
|
2018-12-20 20:18:10 -07:00
|
|
|
it(`Recombines local state back into a TaggedFarmEvent["body"]`, () => {
|
2017-08-28 05:49:13 -06:00
|
|
|
const result = recombine({
|
2018-12-20 20:18:10 -07:00
|
|
|
id: 1,
|
|
|
|
startDate: "2017-08-01",
|
|
|
|
startTime: "08:35",
|
|
|
|
endDate: "2017-08-01",
|
|
|
|
endTime: "08:33",
|
|
|
|
repeat: "1",
|
|
|
|
timeUnit: "never",
|
|
|
|
executable_type: "Regimen",
|
|
|
|
executable_id: "1",
|
2019-04-09 23:17:03 -06:00
|
|
|
timeSettings: fakeTimeSettings(),
|
2018-04-18 19:00:07 -06:00
|
|
|
}, { forceRegimensToMidnight: false });
|
2018-01-24 17:33:00 -07:00
|
|
|
expect(result).toEqual({
|
2018-12-20 20:18:10 -07:00
|
|
|
id: 1,
|
2018-01-24 17:33:00 -07:00
|
|
|
start_time: "2017-08-01T08:35:00.000Z",
|
|
|
|
end_time: "2017-08-01T08:33:00.000Z",
|
|
|
|
repeat: 1,
|
|
|
|
time_unit: "never",
|
|
|
|
executable_type: "Regimen",
|
|
|
|
executable_id: 1
|
|
|
|
});
|
2017-08-01 07:53:32 -06:00
|
|
|
});
|
2017-08-16 07:34:50 -06:00
|
|
|
|
|
|
|
it("renders the correct save button text when adding", () => {
|
2017-08-28 05:49:13 -06:00
|
|
|
const seq = fakeSequence();
|
|
|
|
const fe = fakeFarmEvent("Sequence", seq.body.id || 0);
|
2017-08-16 08:47:23 -06:00
|
|
|
fe.specialStatus = SpecialStatus.DIRTY;
|
2017-08-28 05:49:13 -06:00
|
|
|
const el = mount(<EditFEForm
|
2017-08-16 08:47:23 -06:00
|
|
|
farmEvent={fe}
|
2017-08-16 07:34:50 -06:00
|
|
|
title=""
|
|
|
|
deviceTimezone="America/Chicago"
|
|
|
|
executableOptions={[
|
|
|
|
{
|
2018-12-20 20:18:10 -07:00
|
|
|
label: "Sequence: Every Node",
|
|
|
|
value: 11,
|
|
|
|
headingId: "Sequence"
|
2017-08-16 07:34:50 -06:00
|
|
|
}
|
|
|
|
]}
|
2017-08-16 07:48:34 -06:00
|
|
|
findExecutable={jest.fn(() => seq)}
|
2017-08-16 07:34:50 -06:00
|
|
|
dispatch={jest.fn()}
|
2017-12-29 10:39:04 -07:00
|
|
|
repeatOptions={repeatOptions}
|
2019-04-09 23:17:03 -06:00
|
|
|
timeSettings={fakeTimeSettings()}
|
2018-04-18 19:00:07 -06:00
|
|
|
autoSyncEnabled={false}
|
2018-12-20 20:18:10 -07:00
|
|
|
resources={buildResourceIndex([]).index}
|
|
|
|
shouldDisplay={() => false} />);
|
2017-08-16 08:47:23 -06:00
|
|
|
el.update();
|
2017-08-28 05:49:13 -06:00
|
|
|
const txt = el.text().replace(/\s+/g, " ");
|
2017-08-16 08:47:23 -06:00
|
|
|
expect(txt).toContain("Save *");
|
2017-08-16 07:34:50 -06:00
|
|
|
});
|
2018-01-12 12:54:37 -07:00
|
|
|
|
2018-04-05 14:05:54 -06:00
|
|
|
it("displays success message on save: manual sync", async () => {
|
2018-01-12 12:54:37 -07:00
|
|
|
const p = props();
|
2018-04-05 14:05:54 -06:00
|
|
|
p.autoSyncEnabled = false;
|
2018-04-20 00:37:20 -06:00
|
|
|
p.farmEvent.body.start_time = "2017-05-22T05:00:00.000Z";
|
|
|
|
p.farmEvent.body.end_time = "2017-05-22T06:00:00.000Z";
|
2018-01-12 12:54:37 -07:00
|
|
|
const i = instance(p);
|
2018-04-20 00:37:20 -06:00
|
|
|
await i.commitViewModel(moment("2016-05-22T05:00:00.000Z"));
|
2018-01-12 12:54:37 -07:00
|
|
|
expect(success).toHaveBeenCalledWith(
|
|
|
|
expect.stringContaining("must first SYNC YOUR DEVICE"));
|
|
|
|
});
|
|
|
|
|
2018-04-05 14:05:54 -06:00
|
|
|
it("displays success message on save: auto sync", async () => {
|
|
|
|
const p = props();
|
|
|
|
p.autoSyncEnabled = true;
|
2018-04-20 00:37:20 -06:00
|
|
|
p.farmEvent.body.executable_type = "Regimen";
|
|
|
|
const regimen = fakeRegimen();
|
|
|
|
regimen.body.regimen_items = [{ sequence_id: -1, time_offset: 100000000 }];
|
|
|
|
p.findExecutable = () => regimen;
|
|
|
|
p.farmEvent.body.start_time = "2017-05-22T05:00:00.000Z";
|
|
|
|
p.farmEvent.body.end_time = "2017-05-22T06:00:00.000Z";
|
2018-04-05 14:05:54 -06:00
|
|
|
const i = instance(p);
|
2018-04-20 00:37:20 -06:00
|
|
|
await i.commitViewModel(moment("2016-05-22T05:00:00.000Z"));
|
2018-04-05 14:05:54 -06:00
|
|
|
expect(success).toHaveBeenCalledWith(
|
2019-04-09 19:52:12 -06:00
|
|
|
expect.stringContaining("The next item in this event will run"));
|
2018-04-05 14:05:54 -06:00
|
|
|
expect(success).not.toHaveBeenCalledWith(
|
|
|
|
expect.stringContaining("must first SYNC YOUR DEVICE"));
|
|
|
|
});
|
|
|
|
|
2018-04-20 00:37:20 -06:00
|
|
|
it("warns about missed regimen items", async () => {
|
|
|
|
const p = props();
|
|
|
|
const state = fakeState();
|
|
|
|
state.resources.index.references = { [p.farmEvent.uuid]: p.farmEvent };
|
2019-01-13 16:39:26 -07:00
|
|
|
p.dispatch = jest.fn(x => { isFunction(x) && x(); return Promise.resolve(); });
|
2018-04-20 00:37:20 -06:00
|
|
|
p.farmEvent.body.executable_type = "Regimen";
|
|
|
|
p.farmEvent.body.start_time = "2017-05-22T05:00:00.000Z";
|
|
|
|
p.farmEvent.body.end_time = "2017-05-22T06:00:00.000Z";
|
|
|
|
const i = instance(p);
|
|
|
|
window.alert = jest.fn();
|
2019-04-09 23:17:03 -06:00
|
|
|
await i.commitViewModel(moment(offsetTime(
|
|
|
|
"2017-05-22", "06:00", fakeTimeSettings())));
|
2018-04-20 00:37:20 -06:00
|
|
|
expect(window.alert).toHaveBeenCalledWith(
|
|
|
|
expect.stringContaining("skipped regimen tasks"));
|
|
|
|
});
|
|
|
|
|
|
|
|
it("sends toast with regimen start time", async () => {
|
|
|
|
const p = props();
|
|
|
|
p.farmEvent.body.executable_type = "Regimen";
|
|
|
|
const regimen = fakeRegimen();
|
|
|
|
regimen.body.regimen_items = [{ sequence_id: -1, time_offset: 1000000000 }];
|
|
|
|
p.findExecutable = () => regimen;
|
|
|
|
p.farmEvent.body.start_time = "2017-05-22T05:00:00.000Z";
|
|
|
|
p.farmEvent.body.end_time = "2017-05-22T06:00:00.000Z";
|
|
|
|
const i = instance(p);
|
2019-04-09 23:17:03 -06:00
|
|
|
await i.commitViewModel(moment(offsetTime(
|
|
|
|
"2017-05-25", "06:00", fakeTimeSettings())));
|
2018-04-20 00:37:20 -06:00
|
|
|
expect(success).toHaveBeenCalledWith(
|
|
|
|
expect.stringContaining("run in 8 days"));
|
|
|
|
});
|
|
|
|
|
|
|
|
it("sends toast with next sequence run time", async () => {
|
|
|
|
const p = props();
|
|
|
|
p.farmEvent.body.executable_type = "Sequence";
|
|
|
|
p.farmEvent.body.start_time = "2017-05-22T05:00:00.000Z";
|
|
|
|
p.farmEvent.body.end_time = "2017-06-22T06:00:00.000Z";
|
|
|
|
p.farmEvent.body.repeat = 7;
|
|
|
|
p.farmEvent.body.time_unit = "daily";
|
|
|
|
const i = instance(p);
|
2019-04-09 23:17:03 -06:00
|
|
|
await i.commitViewModel(moment(offsetTime(
|
|
|
|
"2017-05-25", "06:00", fakeTimeSettings())));
|
2018-04-20 00:37:20 -06:00
|
|
|
expect(success).toHaveBeenCalledWith(
|
|
|
|
expect.stringContaining("will run in 4 days"));
|
|
|
|
});
|
|
|
|
|
|
|
|
const expectStartTimeToBeRejected = () => {
|
|
|
|
expect(error).toHaveBeenCalledWith(
|
2019-04-09 19:52:12 -06:00
|
|
|
"Event start time needs to be in the future, not the past.",
|
|
|
|
"Unable to save event.");
|
2018-04-20 00:37:20 -06:00
|
|
|
};
|
|
|
|
|
2018-04-18 19:00:07 -06:00
|
|
|
it("displays error message on save (add): start time has passed", () => {
|
|
|
|
const p = props();
|
|
|
|
p.title = "add";
|
|
|
|
p.farmEvent.body.start_time = "2017-05-22T05:00:00.000Z";
|
|
|
|
p.farmEvent.body.end_time = "2017-05-22T06:00:00.000Z";
|
|
|
|
const i = instance(p);
|
2018-04-20 00:37:20 -06:00
|
|
|
i.commitViewModel(moment("2017-06-22T05:00:00.000Z"));
|
|
|
|
expectStartTimeToBeRejected();
|
2018-04-18 19:00:07 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
it("doesn't display error message on edit: start time has passed", () => {
|
|
|
|
const p = props();
|
|
|
|
p.title = "edit";
|
|
|
|
p.farmEvent.body.start_time = "2017-05-22T05:00:00.000Z";
|
|
|
|
p.farmEvent.body.end_time = "2017-05-22T06:00:00.000Z";
|
|
|
|
const i = instance(p);
|
2018-04-20 00:37:20 -06:00
|
|
|
i.commitViewModel(moment("2017-06-22T05:00:00.000Z"));
|
2018-04-18 19:00:07 -06:00
|
|
|
expect(error).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("displays error message on save: no items", async () => {
|
2018-01-12 12:54:37 -07:00
|
|
|
const p = props();
|
2018-12-20 20:18:10 -07:00
|
|
|
p.shouldDisplay = () => true;
|
2018-01-12 12:54:37 -07:00
|
|
|
p.farmEvent.body.start_time = "2017-05-22T05:00:00.000Z";
|
|
|
|
p.farmEvent.body.end_time = "2017-05-22T06:00:00.000Z";
|
|
|
|
const i = instance(p);
|
2018-04-20 00:37:20 -06:00
|
|
|
await i.commitViewModel(moment("2017-06-22T05:00:00.000Z"));
|
2019-02-11 19:43:48 -07:00
|
|
|
expect(warning).toHaveBeenCalledWith(expect.stringContaining(
|
|
|
|
"Nothing to run."), "Warning");
|
2018-04-20 00:37:20 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
it("allows start time: edit with unsupported OS", () => {
|
|
|
|
const p = props();
|
2018-12-20 20:18:10 -07:00
|
|
|
p.shouldDisplay = () => false;
|
2018-04-20 00:37:20 -06:00
|
|
|
p.farmEvent.body.executable_type = "Regimen";
|
|
|
|
p.farmEvent.body.start_time = "2017-06-01T01:00:00.000Z";
|
|
|
|
const fakeNow = moment("2017-06-01T02:00:00.000Z");
|
|
|
|
p.title = "edit";
|
|
|
|
const reject = instance(p).maybeRejectStartTime(p.farmEvent.body, fakeNow);
|
|
|
|
expect(reject).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("allows start time: add with supported OS", () => {
|
|
|
|
const p = props();
|
|
|
|
p.title = "add";
|
2018-12-20 20:18:10 -07:00
|
|
|
p.shouldDisplay = () => true;
|
2018-04-20 00:37:20 -06:00
|
|
|
p.farmEvent.body.executable_type = "Regimen";
|
|
|
|
p.farmEvent.body.start_time = "2017-06-01T01:00:00.000Z";
|
|
|
|
const fakeNow = moment("2017-06-01T02:00:00.000Z");
|
|
|
|
const reject = instance(p).maybeRejectStartTime(p.farmEvent.body, fakeNow);
|
|
|
|
expect(reject).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("rejects start time: add sequence event", () => {
|
|
|
|
const p = props();
|
|
|
|
p.title = "add";
|
|
|
|
p.farmEvent.body.executable_type = "Sequence";
|
|
|
|
p.farmEvent.body.start_time = "2017-06-01T01:00:00.000Z";
|
|
|
|
const fakeNow = moment("2017-06-01T02:00:00.000Z");
|
|
|
|
const reject = instance(p).maybeRejectStartTime(p.farmEvent.body, fakeNow);
|
|
|
|
expect(reject).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("allows start time: edit sequence event", () => {
|
|
|
|
const p = props();
|
|
|
|
p.farmEvent.body.executable_type = "Sequence";
|
|
|
|
p.farmEvent.body.start_time = "2017-06-01T01:00:00.000Z";
|
|
|
|
const fakeNow = moment("2017-06-01T02:00:00.000Z");
|
|
|
|
p.title = "edit";
|
|
|
|
const reject = instance(p).maybeRejectStartTime(p.farmEvent.body, fakeNow);
|
|
|
|
expect(reject).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("allows start time in the future", () => {
|
|
|
|
const p = props();
|
|
|
|
p.title = "add";
|
|
|
|
p.farmEvent.body.executable_type = "Sequence";
|
|
|
|
p.farmEvent.body.start_time = "2017-06-01T01:00:00.000Z";
|
|
|
|
const fakeNow = moment("2017-06-01T00:00:00.000Z");
|
|
|
|
const reject = instance(p).maybeRejectStartTime(p.farmEvent.body, fakeNow);
|
|
|
|
expect(reject).toBeFalsy();
|
2018-01-12 12:54:37 -07:00
|
|
|
});
|
2018-12-30 11:57:22 -07:00
|
|
|
|
2019-02-22 19:09:40 -07:00
|
|
|
it("edits a variable", () => {
|
2018-12-30 11:57:22 -07:00
|
|
|
const p = props();
|
2019-02-22 19:09:40 -07:00
|
|
|
const oldVariable: ParameterApplication = {
|
|
|
|
kind: "parameter_application",
|
2018-12-30 11:57:22 -07:00
|
|
|
args: {
|
|
|
|
label: "foo",
|
|
|
|
data_value: {
|
|
|
|
kind: "point", args: {
|
|
|
|
pointer_id: 1, pointer_type: "Plant"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2019-02-22 19:09:40 -07:00
|
|
|
const newVariable: ParameterApplication = {
|
|
|
|
kind: "parameter_application",
|
2018-12-30 11:57:22 -07:00
|
|
|
args: {
|
|
|
|
label: "foo",
|
|
|
|
data_value: { kind: "coordinate", args: { x: 1, y: 2, z: 3 } }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const inst = instance(p);
|
2019-02-22 19:09:40 -07:00
|
|
|
inst.setState({ fe: { body: [oldVariable] } });
|
|
|
|
expect(inst.state.fe.body).toEqual([oldVariable]);
|
2018-12-30 11:57:22 -07:00
|
|
|
expect(inst.state.specialStatusLocal).toEqual(SpecialStatus.SAVED);
|
2019-02-22 19:09:40 -07:00
|
|
|
inst.editBodyVariables([oldVariable])(newVariable);
|
|
|
|
expect(inst.state.fe.body).toEqual([newVariable]);
|
2018-12-30 11:57:22 -07:00
|
|
|
expect(inst.state.specialStatusLocal).toEqual(SpecialStatus.DIRTY);
|
|
|
|
});
|
|
|
|
|
2019-02-22 19:09:40 -07:00
|
|
|
it("saves an updated variable", () => {
|
2018-12-30 11:57:22 -07:00
|
|
|
const p = props();
|
2019-02-22 19:09:40 -07:00
|
|
|
const oldVariable: ParameterApplication = {
|
|
|
|
kind: "parameter_application",
|
2018-12-30 11:57:22 -07:00
|
|
|
args: {
|
|
|
|
label: "foo",
|
|
|
|
data_value: {
|
|
|
|
kind: "point", args: {
|
|
|
|
pointer_id: 1, pointer_type: "Plant"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2019-02-22 19:09:40 -07:00
|
|
|
p.farmEvent.body.body = [oldVariable];
|
|
|
|
const newVariable: ParameterApplication = {
|
|
|
|
kind: "parameter_application",
|
2018-12-30 11:57:22 -07:00
|
|
|
args: {
|
|
|
|
label: "foo",
|
|
|
|
data_value: { kind: "coordinate", args: { x: 1, y: 2, z: 3 } }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const inst = instance(p);
|
2019-02-22 19:09:40 -07:00
|
|
|
inst.setState({ fe: { body: [newVariable] } });
|
|
|
|
expect(inst.updatedFarmEvent.body).toEqual([newVariable]);
|
2018-12-30 11:57:22 -07:00
|
|
|
});
|
|
|
|
|
2019-02-22 19:09:40 -07:00
|
|
|
it("saves the current variable", () => {
|
2018-12-30 11:57:22 -07:00
|
|
|
const p = props();
|
|
|
|
const sequence = fakeSequence();
|
|
|
|
p.findExecutable = () => sequence;
|
2019-02-22 19:09:40 -07:00
|
|
|
const plant = fakePlant();
|
|
|
|
plant.body.id = 1;
|
|
|
|
p.resources = buildResourceIndex([plant]).index;
|
2018-12-30 11:57:22 -07:00
|
|
|
p.resources.sequenceMetas[sequence.uuid] = fakeVariableNameSet("foo");
|
2019-02-22 19:09:40 -07:00
|
|
|
const oldVariable: ParameterApplication = {
|
|
|
|
kind: "parameter_application",
|
2018-12-30 11:57:22 -07:00
|
|
|
args: {
|
|
|
|
label: "foo",
|
|
|
|
data_value: {
|
|
|
|
kind: "point", args: {
|
|
|
|
pointer_id: 1, pointer_type: "Plant"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2019-02-22 19:09:40 -07:00
|
|
|
p.farmEvent.body.body = [oldVariable];
|
2018-12-30 11:57:22 -07:00
|
|
|
const inst = instance(p);
|
2019-02-22 19:09:40 -07:00
|
|
|
expect(inst.updatedFarmEvent.body).toEqual([oldVariable]);
|
2018-12-30 11:57:22 -07:00
|
|
|
});
|
2019-01-13 16:39:26 -07:00
|
|
|
|
|
|
|
it("deletes a farmEvent", async () => {
|
|
|
|
const p = props();
|
|
|
|
p.dispatch = jest.fn(() => Promise.resolve());
|
|
|
|
const inst = instance(p);
|
|
|
|
const wrapper = shallow(<inst.FarmEventDeleteButton />);
|
|
|
|
clickButton(wrapper, 0, "delete");
|
|
|
|
await expect(destroy).toHaveBeenCalledWith(p.farmEvent.uuid);
|
2019-04-09 19:52:12 -06:00
|
|
|
expect(history.push).toHaveBeenCalledWith("/app/designer/events");
|
|
|
|
expect(success).toHaveBeenCalledWith("Deleted event.", "Deleted");
|
2019-01-13 16:39:26 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
it("sets repeat", () => {
|
|
|
|
const p = props();
|
|
|
|
p.dispatch = jest.fn(() => Promise.resolve());
|
|
|
|
const e = {
|
|
|
|
currentTarget: { checked: true }
|
|
|
|
} as React.ChangeEvent<HTMLInputElement>;
|
|
|
|
const inst = instance(p);
|
|
|
|
inst.toggleRepeat(e);
|
|
|
|
expect(inst.state).toEqual({
|
|
|
|
fe: { timeUnit: "daily" },
|
|
|
|
specialStatusLocal: SpecialStatus.DIRTY
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("sets repeat: regimen", () => {
|
|
|
|
const p = props();
|
|
|
|
p.farmEvent.body.executable_type = "Regimen";
|
|
|
|
p.dispatch = jest.fn(() => Promise.resolve());
|
|
|
|
const e = {
|
|
|
|
currentTarget: { checked: true }
|
|
|
|
} as React.ChangeEvent<HTMLInputElement>;
|
|
|
|
const inst = instance(p);
|
|
|
|
inst.toggleRepeat(e);
|
|
|
|
expect(inst.state).toEqual({
|
|
|
|
fe: { timeUnit: "never" },
|
|
|
|
specialStatusLocal: SpecialStatus.DIRTY
|
|
|
|
});
|
|
|
|
});
|
2017-07-26 13:02:00 -06:00
|
|
|
});
|
2018-01-03 18:50:04 -07:00
|
|
|
|
|
|
|
describe("destructureFarmEvent", () => {
|
|
|
|
it("Converts UTC to Bot's local time", () => {
|
|
|
|
const fe = fakeFarmEvent("Sequence", 12);
|
|
|
|
fe.body.start_time = "2017-12-28T21:32:00.000Z";
|
|
|
|
fe.body.end_time = "2018-12-28T22:32:00.000Z";
|
2019-04-09 23:17:03 -06:00
|
|
|
const timeSettings = fakeTimeSettings();
|
|
|
|
timeSettings.utcOffset = 1;
|
|
|
|
const { startTime, endTime } = destructureFarmEvent(fe, timeSettings);
|
2018-01-03 18:50:04 -07:00
|
|
|
expect(startTime).toBe("22:32");
|
|
|
|
expect(endTime).toBe("23:32");
|
|
|
|
});
|
|
|
|
});
|