Farmbot-Web-App/frontend/__tests__/controls_popup_test.tsx

79 lines
2.4 KiB
TypeScript
Raw Normal View History

const mockDevice = {
moveRelative: jest.fn(() => { return Promise.resolve(); }),
};
2017-09-08 12:38:46 -06:00
jest.mock("../device", () => ({
getDevice: () => (mockDevice)
2017-09-08 12:38:46 -06:00
}));
2017-07-07 22:19:37 -06:00
import * as React from "react";
import { ControlsPopup } from "../controls_popup";
2017-07-24 13:33:06 -06:00
import { mount } from "enzyme";
2018-01-17 18:13:02 -07:00
import { bot } from "../__test_support__/fake_state/bot";
2018-07-31 18:48:43 -06:00
import { ControlsPopupProps } from "../controls/move/interfaces";
2017-07-07 22:19:37 -06:00
describe("<ControlsPopup />", () => {
2018-04-12 19:27:06 -06:00
const fakeProps = (): ControlsPopupProps => {
return {
dispatch: jest.fn(),
axisInversion: { x: false, y: false, z: false },
botPosition: { x: undefined, y: undefined, z: undefined },
firmwareSettings: bot.hardware.mcu_params,
xySwap: false,
arduinoBusy: false,
stepSize: 100,
};
};
const p = fakeProps();
p.axisInversion.x = true;
const wrapper = mount(<ControlsPopup {...p} />);
2017-07-07 23:37:12 -06:00
2018-10-12 12:14:49 -06:00
afterAll(wrapper.unmount);
2017-07-24 13:33:06 -06:00
it("Has a false initial state", () => {
expect(wrapper.state("isOpen")).toBeFalsy();
});
2017-07-07 23:37:12 -06:00
2017-07-24 13:33:06 -06:00
it("Toggles state", () => {
2017-09-06 04:37:20 -06:00
const parent = wrapper.find("i").first();
2017-07-24 13:33:06 -06:00
parent.simulate("click");
expect(wrapper.state("isOpen")).toBeTruthy();
});
2017-07-07 23:37:12 -06:00
2017-09-08 12:38:46 -06:00
it("x axis is inverted", () => {
2018-01-17 18:13:02 -07:00
const button = wrapper.find("button").at(3);
expect(button.props().title).toBe("move x axis (100)");
2017-09-08 12:38:46 -06:00
button.simulate("click");
2017-12-01 01:47:17 -07:00
expect(mockDevice.moveRelative)
.toHaveBeenCalledWith({ speed: 100, x: 100, y: 0, z: 0 });
2017-09-08 12:38:46 -06:00
});
it("y axis is not inverted", () => {
2018-01-17 18:13:02 -07:00
const button = wrapper.find("button").at(1);
expect(button.props().title).toBe("move y axis (100)");
2017-09-08 12:38:46 -06:00
button.simulate("click");
2017-12-01 01:47:17 -07:00
expect(mockDevice.moveRelative)
.toHaveBeenCalledWith({ speed: 100, x: 0, y: 100, z: 0 });
2017-09-08 12:38:46 -06:00
});
it("disabled when closed", () => {
wrapper.setState({ isOpen: false });
[0, 1, 2, 3].map((i) => wrapper.find("button").at(i).simulate("click"));
2017-12-01 01:47:17 -07:00
expect(mockDevice.moveRelative).not.toHaveBeenCalled();
2017-09-08 12:38:46 -06:00
});
2018-04-12 17:55:38 -06:00
it("swaps axes", () => {
2018-04-12 19:27:06 -06:00
const swappedProps = fakeProps();
swappedProps.xySwap = true;
const swapped = mount(<ControlsPopup {...swappedProps} />);
2018-04-12 17:55:38 -06:00
swapped.setState({ isOpen: true });
expect(swapped.state("isOpen")).toBeTruthy();
const button = swapped.find("button").at(1);
expect(button.props().title).toBe("move x axis (100)");
button.simulate("click");
expect(mockDevice.moveRelative)
.toHaveBeenCalledWith({ speed: 100, x: 100, y: 0, z: 0 });
});
2017-07-07 22:19:37 -06:00
});