Farmbot-Web-App/frontend/devices/components/hardware_settings/__tests__/homing_and_calibration_test...

57 lines
2.0 KiB
TypeScript
Raw Normal View History

2017-12-16 17:16:19 -07:00
jest.mock("../../../actions", () => ({
updateMCU: jest.fn()
}));
import * as React from "react";
import { mount } from "enzyme";
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";
2017-12-16 17:16:19 -07:00
describe("<HomingAndCalibration />", () => {
function testAxisLengthInput(
2019-01-13 16:39:26 -07:00
fw: string, provided: string, expected: string | undefined) {
2017-12-16 17:16:19 -07:00
const dispatch = jest.fn();
bot.controlPanelState.homing_and_calibration = true;
bot.hardware.informational_settings.firmware_version = fw;
const result = mount(<HomingAndCalibration
2018-03-09 02:34:24 -07:00
dispatch={dispatch}
bot={bot}
firmwareConfig={fakeFirmwareConfig().body}
sourceFwConfig={(x) => {
return { value: bot.hardware.mcu_params[x], consistent: true };
}}
botDisconnected={false} />);
2017-12-16 17:16:19 -07:00
const e = { currentTarget: { value: provided } } as
React.SyntheticEvent<HTMLInputElement>;
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("short int", () => {
2019-01-13 16:39:26 -07:00
testAxisLengthInput("5.0.0", "100000", undefined);
expect(error)
.toHaveBeenCalledWith("Value must be less than or equal to 32000.");
2017-12-16 17:16:19 -07:00
});
it("long int: too long", () => {
2019-01-13 16:39:26 -07:00
testAxisLengthInput("6.0.0", "10000000000", undefined);
expect(error)
.toHaveBeenCalledWith("Value must be less than or equal to 2000000000.");
2017-12-16 17:16:19 -07:00
});
it("long int: ok", () => {
testAxisLengthInput("6.0.0", "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
});
});