Merge pull request #890 from gabrielburnworth/staging

Test updates
pull/891/head
Rick Carlino 2018-06-16 22:08:15 -05:00 committed by GitHub
commit d96b9bd467
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 335 additions and 242 deletions

View File

@ -1,6 +1,33 @@
import { ReactWrapper } from "enzyme";
import { ReactWrapper, ShallowWrapper } from "enzyme";
import { range } from "lodash";
// tslint:disable-next-line:no-any
export function getProp(i: ReactWrapper<any, {}>, key: string): any {
return i.props()[key];
}
/** Simulate a click and check button text for a button in a wrapper. */
export function clickButton(
wrapper: ReactWrapper | ShallowWrapper,
position: number,
text: string,
options?: { partial_match?: boolean, button_tag?: string }) {
const btnTag = options && options.button_tag ? options.button_tag : "button";
const button = wrapper.find(btnTag).at(position);
const expectedText = text.toLowerCase();
const actualText = button.text().toLowerCase();
options && options.partial_match
? expect(actualText).toContain(expectedText)
: expect(actualText).toEqual(expectedText);
button.simulate("click");
}
/** Like `wrapper.text()`, but only includes buttons. */
export function allButtonText(wrapper: ReactWrapper | ShallowWrapper): string {
const buttons = wrapper.find("button");
const btnCount = buttons.length;
const btnPositions = range(btnCount);
const btnTextArray = btnPositions.map(position =>
wrapper.find("button").at(position).text());
return btnTextArray.join("");
}

View File

@ -1,7 +0,0 @@
import * as React from "react";
export class Wrapper extends React.Component<{}, {}> {
render() {
return <div> {this.props.children} </div>;
}
}

View File

