2020-02-15 11:29:09 -07:00
|
|
|
jest.mock("../../../actions", () => ({
|
|
|
|
updateMCU: jest.fn(),
|
|
|
|
commandErr: jest.fn(),
|
|
|
|
}));
|
|
|
|
|
|
|
|
const mockDevice = {
|
|
|
|
calibrate: jest.fn(() => Promise.resolve({})),
|
|
|
|
findHome: jest.fn(() => Promise.resolve({})),
|
|
|
|
setZero: jest.fn(() => Promise.resolve({})),
|
|
|
|
};
|
|
|
|
jest.mock("../../../../device", () => ({ getDevice: () => mockDevice }));
|
2017-12-16 17:16:19 -07:00
|
|
|
|
|
|
|
import * as React from "react";
|
2020-02-15 11:29:09 -07:00
|
|
|
import { mount, shallow } from "enzyme";
|
2017-12-16 17:16:19 -07:00
|
|
|
import { HomingAndCalibration } from "../homing_and_calibration";
|
|
|
|
import { bot } from "../../../../__test_support__/fake_state/bot";
|
|
|
|
import { updateMCU } from "../../../actions";
|
2018-03-09 02:34:24 -07:00
|
|
|
import {
|
|
|
|
fakeFirmwareConfig
|
|
|
|
} from "../../../../__test_support__/fake_state/resources";
|
2019-06-24 15:39:49 -06:00
|
|
|
import { error, warning } from "../../../../toast/toast";
|
2020-02-07 16:06:40 -07:00
|
|
|
import { inputEvent } from "../../../../__test_support__/fake_html_events";
|
2020-02-15 11:29:09 -07:00
|
|
|
import { panelState } from "../../../../__test_support__/control_panel_state";
|
|
|
|
import { HomingAndCalibrationProps } from "../../interfaces";
|
|
|
|
import { CalibrationRow } from "../calibration_row";
|
2017-12-16 17:16:19 -07:00
|
|
|
|
|
|
|
describe("<HomingAndCalibration />", () => {
|
2020-02-15 11:29:09 -07:00
|
|
|
const fakeProps = (): HomingAndCalibrationProps => ({
|
|
|
|
dispatch: jest.fn(),
|
|
|
|
bot,
|
|
|
|
controlPanelState: panelState(),
|
|
|
|
sourceFwConfig: x => ({
|
|
|
|
value: bot.hardware.mcu_params[x], consistent: true
|
|
|
|
}),
|
|
|
|
firmwareConfig: fakeFirmwareConfig().body,
|
|
|
|
botDisconnected: false,
|
|
|
|
firmwareHardware: undefined,
|
|
|
|
});
|
|
|
|
|
2017-12-16 17:16:19 -07:00
|
|
|
function testAxisLengthInput(
|
2020-02-07 16:06:40 -07:00
|
|
|
provided: string, expected: string | undefined) {
|
2020-02-15 11:29:09 -07:00
|
|
|
const p = fakeProps();
|
|
|
|
p.bot.controlPanelState.homing_and_calibration = true;
|
|
|
|
const result = mount(<HomingAndCalibration {...p} />);
|
2020-02-07 16:06:40 -07:00
|
|
|
const e = inputEvent(provided);
|
2017-12-16 17:16:19 -07:00
|
|
|
const input = result.find("input").first().props();
|
|
|
|
input.onChange && input.onChange(e);
|
|
|
|
input.onSubmit && input.onSubmit(e);
|
2019-01-13 16:39:26 -07:00
|
|
|
expected
|
|
|
|
? expect(updateMCU)
|
|
|
|
.toHaveBeenCalledWith("movement_axis_nr_steps_x", expected)
|
|
|
|
: expect(updateMCU).not.toHaveBeenCalled();
|
2017-12-16 17:16:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
it("long int: too long", () => {
|
2020-02-07 16:06:40 -07:00
|
|
|
testAxisLengthInput("10000000000", undefined);
|
2019-01-13 16:39:26 -07:00
|
|
|
expect(error)
|
|
|
|
.toHaveBeenCalledWith("Value must be less than or equal to 2000000000.");
|
2017-12-16 17:16:19 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
it("long int: ok", () => {
|
2020-02-07 16:06:40 -07:00
|
|
|
testAxisLengthInput("100000", "100000");
|
2018-06-15 18:28:42 -06:00
|
|
|
expect(warning).not.toHaveBeenCalled();
|
2019-01-13 16:39:26 -07:00
|
|
|
expect(error).not.toHaveBeenCalled();
|
2017-12-16 17:16:19 -07:00
|
|
|
});
|
2020-02-15 11:29:09 -07:00
|
|
|
|
|
|
|
it("finds home", () => {
|
|
|
|
const wrapper = shallow(<HomingAndCalibration {...fakeProps()} />);
|
|
|
|
wrapper.find(CalibrationRow).first().props().action("x");
|
|
|
|
expect(mockDevice.findHome).toHaveBeenCalledWith({
|
|
|
|
axis: "x", speed: 100
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("calibrates", () => {
|
|
|
|
const wrapper = shallow(<HomingAndCalibration {...fakeProps()} />);
|
|
|
|
wrapper.find(CalibrationRow).at(1).props().action("all");
|
|
|
|
expect(mockDevice.calibrate).toHaveBeenCalledWith({ axis: "all" });
|
|
|
|
});
|
|
|
|
|
|
|
|
it("sets zero", () => {
|
|
|
|
const wrapper = shallow(<HomingAndCalibration {...fakeProps()} />);
|
|
|
|
wrapper.find(CalibrationRow).last().props().action("all");
|
|
|
|
expect(mockDevice.setZero).toHaveBeenCalledWith("all");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("shows express board related labels", () => {
|
|
|
|
const p = fakeProps();
|
|
|
|
p.firmwareHardware = "express_k10";
|
|
|
|
p.controlPanelState.homing_and_calibration = true;
|
|
|
|
const wrapper = shallow(<HomingAndCalibration {...p} />);
|
|
|
|
expect(wrapper.find(CalibrationRow).first().props().toolTip)
|
|
|
|
.toContain("stall detection");
|
|
|
|
});
|
2017-12-16 17:16:19 -07:00
|
|
|
});
|