Farmbot-Web-App/frontend/sequences/__tests__/step_button_cluster_test.tsx

50 lines
1.7 KiB
TypeScript
Raw Normal View History

2017-10-12 21:50:02 -06:00
import * as React from "react";
import { mount } from "enzyme";
2018-09-11 17:17:30 -06:00
import { StepButtonCluster, StepButtonProps } from "../step_button_cluster";
import { Actions } from "../../constants";
2017-10-12 21:50:02 -06:00
describe("<StepButtonCluster />", () => {
2019-04-09 22:11:26 -06:00
const commands = ["move to", "move relative",
"control peripheral", "read sensor",
2017-10-12 21:50:02 -06:00
"wait", "send message", "find home", "if statement", "execute sequence",
"run farmware", "take photo"];
2018-09-11 17:17:30 -06:00
const fakeProps = (): StepButtonProps => ({
dispatch: jest.fn(),
current: undefined,
shouldDisplay: () => false,
2019-04-09 19:45:59 -06:00
stepIndex: undefined,
2018-09-11 17:17:30 -06:00
});
2017-10-12 21:50:02 -06:00
it("renders sequence commands", () => {
2018-09-11 17:17:30 -06:00
const wrapper = mount(<StepButtonCluster {...fakeProps()} />);
2017-10-12 21:50:02 -06:00
commands.map(command =>
expect(wrapper.text().toLowerCase()).toContain(command));
2018-09-11 17:17:30 -06:00
expect(wrapper.text().toLowerCase()).not.toContain("mark as");
});
it("renders future commands", () => {
const p = fakeProps();
p.shouldDisplay = () => true;
const wrapper = mount(<StepButtonCluster {...p} />);
expect(wrapper.text().toLowerCase()).toContain("mark as");
2017-10-12 21:50:02 -06:00
});
it("has correct drag data", () => {
2018-09-11 17:17:30 -06:00
const p = fakeProps();
const wrapper = mount(<StepButtonCluster {...p} />);
2020-04-23 13:11:25 -06:00
const steps = wrapper.find(".step-dragger");
const stepButton = steps.at(steps.length - 2);
expect(stepButton.text().toLowerCase()).toEqual("take photo");
stepButton.simulate("dragStart", { dataTransfer: { setData: jest.fn() } });
2018-09-11 17:17:30 -06:00
expect(p.dispatch).toHaveBeenCalledWith(expect.objectContaining({
type: Actions.PUT_DATA_XFER,
payload: expect.objectContaining({
value: expect.objectContaining({
kind: "take_photo"
})
})
}));
});
2017-10-12 21:50:02 -06:00
});