@ -3,14 +3,13 @@ jest.mock("fastclick", () => ({
}));
let mockAuth: AuthState | undefined = undefined;
const mockClear = jest.fn();
jest.mock("../session", () => ({
Session: {
fetchStoredToken: jest.fn(() => mockAuth),
deprecatedGetNum: () => undefined,
deprecatedGetBool: () => undefined,
getAll: () => undefined,
clear: mockClear
clear: jest.fn()
}
}));
@ -27,6 +26,7 @@ import { RootComponent } from "../routes";
import { store } from "../redux/store";
import { AuthState } from "../auth/interfaces";
import { auth } from "../__test_support__/fake_state/token";
import { Session } from "../session";
describe("<RootComponent />", () => {
beforeEach(function () {
@ -37,13 +37,13 @@ describe("<RootComponent />", () => {
mockAuth = undefined;
mockPathname = "/app/account";
shallow(<RootComponent store={store} />);
expect(mockClear).toHaveBeenCalled();
expect(Session.clear).toHaveBeenCalled();
});
it("authorized", () => {
mockAuth = auth;
mockPathname = "/app/account";
shallow(<RootComponent store={store} />);
expect(mockClear).not.toHaveBeenCalled();
expect(Session.clear).not.toHaveBeenCalled();
});
});

View File

@ -0,0 +1,101 @@
const mockResource: { kind: string, body: { id: number | undefined } }
= { kind: "Regimen", body: { id: 1 } };
jest.mock("../../resources/reducer", () => ({
findByUuid: () => (mockResource)
}));
jest.mock("../../resources/actions", () => ({
destroyOK: jest.fn(),
destroyNO: jest.fn()
}));
jest.mock("../maybe_start_tracking", () => ({
maybeStartTracking: jest.fn()
}));
let mockDelete: Promise<{}> = Promise.resolve({});
jest.mock("axios", () => ({
default: {
delete: jest.fn(() => mockDelete)
}
}));
import { destroy } from "../crud";
import { API } from "../api";
import axios from "axios";
import { destroyOK, destroyNO } from "../../resources/actions";
describe("destroy", () => {
beforeEach(() => {
jest.clearAllMocks();
mockResource.body.id = 1;
mockResource.kind = "Regimen";
});
API.setBaseUrl("http://localhost:3000");
// tslint:disable-next-line:no-any
const fakeGetState = () => ({ resources: { index: {} } } as any);
const fakeDestroy = () => destroy("fakeResource")(jest.fn(), fakeGetState);
const expectDestroyed = () => {
const kind = mockResource.kind.toLowerCase() + "s";
expect(axios.delete)
.toHaveBeenCalledWith(`http://localhost:3000/api/${kind}/1`);
expect(destroyOK).toHaveBeenCalledWith(mockResource);
};
const expectNotDestroyed = () => {
expect(axios.delete).not.toHaveBeenCalled();
};
it("not confirmed", () => {
expect(fakeDestroy()).rejects.toEqual("User pressed cancel");
expectNotDestroyed();
});
it("id: 0", () => {
mockResource.body.id = 0;
window.confirm = () => true;
expect(fakeDestroy()).resolves.toEqual("");
expect(destroyOK).toHaveBeenCalledWith(mockResource);
});
it("id: undefined", () => {
mockResource.body.id = undefined;
window.confirm = () => true;
expect(fakeDestroy()).resolves.toEqual("");
expect(destroyOK).toHaveBeenCalledWith(mockResource);
});
it("confirmed", async () => {
window.confirm = () => true;
await expect(fakeDestroy()).resolves.toEqual(undefined);
expectDestroyed();
});
it("confirmation overridden", async () => {
window.confirm = () => false;
const forceDestroy = () =>
destroy("fakeResource", true)(jest.fn(), fakeGetState);
await expect(forceDestroy()).resolves.toEqual(undefined);
expectDestroyed();
});
it("confirmation not required", async () => {
mockResource.kind = "Sensor";
window.confirm = () => false;
await expect(fakeDestroy()).resolves.toEqual(undefined);
expectDestroyed();
});
it("rejected", async () => {
window.confirm = () => true;
mockDelete = Promise.reject("error");
await expect(fakeDestroy()).rejects.toEqual("error");
expect(destroyNO).toHaveBeenCalledWith({
err: "error",
statusBeforeError: undefined,
uuid: "fakeResource"
});
});
});

View File

@ -3,6 +3,7 @@ import { mount } from "enzyme";
import { AxisInputBoxGroup } from "../axis_input_box_group";
import { BotPosition } from "../../devices/interfaces";
import { AxisInputBoxGroupProps } from "../interfaces";
import { clickButton } from "../../__test_support__/helpers";
describe("<AxisInputBoxGroup />", () => {
beforeEach(function () {
@ -45,9 +46,7 @@ describe("<AxisInputBoxGroup />", () => {
props.position = coordinates.position;
const wrapper = mount(<AxisInputBoxGroup {...props} />);
wrapper.setState(coordinates.inputs);
const buttons = wrapper.find("button");
expect(buttons.text().toLowerCase()).toEqual("go");
buttons.simulate("click");
clickButton(wrapper, 0, "go");
expect(props.onCommit).toHaveBeenCalledWith(coordinates.expected);
});
}

View File

@ -5,8 +5,8 @@ const mockDevice = {
jest.mock("../../device", () => ({
getDevice: () => (mockDevice)
}));
const mockOk = jest.fn();
jest.mock("farmbot-toastr", () => ({ success: mockOk }));
jest.mock("farmbot-toastr", () => ({ success: jest.fn() }));
import * as React from "react";
import { mount } from "enzyme";

View File

@ -8,8 +8,8 @@ const mockDevice = {
jest.mock("../../device", () => ({
getDevice: () => (mockDevice)
}));
const mockOk = jest.fn();
jest.mock("farmbot-toastr", () => ({ success: mockOk }));
jest.mock("farmbot-toastr", () => ({ success: jest.fn() }));
import * as React from "react";
import { mount } from "enzyme";

View File

@ -21,6 +21,7 @@ import { toggleWebAppBool } from "../../config_storage/actions";
import { Dictionary } from "farmbot";
import { BooleanSetting } from "../../session_keys";
import { Actions } from "../../constants";
import { clickButton } from "../../__test_support__/helpers";
describe("<Move />", () => {
beforeEach(function () {
@ -78,9 +79,7 @@ describe("<Move />", () => {
it("changes step size", () => {
const p = fakeProps();
const wrapper = mount(<Move {...p} />);
const btn = wrapper.find("button").first();
expect(btn.text()).toEqual("1");
btn.simulate("click");
clickButton(wrapper, 0, "1");
expect(p.dispatch).toHaveBeenCalledWith({
type: Actions.CHANGE_STEP_SIZE,
payload: 1

View File

@ -1,6 +1,5 @@
const mockError = jest.fn();
jest.mock("farmbot-toastr", () => ({
error: mockError
error: jest.fn()
}));
import * as React from "react";
@ -9,6 +8,9 @@ import { Peripherals } from "../index";
import { bot } from "../../../__test_support__/fake_state/bot";
import { PeripheralsProps } from "../../../devices/interfaces";
import { fakePeripheral } from "../../../__test_support__/fake_state/resources";
import { clickButton } from "../../../__test_support__/helpers";
import { SpecialStatus } from "../../../resources/tagged_resources";
import { error } from "farmbot-toastr";
describe("<Peripherals />", () => {
beforeEach(function () {
@ -25,7 +27,7 @@ describe("<Peripherals />", () => {
}
it("renders", () => {
const wrapper = mount(<Peripherals {...fakeProps() } />);
const wrapper = mount(<Peripherals {...fakeProps()} />);
["Peripherals", "Edit", "Save", "Fake Pin", "1"].map(string =>
expect(wrapper.text()).toContain(string));
const saveButton = wrapper.find("button").at(1);
@ -34,22 +36,19 @@ describe("<Peripherals />", () => {
});
it("isEditing", () => {
const wrapper = mount(<Peripherals {...fakeProps() } />);
const wrapper = mount(<Peripherals {...fakeProps()} />);
expect(wrapper.state().isEditing).toBeFalsy();
const edit = wrapper.find("button").at(0);
expect(edit.text()).toEqual("Edit");
edit.simulate("click");
clickButton(wrapper, 0, "edit");
expect(wrapper.state().isEditing).toBeTruthy();
});
function attemptSave(num: number, error: string) {
function attemptSave(num: number, errorString: string) {
const p = fakeProps();
p.peripherals[0].body.pin = num;
const wrapper = mount(<Peripherals {...p } />);
const save = wrapper.find("button").at(1);
expect(save.text()).toContain("Save");
save.simulate("click");
expect(mockError).toHaveBeenLastCalledWith(error);
p.peripherals[0].specialStatus = SpecialStatus.DIRTY;
const wrapper = mount(<Peripherals {...p} />);
clickButton(wrapper, 1, "save", { partial_match: true });
expect(error).toHaveBeenLastCalledWith(errorString);
}
it("save attempt: pin number too small", () => {
@ -63,30 +62,25 @@ describe("<Peripherals />", () => {
it("saves", () => {
const p = fakeProps();
p.peripherals[0].body.pin = 1;
const wrapper = mount(<Peripherals {...p } />);
const save = wrapper.find("button").at(1);
expect(save.text()).toContain("Save");
save.simulate("click");
p.peripherals[0].specialStatus = SpecialStatus.DIRTY;
const wrapper = mount(<Peripherals {...p} />);
clickButton(wrapper, 1, "save", { partial_match: true });
expect(p.dispatch).toHaveBeenCalled();
});
it("adds empty peripheral", () => {
const p = fakeProps();
const wrapper = mount(<Peripherals {...p } />);
const wrapper = mount(<Peripherals {...p} />);
wrapper.setState({ isEditing: true });
const add = wrapper.find("button").at(2);
expect(add.text()).toEqual("");
add.simulate("click");
clickButton(wrapper, 2, "");
expect(p.dispatch).toHaveBeenCalled();
});
it("adds farmduino peripherals", () => {
const p = fakeProps();
const wrapper = mount(<Peripherals {...p } />);
const wrapper = mount(<Peripherals {...p} />);
wrapper.setState({ isEditing: true });
const add = wrapper.find("button").at(3);
expect(add.text()).toEqual("Farmduino");
add.simulate("click");
clickButton(wrapper, 3, "farmduino");
expect(p.dispatch).toHaveBeenCalledTimes(5);
});
});

View File

@ -1,6 +1,5 @@
const mockError = jest.fn();
jest.mock("farmbot-toastr", () => ({
error: mockError
error: jest.fn()
}));
import * as React from "react";
@ -9,6 +8,9 @@ import { Sensors } from "../index";
import { bot } from "../../../__test_support__/fake_state/bot";
import { SensorsProps } from "../../../devices/interfaces";
import { fakeSensor } from "../../../__test_support__/fake_state/resources";
import { error } from "farmbot-toastr";
import { clickButton } from "../../../__test_support__/helpers";
import { SpecialStatus } from "../../../resources/tagged_resources";
describe("<Sensors />", () => {
beforeEach(function () {
@ -40,9 +42,7 @@ describe("<Sensors />", () => {
it("isEditing", () => {
const wrapper = mount(<Sensors {...fakeProps()} />);
expect(wrapper.state().isEditing).toBeFalsy();
const edit = wrapper.find("button").at(0);
expect(edit.text()).toEqual("Edit");
edit.simulate("click");
clickButton(wrapper, 0, "edit");
expect(wrapper.state().isEditing).toBeTruthy();
});
@ -50,20 +50,18 @@ describe("<Sensors />", () => {
const p = fakeProps();
p.sensors[0].body.pin = 1;
p.sensors[1].body.pin = 1;
p.sensors[0].specialStatus = SpecialStatus.DIRTY;
const wrapper = mount(<Sensors {...p} />);
const save = wrapper.find("button").at(1);
expect(save.text()).toContain("Save");
save.simulate("click");
expect(mockError).toHaveBeenLastCalledWith("Pin numbers must be unique.");
clickButton(wrapper, 1, "save", { partial_match: true });
expect(error).toHaveBeenLastCalledWith("Pin numbers must be unique.");
});
it("saves", () => {
const p = fakeProps();
p.sensors[0].body.pin = 1;
p.sensors[0].specialStatus = SpecialStatus.DIRTY;
const wrapper = mount(<Sensors {...p} />);
const save = wrapper.find("button").at(1);
expect(save.text()).toContain("Save");
save.simulate("click");
clickButton(wrapper, 1, "save", { partial_match: true });
expect(p.dispatch).toHaveBeenCalled();
});
@ -71,9 +69,7 @@ describe("<Sensors />", () => {
const p = fakeProps();
const wrapper = mount(<Sensors {...p} />);
wrapper.setState({ isEditing: true });
const add = wrapper.find("button").at(2);
expect(add.text()).toEqual("");
add.simulate("click");
clickButton(wrapper, 2, "");
expect(p.dispatch).toHaveBeenCalled();
});
@ -81,9 +77,7 @@ describe("<Sensors />", () => {
const p = fakeProps();
const wrapper = mount(<Sensors {...p} />);
wrapper.setState({ isEditing: true });
const add = wrapper.find("button").at(3);
expect(add.text()).toEqual("Stock sensors");
add.simulate("click");
clickButton(wrapper, 3, "stock sensors");
expect(p.dispatch).toHaveBeenCalledTimes(2);
});
});

View File

@ -1,27 +1,44 @@
import * as React from "react";
import { fakeWebcamFeed } from "../../../__test_support__/fake_state/resources";
import { shallow } from "enzyme";
import { mount } from "enzyme";
import { props } from "../test_helpers";
import { Edit } from "../edit";
import { SpecialStatus } from "../../../resources/tagged_resources";
import { clickButton } from "../../../__test_support__/helpers";
import { WebcamPanelProps } from "../interfaces";
describe("<Edit/>", () => {
it("renders the list of feeds", () => {
const fakeProps = (): WebcamPanelProps => {
const feed1 = fakeWebcamFeed();
const feed2 = fakeWebcamFeed();
feed1.specialStatus = SpecialStatus.DIRTY;
const p = props([feed1, feed2]);
const el = shallow(<Edit {...p} />);
const inputs = el.html();
expect(inputs).toContain(feed1.body.name);
expect(inputs).toContain(feed1.body.url);
expect(inputs).toContain(feed2.body.name);
expect(inputs).toContain(feed2.body.url);
expect(el.html()).toContain("Save*");
el.find("button").at(1).simulate("click");
expect(p.save).toHaveBeenCalledWith(feed1);
feed1.specialStatus = SpecialStatus.SAVED;
el.update();
expect(el.text()).not.toContain("Save*");
return props([feed1, feed2]);
};
it("renders the list of feeds", () => {
const p = fakeProps();
const wrapper = mount(<Edit {...p} />);
[
p.feeds[0].body.name,
p.feeds[0].body.url,
p.feeds[1].body.name,
p.feeds[1].body.url
].map(text =>
expect(wrapper.html()).toContain(text));
});
it("saves feeds", () => {
const p = fakeProps();
const wrapper = mount(<Edit {...p} />);
clickButton(wrapper, 1, "save*");
expect(p.save).toHaveBeenCalledWith(p.feeds[0]);
});
it("shows feeds as saved", () => {
const p = fakeProps();
p.feeds[0].specialStatus = SpecialStatus.SAVED;
p.feeds[1].specialStatus = SpecialStatus.SAVED;
const wrapper = mount(<Edit {...p} />);
expect(wrapper.find("button").at(1).text()).toEqual("Save");
});
});

View File

@ -8,15 +8,27 @@ import { WebcamPanel, preToggleCleanup } from "../index";
import { fakeWebcamFeed } from "../../../__test_support__/fake_state/resources";
import { destroy, save } from "../../../api/crud";
import { SpecialStatus } from "../../../resources/tagged_resources";
import { clickButton, allButtonText } from "../../../__test_support__/helpers";
describe("<WebcamPanel/>", () => {
it("toggles form states", () => {
it("toggles form state to edit", () => {
const props = { feeds: [], dispatch: jest.fn() };
const el = mount(<WebcamPanel {...props} />);
expect(el.text()).toContain("edit");
el.find("button").first().simulate("click");
el.update();
expect(el.text()).toContain("view");
const wrapper = mount(<WebcamPanel {...props} />);
expect(wrapper.state().activeMenu).toEqual("show");
const text = allButtonText(wrapper);
expect(text.toLowerCase()).not.toContain("view");
clickButton(wrapper, 0, "edit");
expect(wrapper.state().activeMenu).toEqual("edit");
});
it("toggles form state to view", () => {
const props = { feeds: [], dispatch: jest.fn() };
const wrapper = mount(<WebcamPanel {...props} />);
wrapper.setState({ activeMenu: "edit" });
const text = allButtonText(wrapper);
expect(text.toLowerCase()).not.toContain("edit");
clickButton(wrapper, 2, "view");
expect(wrapper.state().activeMenu).toEqual("show");
});
});

View File

@ -21,15 +21,12 @@ jest.mock("../../device", () => ({
return mockDevice;
}
}));
const mockOk = jest.fn();
const mockInfo = jest.fn();
const mockError = jest.fn();
const mockWarning = jest.fn();
jest.mock("farmbot-toastr", () => ({
success: mockOk,
info: mockInfo,
error: mockError,
warning: mockWarning,
success: jest.fn(),
info: jest.fn(),
error: jest.fn(),
warning: jest.fn(),
}));
let mockGetRelease: Promise<{}> = Promise.resolve({});
@ -52,6 +49,7 @@ import axios from "axios";
import { SpecialStatus } from "../../resources/tagged_resources";
import { McuParamName } from "farmbot";
import { bot } from "../../__test_support__/fake_state/bot";
import { success, error, warning, info } from "farmbot-toastr";
describe("checkControllerUpdates()", function () {
beforeEach(function () {
@ -61,7 +59,7 @@ describe("checkControllerUpdates()", function () {
it("calls checkUpdates", async () => {
await actions.checkControllerUpdates();
expect(mockDevice.checkUpdates).toHaveBeenCalled();
expect(mockOk).toHaveBeenCalled();
expect(success).toHaveBeenCalled();
});
});
@ -73,7 +71,7 @@ describe("powerOff()", function () {
it("calls powerOff", async () => {
await actions.powerOff();
expect(mockDevice.powerOff).toHaveBeenCalled();
expect(mockOk).toHaveBeenCalled();
expect(success).toHaveBeenCalled();
});
});
@ -103,7 +101,7 @@ describe("reboot()", function () {
it("calls reboot", async () => {
await actions.reboot();
expect(mockDevice.reboot).toHaveBeenCalled();
expect(mockOk).toHaveBeenCalled();
expect(success).toHaveBeenCalled();
});
});
@ -134,7 +132,7 @@ describe("sync()", function () {
actions.sync()(jest.fn(), getState);
expect(mockDevice.sync).not.toHaveBeenCalled();
const expectedMessage = ["FarmBot is not connected.", "Disconnected", "red"];
expect(mockInfo).toBeCalledWith(...expectedMessage);
expect(info).toBeCalledWith(...expectedMessage);
});
});
@ -147,7 +145,7 @@ describe("execSequence()", function () {
const s = fakeSequence().body;
await actions.execSequence(s);
expect(mockDevice.execSequence).toHaveBeenCalledWith(s.id);
expect(mockOk).toHaveBeenCalled();
expect(success).toHaveBeenCalled();
});
it("implodes when executing unsaved sequences", () => {
@ -264,7 +262,7 @@ describe("updateMCU()", () => {
await actions.updateMCU(
"movement_min_spd_x", "100")(jest.fn(), () => state);
expect(mockDevice.updateMcu).not.toHaveBeenCalled();
expect(mockWarning).toHaveBeenCalledWith(
expect(warning).toHaveBeenCalledWith(
"Minimum speed should always be lower than maximum");
});
});
@ -277,7 +275,7 @@ describe("pinToggle()", function () {
it("calls togglePin", async () => {
await actions.pinToggle(5);
expect(mockDevice.togglePin).toHaveBeenCalledWith({ pin_number: 5 });
expect(mockOk).not.toHaveBeenCalled();
expect(success).not.toHaveBeenCalled();
});
});
@ -290,7 +288,7 @@ describe("homeAll()", function () {
await actions.homeAll(100);
expect(mockDevice.home)
.toHaveBeenCalledWith({ axis: "all", speed: 100 });
expect(mockOk).not.toHaveBeenCalled();
expect(success).not.toHaveBeenCalled();
});
});
@ -346,7 +344,7 @@ describe("fetchReleases()", () => {
const dispatch = jest.fn();
await actions.fetchReleases("url")(dispatch);
expect(axios.get).toHaveBeenCalledWith("url");
expect(mockError).not.toHaveBeenCalled();
expect(error).not.toHaveBeenCalled();
expect(dispatch).toHaveBeenCalledWith({
payload: { version: "1.0.0", commit: undefined },
type: Actions.FETCH_OS_UPDATE_INFO_OK
@ -360,7 +358,7 @@ describe("fetchReleases()", () => {
const dispatch = jest.fn();
await actions.fetchReleases("url", { beta: true })(dispatch);
expect(axios.get).toHaveBeenCalledWith("url");
expect(mockError).not.toHaveBeenCalled();
expect(error).not.toHaveBeenCalled();
expect(dispatch).toHaveBeenCalledWith({
payload: { version: "1.0.0-beta", commit: "commit" },
type: Actions.FETCH_BETA_OS_UPDATE_INFO_OK
@ -372,7 +370,7 @@ describe("fetchReleases()", () => {
const dispatch = jest.fn();
await actions.fetchReleases("url")(dispatch);
await expect(axios.get).toHaveBeenCalledWith("url");
expect(mockError).toHaveBeenCalledWith(
expect(error).toHaveBeenCalledWith(
"Could not download FarmBot OS update information.");
expect(dispatch).toHaveBeenCalledWith({
payload: "error",
@ -385,7 +383,7 @@ describe("fetchReleases()", () => {
const dispatch = jest.fn();
await actions.fetchReleases("url", { beta: true })(dispatch);
await expect(axios.get).toHaveBeenCalledWith("url");
expect(mockError).not.toHaveBeenCalled();
expect(error).not.toHaveBeenCalled();
expect(dispatch).toHaveBeenCalledWith({
payload: "error",
type: "FETCH_BETA_OS_UPDATE_INFO_ERROR"
@ -448,7 +446,7 @@ describe("fetchMinOsFeatureData()", () => {
const dispatch = jest.fn();
await actions.fetchMinOsFeatureData("url")(dispatch);
await expect(axios.get).toHaveBeenCalledWith("url");
expect(mockError).not.toHaveBeenCalled();
expect(error).not.toHaveBeenCalled();
expect(dispatch).toHaveBeenCalledWith({
payload: "error",
type: "FETCH_MIN_OS_FEATURE_INFO_ERROR"
@ -492,7 +490,7 @@ describe("updateConfig()", () => {
describe("badVersion()", () => {
it("warns of old FBOS version", () => {
actions.badVersion();
expect(mockInfo).toHaveBeenCalledWith(
expect(info).toHaveBeenCalledWith(
expect.stringContaining("old version"), "Please Update", "red");
});
});

View File

@ -6,6 +6,7 @@ import { Actions } from "../../../constants";
import { bot } from "../../../__test_support__/fake_state/bot";
import { panelState } from "../../../__test_support__/control_panel_state";
import { fakeFirmwareConfig } from "../../../__test_support__/fake_state/resources";
import { clickButton } from "../../../__test_support__/helpers";
describe("<HardwareSettings />", () => {
beforeEach(() => {
@ -43,9 +44,9 @@ describe("<HardwareSettings />", () => {
payload: boolean | string) {
const p = fakeProps();
const wrapper = mount(<HardwareSettings {...p} />);
const button = wrapper.find(buttonElement).at(buttonIndex);
expect(button.text().toLowerCase()).toContain(buttonText);
button.simulate("click");
clickButton(wrapper, buttonIndex, buttonText, {
button_tag: buttonElement, partial_match: true
});
expect(p.dispatch).toHaveBeenCalledWith({ payload, type });
}

View File

@ -5,11 +5,10 @@ const mockDevice = {
jest.mock("../../../../device", () => ({
getDevice: () => (mockDevice)
}));
const mockToast = jest.fn();
jest.mock("farmbot-toastr", () => ({
success: mockToast,
info: mockToast,
error: mockToast
success: jest.fn(),
info: jest.fn(),
error: jest.fn()
}));
import * as React from "react";

View File

@ -4,14 +4,14 @@ const mockDevice = {
jest.mock("../../../../device", () => ({
getDevice: () => (mockDevice)
}));
const mockInfo = jest.fn();
const mockError = jest.fn();
jest.mock("farmbot-toastr", () => ({ info: mockInfo, error: mockError }));
jest.mock("farmbot-toastr", () => ({ info: jest.fn(), error: jest.fn() }));
import * as React from "react";
import { mount, shallow } from "enzyme";
import { CameraSelection } from "../camera_selection";
import { CameraSelectionProps } from "../interfaces";
import { info } from "farmbot-toastr";
describe("<CameraSelection/>", () => {
beforeEach(function () {
@ -41,7 +41,7 @@ describe("<CameraSelection/>", () => {
const cameraSelection = shallow(<CameraSelection {...fakeProps()} />);
cameraSelection.find("FBSelect")
.simulate("change", { label: "My Camera", value: "mycamera" });
expect(mockInfo)
expect(info)
.toHaveBeenCalledWith("Sending camera configuration...", "Sending");
expect(mockDevice.setUserEnv)
.toHaveBeenCalledWith({ camera: "\"mycamera\"" });

View File

@ -5,8 +5,8 @@ const mockDevice = {
jest.mock("../../../../device", () => ({
getDevice: () => (mockDevice)
}));
const mockOk = jest.fn();
jest.mock("farmbot-toastr", () => ({ success: mockOk }));
jest.mock("farmbot-toastr", () => ({ success: jest.fn() }));
import * as React from "react";
import { mount } from "enzyme";

View File

@ -2,8 +2,7 @@ jest.mock("../../../actions", () => ({
updateMCU: jest.fn()
}));
const mockWarn = jest.fn();
jest.mock("farmbot-toastr", () => ({ warning: mockWarn }));
jest.mock("farmbot-toastr", () => ({ warning: jest.fn() }));
import * as React from "react";
import { mount } from "enzyme";
@ -13,6 +12,7 @@ import { updateMCU } from "../../../actions";
import {
fakeFirmwareConfig
} from "../../../../__test_support__/fake_state/resources";
import { warning } from "farmbot-toastr";
describe("<HomingAndCalibration />", () => {
beforeEach(function () {
@ -42,18 +42,18 @@ describe("<HomingAndCalibration />", () => {
}
it("short int", () => {
testAxisLengthInput("5.0.0", "100000", "32000");
expect(mockWarn)
expect(warning)
.toHaveBeenCalledWith("Maximum input is 32,000. Rounding down.");
});
it("long int: too long", () => {
testAxisLengthInput("6.0.0", "10000000000", "2000000000");
expect(mockWarn)
expect(warning)
.toHaveBeenCalledWith("Maximum input is 2,000,000,000. Rounding down.");
});
it("long int: ok", () => {
testAxisLengthInput("6.0.0", "100000", "100000");
expect(mockWarn).not.toHaveBeenCalled();
expect(warning).not.toHaveBeenCalled();
});
});

View File

@ -1,9 +1,6 @@
const mockHistory = jest.fn();
let mockPath = "/app/designer/plants";
jest.mock("../../history", () => ({
history: {
push: mockHistory
},
history: { push: jest.fn() },
getPathArray: jest.fn(() => { return mockPath.split("/"); })
}));
@ -17,6 +14,7 @@ import { fakePlant } from "../../__test_support__/fake_state/resources";
import { edit } from "../../api/crud";
import { Actions } from "../../constants";
import { DEFAULT_ICON } from "../../open_farm/icons";
import { history } from "../../history";
describe("movePlant", () => {
beforeEach(() => {
@ -59,7 +57,7 @@ describe("closePlantInfo()", () => {
mockPath = "/app/designer/plants";
const dispatch = jest.fn();
closePlantInfo(dispatch)();
expect(mockHistory).not.toHaveBeenCalled();
expect(history.push).not.toHaveBeenCalled();
expect(dispatch).not.toHaveBeenCalled();
});
@ -67,7 +65,7 @@ describe("closePlantInfo()", () => {
mockPath = "/app/designer/plants/1/edit";
const dispatch = jest.fn();
closePlantInfo(dispatch)();
expect(mockHistory).not.toHaveBeenCalled();
expect(history.push).not.toHaveBeenCalled();
expect(dispatch).not.toHaveBeenCalled();
});
@ -75,7 +73,7 @@ describe("closePlantInfo()", () => {
mockPath = "/app/designer/plants/1";
const dispatch = jest.fn();
closePlantInfo(dispatch)();
expect(mockHistory).toHaveBeenCalledWith("/app/designer/plants");
expect(history.push).toHaveBeenCalledWith("/app/designer/plants");
expect(dispatch).toHaveBeenCalledWith({
payload: undefined, type: Actions.SELECT_PLANT
});

View File

@ -1,7 +1,6 @@
const mockHistory = jest.fn();
jest.mock("../../../history", () => ({
history: {
push: mockHistory
push: jest.fn()
}
}));

View File

@ -2,10 +2,7 @@ jest.mock("../../../open_farm/icons", () => ({
cachedCrop: jest.fn(() => { return Promise.resolve({ spread: 100 }); })
}));
const mockError = jest.fn();
jest.mock("farmbot-toastr", () => ({
error: mockError
}));
jest.mock("farmbot-toastr", () => ({ error: jest.fn() }));
jest.mock("../../actions", () => ({
closePlantInfo: jest.fn(),
@ -33,6 +30,7 @@ import { Actions } from "../../../constants";
import { initSave } from "../../../api/crud";
import { setEggStatus, EggKeys } from "../easter_eggs/status";
import { movePlant, unselectPlant } from "../../actions";
import { error } from "farmbot-toastr";
function fakeProps(): GardenMapProps {
return {
@ -143,7 +141,7 @@ describe("<GardenPlant/>", () => {
wrapper.find("#drop-area-svg").simulate("click", {
preventDefault: jest.fn(), pageX: -100, pageY: -100
});
expect(mockError).toHaveBeenCalledWith(
expect(error).toHaveBeenCalledWith(
expect.stringContaining("Outside of planting area"));
});

View File

@ -1,9 +1,6 @@
const mockHistory = jest.fn();
let mockPath = "/app/designer/plants";
jest.mock("../../../../history", () => ({
history: {
push: mockHistory
},
history: { push: jest.fn() },
getPathArray: jest.fn(() => { return mockPath.split("/"); })
}));
@ -13,6 +10,7 @@ import { fakeMapTransformProps } from "../../../../__test_support__/map_transfor
import { fakeResource } from "../../../../__test_support__/fake_resource";
import { ToolSlotPointer } from "../../../../interfaces";
import { shallow } from "enzyme";
import { history } from "../../../../history";
describe("<ToolSlotLayer/>", () => {
beforeEach(function () {
@ -56,7 +54,7 @@ describe("<ToolSlotLayer/>", () => {
const wrapper = shallow(<ToolSlotLayer {...p} />);
const tools = wrapper.find("g").first();
await tools.simulate("click");
expect(mockHistory).toHaveBeenCalledWith("/app/tools");
expect(history.push).toHaveBeenCalledWith("/app/tools");
});
it("doesn't navigate to tools page", async () => {
@ -65,7 +63,7 @@ describe("<ToolSlotLayer/>", () => {
const wrapper = shallow(<ToolSlotLayer {...p} />);
const tools = wrapper.find("g").first();
await tools.simulate("click");
expect(mockHistory).not.toHaveBeenCalled();
expect(history.push).not.toHaveBeenCalled();
});
it("is in non-clickable mode", () => {

View File

@ -16,6 +16,7 @@ import { CreatePoints, CreatePointsProps } from "../create_points";
import { initSave } from "../../../api/crud";
import { deletePoints } from "../../../farmware/weed_detector/actions";
import { Actions } from "../../../constants";
import { clickButton } from "../../../__test_support__/helpers";
describe("<CreatePoints />", () => {
beforeEach(function () {
@ -37,9 +38,7 @@ describe("<CreatePoints />", () => {
it("creates point", () => {
const wrapper = mount(<CreatePoints {...fakeProps()} />);
wrapper.setState({ cx: 10, cy: 20, r: 30, color: "red" });
const button = wrapper.find("button").at(0);
expect(button.text()).toEqual("Create point");
button.simulate("click");
clickButton(wrapper, 0, "create point");
expect(initSave).toHaveBeenCalledWith({
body: {
meta: { color: "red", created_by: "farm-designer" },

View File

@ -3,12 +3,9 @@ jest.mock("react-redux", () => ({
}));
let mockPath = "";
const mockHistory = jest.fn();
jest.mock("../../../history", () => ({
getPathArray: jest.fn(() => { return mockPath.split("/"); }),
history: {
push: mockHistory
}
history: { push: jest.fn() }
}));
jest.mock("../../../api/crud", () => ({
@ -20,6 +17,7 @@ import { CropInfo } from "../crop_info";
import { shallow, mount } from "enzyme";
import { CropInfoProps } from "../../interfaces";
import { initSave } from "../../../api/crud";
import { history } from "../../../history";
describe("<CropInfo />", () => {
const fakeProps = (): CropInfoProps => {
@ -59,7 +57,7 @@ describe("<CropInfo />", () => {
mockPath = "/app/designer/plants/crop_search/mint";
const wrapper = shallow(<CropInfo {...fakeProps()} />);
wrapper.find(".right-button").simulate("click");
expect(mockHistory).toHaveBeenCalledWith(
expect(history.push).toHaveBeenCalledWith(
"/app/designer/plants/crop_search/mint/add");
});
@ -67,7 +65,7 @@ describe("<CropInfo />", () => {
mockPath = "/app/designer/plants/crop_search/mint";
const wrapper = shallow(<CropInfo {...fakeProps()} />);
wrapper.find(".plant-panel-back-arrow").simulate("click");
expect(mockHistory).toHaveBeenCalledWith(
expect(history.push).toHaveBeenCalledWith(
"/app/designer/plants/crop_search/");
});

View File

@ -9,8 +9,7 @@ jest.mock("../../../history", () => ({
getPathArray: () => ""
}));
const mockErr = jest.fn();
jest.mock("farmbot-toastr", () => ({ error: mockErr }));
jest.mock("farmbot-toastr", () => ({ error: jest.fn() }));
import * as React from "react";
import { EditPlantInfo } from "../edit_plant_info";

View File

@ -1,13 +1,11 @@
const mockHistory = jest.fn();
jest.mock("../../../history", () => ({
push: mockHistory
}));
jest.mock("../../../history", () => ({ push: jest.fn() }));
import * as React from "react";
import { PlantInventoryItem } from "../plant_inventory_item";
import { shallow } from "enzyme";
import { fakePlant } from "../../../__test_support__/fake_state/resources";
import { Actions } from "../../../constants";
import { push } from "../../../history";
describe("<PlantInventoryItem />", () => {
const fakeProps = () => {
@ -19,7 +17,7 @@ describe("<PlantInventoryItem />", () => {
};
it("renders", () => {
const wrapper = shallow(<PlantInventoryItem {...fakeProps() } />);
const wrapper = shallow(<PlantInventoryItem {...fakeProps()} />);
expect(wrapper.text()).toEqual("Strawberry Plant 11 days old");
expect(wrapper.find("div").first().hasClass("hovered")).toBeFalsy();
});
@ -65,7 +63,6 @@ describe("<PlantInventoryItem />", () => {
payload: [p.tpp.uuid],
type: Actions.SELECT_PLANT
});
expect(mockHistory)
.toHaveBeenCalledWith("/app/designer/plants/" + p.tpp.body.id);
expect(push).toHaveBeenCalledWith("/app/designer/plants/" + p.tpp.body.id);
});
});

View File

@ -1,15 +1,14 @@
const mockHistory = jest.fn();
jest.mock("../../../history", () => ({
history: {
push: mockHistory
}
}));
jest.mock("../../../history", () => ({ history: { push: jest.fn() } }));
import * as React from "react";
import { PlantPanel, PlantPanelProps, EditPlantStatus, EditPlantStatusProps } from "../plant_panel";
import {
PlantPanel, PlantPanelProps, EditPlantStatus, EditPlantStatusProps
} from "../plant_panel";
import { shallow } from "enzyme";
import { FormattedPlantInfo } from "../map_state_to_props";
import { Actions } from "../../../constants";
import { clickButton } from "../../../__test_support__/helpers";
import { history } from "../../../history";
describe("<PlantPanel/>", () => {
beforeEach(function () {
@ -48,9 +47,7 @@ describe("<PlantPanel/>", () => {
it("calls destroy", () => {
const p = fakeProps();
const wrapper = shallow(<PlantPanel {...p} />);
const btn = wrapper.find("button").at(1);
expect(btn.text()).toEqual("Delete");
btn.simulate("click");
clickButton(wrapper, 1, "Delete");
expect(p.onDestroy).toHaveBeenCalledWith("Plant.0.0");
});
@ -63,19 +60,15 @@ describe("<PlantPanel/>", () => {
it("enters select mode", () => {
const wrapper = shallow(<PlantPanel info={info} dispatch={jest.fn()} />);
const btn = wrapper.find("button").last();
btn.simulate("click");
expect(btn.text()).toEqual("Delete multiple");
expect(mockHistory).toHaveBeenCalledWith("/app/designer/plants/select");
clickButton(wrapper, 2, "Delete multiple");
expect(history.push).toHaveBeenCalledWith("/app/designer/plants/select");
});
it("navigates to 'move to' mode", () => {
const dispatch = jest.fn();
const wrapper = shallow(<PlantPanel info={info} dispatch={dispatch} />);
const btn = wrapper.find("button").first();
btn.simulate("click");
expect(btn.text()).toEqual("Move FarmBot to this plant");
expect(mockHistory).toHaveBeenCalledWith("/app/designer/plants/move_to");
clickButton(wrapper, 0, "Move FarmBot to this plant");
expect(history.push).toHaveBeenCalledWith("/app/designer/plants/move_to");
expect(dispatch).toHaveBeenCalledWith({
payload: { "x": 12, "y": 34, "z": undefined },
type: Actions.CHOOSE_LOCATION

View File

@ -12,6 +12,7 @@ import { mount, shallow } from "enzyme";
import { SelectPlants, SelectPlantsProps } from "../select_plants";
import { fakePlant } from "../../../__test_support__/fake_state/resources";
import { Actions } from "../../../constants";
import { clickButton } from "../../../__test_support__/helpers";
describe("<SelectPlants />", () => {
beforeEach(function () {
@ -35,7 +36,7 @@ describe("<SelectPlants />", () => {
}
it("displays selected plant", () => {
const wrapper = mount(<SelectPlants {...fakeProps() } />);
const wrapper = mount(<SelectPlants {...fakeProps()} />);
expect(wrapper.text()).toContain("Strawberry");
});
@ -65,9 +66,7 @@ describe("<SelectPlants />", () => {
const p = fakeProps();
p.dispatch = jest.fn();
const wrapper = mount(<SelectPlants {...p} />);
const selectAllButton = wrapper.find("button").at(1);
expect(selectAllButton.text()).toEqual("Select all");
selectAllButton.simulate("click");
clickButton(wrapper, 1, "select all");
expect(p.dispatch).toHaveBeenCalledWith(
{ payload: ["plant.1", "plant.2"], type: Actions.SELECT_PLANT });
});
@ -76,9 +75,7 @@ describe("<SelectPlants />", () => {
const p = fakeProps();
p.dispatch = jest.fn();
const wrapper = mount(<SelectPlants {...p} />);
const selectNoneButton = wrapper.find("button").at(2);
expect(selectNoneButton.text()).toEqual("Select none");
selectNoneButton.simulate("click");
clickButton(wrapper, 2, "select none");
expect(p.dispatch).toHaveBeenCalledWith(
{ payload: undefined, type: Actions.SELECT_PLANT });
});

View File

@ -11,6 +11,7 @@ import * as React from "react";
import { mount, shallow } from "enzyme";
import { FarmwareForms } from "../farmware_forms";
import { fakeFarmwares } from "../../__test_support__/fake_farmwares";
import { clickButton } from "../../__test_support__/helpers";
describe("<FarmwareForms/>", () => {
it("doesn't render", () => {
@ -37,9 +38,7 @@ describe("<FarmwareForms/>", () => {
const wrapper = mount(<FarmwareForms
farmwares={fakeFarmwares()}
user_env={{}} />);
const run = wrapper.find("button").first();
run.simulate("click");
expect(run.text()).toEqual("Run");
clickButton(wrapper, 0, "run");
expect(mockDevice.execScript).toHaveBeenCalledWith(
"My Farmware", [{
kind: "pair",

View File

@ -2,8 +2,7 @@ jest.mock("../../../api/crud", () => ({
destroy: jest.fn(),
}));
const mockOk = jest.fn();
jest.mock("farmbot-toastr", () => ({ success: mockOk }));
jest.mock("farmbot-toastr", () => ({ success: jest.fn() }));
import * as React from "react";
import { mount } from "enzyme";
@ -12,6 +11,7 @@ import { TaggedImage } from "../../../resources/tagged_resources";
import { fakeImages } from "../../../__test_support__/fake_state/images";
import { defensiveClone } from "../../../util";
import { destroy } from "../../../api/crud";
import { clickButton } from "../../../__test_support__/helpers";
describe("<Photos/>", () => {
beforeEach(() => {
@ -69,9 +69,7 @@ describe("<Photos/>", () => {
timeOffset: 0
};
const wrapper = mount(<Photos {...props} />);
const deleteButton = wrapper.find("button").at(1);
expect(deleteButton.text().toLowerCase()).toBe("delete photo");
deleteButton.simulate("click");
clickButton(wrapper, 1, "delete photo");
expect(destroy).toHaveBeenCalledWith("Position 1");
});
});

View File

@ -2,6 +2,7 @@ import * as React from "react";
import { mount } from "enzyme";
import { LogsFilterMenu } from "../filter_menu";
import { LogsFilterMenuProps, LogsState } from "../../interfaces";
import { clickButton } from "../../../__test_support__/helpers";
const logTypes = ["success", "busy", "warn", "error", "info", "fun", "debug"];
@ -52,15 +53,11 @@ describe("<LogsFilterMenu />", () => {
const p = fakeProps();
p.setFilterLevel = (x) => () => setFilterLevel(x);
const wrapper = mount(<LogsFilterMenu {...p} />);
const max = wrapper.find("button").first();
expect(max.text()).toEqual("max");
max.simulate("click");
clickButton(wrapper, 0, "max");
logTypes.map(logType =>
expect(setFilterLevel).toHaveBeenCalledWith(logType));
jest.clearAllMocks();
const normal = wrapper.find("button").at(1);
expect(normal.text()).toEqual("normal");
normal.simulate("click");
clickButton(wrapper, 1, "normal");
logTypes.map(logType =>
expect(setFilterLevel).toHaveBeenCalledWith(logType));
});

View File

@ -1,7 +1,4 @@
const mockPush = jest.fn();
jest.mock("../../../history", () => ({
push: (url: string) => mockPush(url)
}));
jest.mock("../../../history", () => ({ push: jest.fn() }));
jest.unmock("../../../api/crud");
import * as React from "react";
@ -10,6 +7,7 @@ import { CopyButton } from "../copy_button";
import { fakeRegimen } from "../../../__test_support__/fake_state/resources";
import { SpecialStatus } from "../../../resources/tagged_resources";
import { Actions } from "../../../constants";
import { push } from "../../../history";
describe("Copy button", () => {
@ -30,7 +28,7 @@ describe("Copy button", () => {
}),
type: Actions.INIT_RESOURCE
});
expect(mockPush).toHaveBeenCalledWith("/app/regimens/foo_copy_1");
expect(push).toHaveBeenCalledWith("/app/regimens/foo_copy_1");
});
it("Render a button when given a regimen", () => {

View File

@ -12,6 +12,8 @@ import { RegimenEditor } from "../index";
import { fakeRegimen } from "../../../__test_support__/fake_state/resources";
import { RegimenEditorProps } from "../interfaces";
import { destroy, save } from "../../../api/crud";
import { clickButton } from "../../../__test_support__/helpers";
import { SpecialStatus } from "../../../resources/tagged_resources";
describe("<RegimenEditor />", () => {
beforeEach(function () {
@ -19,9 +21,11 @@ describe("<RegimenEditor />", () => {
});
function fakeProps(): RegimenEditorProps {
const regimen = fakeRegimen();
regimen.specialStatus = SpecialStatus.DIRTY;
return {
dispatch: jest.fn(),
current: fakeRegimen(),
current: regimen,
calendar: [{
day: "1",
items: [{
@ -31,7 +35,7 @@ describe("<RegimenEditor />", () => {
sortKey: 0,
day: 1,
dispatch: jest.fn(),
regimen: fakeRegimen(),
regimen: regimen,
item: {
sequence_id: 0, time_offset: 1000
}
@ -57,9 +61,7 @@ describe("<RegimenEditor />", () => {
it("deletes regimen", () => {
const p = fakeProps();
const wrapper = mount(<RegimenEditor {...p} />);
const deleteButton = wrapper.find("button").at(2);
expect(deleteButton.text()).toContain("Delete");
deleteButton.simulate("click");
clickButton(wrapper, 2, "delete");
const expectedUuid = p.current && p.current.uuid;
expect(destroy).toHaveBeenCalledWith(expectedUuid);
});
@ -67,9 +69,7 @@ describe("<RegimenEditor />", () => {
it("saves regimen", () => {
const p = fakeProps();
const wrapper = mount(<RegimenEditor {...p} />);
const saveeButton = wrapper.find("button").at(0);
expect(saveeButton.text()).toContain("Save");
saveeButton.simulate("click");
clickButton(wrapper, 0, "save", { partial_match: true });
const expectedUuid = p.current && p.current.uuid;
expect(save).toHaveBeenCalledWith(expectedUuid);
});

View File

@ -1,11 +1,11 @@
jest.unmock("../../actions");
const mockPush = jest.fn();
jest.mock("../../../history", () => ({ push: mockPush }));
jest.mock("../../../history", () => ({ push: jest.fn() }));
import * as React from "react";
import { AddRegimen } from "../add_button";
import { AddRegimenProps } from "../../interfaces";
import { shallow } from "enzyme";
import { Actions } from "../../../constants";
import { push } from "../../../history";
describe("<AddRegimen/>", () => {
function btn(props: AddRegimenProps) {
@ -22,7 +22,7 @@ describe("<AddRegimen/>", () => {
it("dispatches a new regimen onclick", () => {
const dispatch = jest.fn();
const b = btn({ dispatch, length });
expect(mockPush).not.toHaveBeenCalled();
expect(push).not.toHaveBeenCalled();
b.find("button").simulate("click");
expect(dispatch).toHaveBeenCalledTimes(1);
expect(dispatch).toHaveBeenCalledWith({

View File

@ -22,7 +22,7 @@ import * as React from "react";
import {
SequenceEditorMiddleActive, onDrop
} from "../sequence_editor_middle_active";
import { mount, ReactWrapper, shallow } from "enzyme";
import { mount, shallow } from "enzyme";
import { ActiveMiddleProps } from "../interfaces";
import {
FAKE_RESOURCES, buildResourceIndex
@ -36,6 +36,7 @@ import { SpecialStatus } from "../../resources/tagged_resources";
import { move, splice } from "../step_tiles";
import { copySequence, editCurrentSequence } from "../actions";
import { execSequence } from "../../devices/actions";
import { clickButton } from "../../__test_support__/helpers";
describe("<SequenceEditorMiddleActive/>", () => {
const sequence = fakeSequence();
@ -57,15 +58,9 @@ describe("<SequenceEditorMiddleActive/>", () => {
};
}
function clickButton(position: number, text: string, wrapper: ReactWrapper) {
const button = wrapper.find("button").at(position);
expect(button.text()).toEqual(text);
button.simulate("click");
}
it("saves", () => {
const wrapper = mount(<SequenceEditorMiddleActive {...fakeProps()} />);
clickButton(0, "Save * ", wrapper);
clickButton(wrapper, 0, "Save * ");
expect(save).toHaveBeenCalledWith(expect.stringContaining("Sequence"));
});
@ -74,19 +69,19 @@ describe("<SequenceEditorMiddleActive/>", () => {
p.syncStatus = "synced";
p.sequence.specialStatus = SpecialStatus.SAVED;
const wrapper = mount(<SequenceEditorMiddleActive {...p} />);
clickButton(1, "Test", wrapper);
clickButton(wrapper, 1, "Test");
expect(execSequence).toHaveBeenCalledWith(p.sequence.body);
});
it("deletes", () => {
const wrapper = mount(<SequenceEditorMiddleActive {...fakeProps()} />);
clickButton(2, "Delete", wrapper);
clickButton(wrapper, 2, "Delete");
expect(destroy).toHaveBeenCalledWith(expect.stringContaining("Sequence"));
});
it("copies", () => {
const wrapper = mount(<SequenceEditorMiddleActive {...fakeProps()} />);
clickButton(3, "Copy", wrapper);
clickButton(wrapper, 3, "Copy");
expect(copySequence).toHaveBeenCalledWith(expect.objectContaining({
uuid: expect.stringContaining("Sequence")
}));

View File

@ -4,7 +4,6 @@ import { InputDefault } from "../input_default";
import { mount } from "enzyme";
import { TaggedSequence, SpecialStatus } from "../../../resources/tagged_resources";
import { MoveAbsolute } from "farmbot/dist";
import { Wrapper } from "../../../__test_support__/wrapper";
import { Actions } from "../../../constants";
describe("<InputDefault/>", () => {
@ -49,14 +48,12 @@ describe("<InputDefault/>", () => {
},
"uuid": "Sequence.74.145"
};
const c = mount(<Wrapper>
<InputDefault
index={0}
field="speed"
step={step}
dispatch={dispatcher}
sequence={tr} />
</Wrapper>);
const c = mount(<InputDefault
index={0}
field="speed"
step={step}
dispatch={dispatcher}
sequence={tr} />);
const input = c.find("input").first();
input.simulate("change");
input.simulate("blur");

View File

@ -3,6 +3,7 @@ import { ToolForm } from "../tool_form";
import { mount } from "enzyme";
import { fakeTool } from "../../../__test_support__/fake_state/resources";
import { ToolFormProps } from "../../interfaces";
import { clickButton } from "../../../__test_support__/helpers";
describe("<ToolForm/>", () => {
function fakeProps(): ToolFormProps {
@ -23,9 +24,7 @@ describe("<ToolForm/>", () => {
it("adds stock tools", () => {
const p = fakeProps();
const wrapper = mount(<ToolForm {...p} />);
const add = wrapper.find("button").at(3);
expect(add.text()).toEqual("Stock Tools");
add.simulate("click");
clickButton(wrapper, 3, "stock tools");
expect(p.dispatch).toHaveBeenCalledTimes(6);
});