2017-08-09 19:02:49 -06:00
|
|
|
jest.mock("../../device", () => ({
|
|
|
|
devices: {
|
|
|
|
current: {
|
|
|
|
moveRelative: jest.fn(() => { return Promise.resolve(); }),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
2017-08-28 05:49:13 -06:00
|
|
|
const mockOk = jest.fn();
|
2017-08-09 19:02:49 -06:00
|
|
|
jest.mock("farmbot-toastr", () => ({ success: mockOk }));
|
|
|
|
|
|
|
|
import * as React from "react";
|
|
|
|
import { mount } from "enzyme";
|
|
|
|
import { DirectionButton } from "../direction_button";
|
|
|
|
import { DirectionButtonProps } from "../interfaces";
|
|
|
|
import { devices } from "../../device";
|
|
|
|
|
|
|
|
describe("<DirectionButton/>", function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
buttonProps.disabled = false;
|
|
|
|
});
|
2017-08-28 05:49:13 -06:00
|
|
|
const buttonProps: DirectionButtonProps = {
|
2017-08-09 19:02:49 -06:00
|
|
|
axis: "y",
|
|
|
|
direction: "up",
|
|
|
|
isInverted: false,
|
|
|
|
steps: 1000,
|
|
|
|
disabled: false
|
|
|
|
};
|
|
|
|
|
|
|
|
it("calls move command", () => {
|
2017-08-28 05:49:13 -06:00
|
|
|
const { mock } = devices.current.moveRelative as jest.Mock<{}>;
|
|
|
|
const btn = mount(<DirectionButton {...buttonProps} />);
|
2017-08-09 19:02:49 -06:00
|
|
|
btn.simulate("click");
|
|
|
|
expect(mock.calls.length).toEqual(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("is disabled", () => {
|
2017-08-28 05:49:13 -06:00
|
|
|
const { mock } = devices.current.moveRelative as jest.Mock<{}>;
|
2017-08-09 19:02:49 -06:00
|
|
|
buttonProps.disabled = true;
|
2017-08-28 05:49:13 -06:00
|
|
|
const btn = mount(<DirectionButton {...buttonProps} />);
|
2017-08-09 19:02:49 -06:00
|
|
|
btn.simulate("click");
|
|
|
|
expect(mock.calls.length).toEqual(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("call has correct args", () => {
|
2017-08-28 05:49:13 -06:00
|
|
|
const { mock } = devices.current.moveRelative as jest.Mock<{}>;
|
|
|
|
const btn = mount(<DirectionButton {...buttonProps} />);
|
2017-08-09 19:02:49 -06:00
|
|
|
btn.simulate("click");
|
2017-08-28 05:49:13 -06:00
|
|
|
const argList = mock.calls[0][0];
|
2017-08-09 19:02:49 -06:00
|
|
|
expect(argList.x).toEqual(0);
|
|
|
|
expect(argList.y).toEqual(-1000);
|
|
|
|
expect(argList.z).toEqual(0);
|
|
|
|
});
|
|
|
|
});
|