2017-08-11 19:56:02 -06:00
|
|
|
jest.mock("../../device", () => ({
|
|
|
|
devices: {
|
|
|
|
current: {
|
|
|
|
home: jest.fn(() => { return Promise.resolve(); }),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
2017-08-28 05:49:13 -06:00
|
|
|
const mockOk = jest.fn();
|
2017-08-11 19:56:02 -06:00
|
|
|
jest.mock("farmbot-toastr", () => ({ success: mockOk }));
|
|
|
|
|
|
|
|
import * as React from "react";
|
|
|
|
import { mount } from "enzyme";
|
|
|
|
import { JogButtons } from "../jog_buttons";
|
|
|
|
import { JogMovementControlsProps } from "../interfaces";
|
|
|
|
import { devices } from "../../device";
|
|
|
|
import { bot } from "../../__test_support__/fake_state/bot";
|
|
|
|
|
|
|
|
describe("<JogButtons/>", function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
jogButtonProps.disabled = false;
|
|
|
|
});
|
2017-08-28 05:49:13 -06:00
|
|
|
const jogButtonProps: JogMovementControlsProps = {
|
2017-08-11 19:56:02 -06:00
|
|
|
bot: bot,
|
|
|
|
x_axis_inverted: false,
|
|
|
|
y_axis_inverted: false,
|
|
|
|
z_axis_inverted: false,
|
|
|
|
disabled: false
|
|
|
|
};
|
|
|
|
|
|
|
|
it("calls home command", () => {
|
2017-08-28 05:49:13 -06:00
|
|
|
const { mock } = devices.current.home as jest.Mock<{}>;
|
|
|
|
const jogButtons = mount(<JogButtons {...jogButtonProps} />);
|
2017-08-11 19:56:02 -06:00
|
|
|
jogButtons.find("button").at(2).simulate("click");
|
|
|
|
expect(mock.calls.length).toEqual(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("is disabled", () => {
|
2017-08-28 05:49:13 -06:00
|
|
|
const { mock } = devices.current.home as jest.Mock<{}>;
|
2017-08-11 19:56:02 -06:00
|
|
|
jogButtonProps.disabled = true;
|
2017-08-28 05:49:13 -06:00
|
|
|
const jogButtons = mount(<JogButtons {...jogButtonProps} />);
|
2017-08-11 19:56:02 -06:00
|
|
|
jogButtons.find("button").at(2).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.home as jest.Mock<{}>;
|
|
|
|
const jogButtons = mount(<JogButtons {...jogButtonProps} />);
|
2017-08-11 19:56:02 -06:00
|
|
|
jogButtons.find("button").at(2).simulate("click");
|
2017-08-28 05:49:13 -06:00
|
|
|
const argList = mock.calls[0][0];
|
2017-08-11 19:56:02 -06:00
|
|
|
expect(argList.axis).toEqual("all");
|
|
|
|
expect(argList.speed).toEqual(100);
|
|
|
|
});
|
|
|
|
});
|