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

49 lines
1.7 KiB
TypeScript
Raw Normal View History

2020-02-07 16:06:40 -07:00
jest.mock("../../../actions", () => ({ updateMCU: jest.fn() }));
2017-12-16 17:16:19 -07:00
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";
2020-02-07 16:06:40 -07:00
import { inputEvent } from "../../../../__test_support__/fake_html_events";
2017-12-16 17:16:19 -07:00
describe("<HomingAndCalibration />", () => {
function testAxisLengthInput(
2020-02-07 16:06:40 -07:00
provided: string, expected: string | undefined) {
2017-12-16 17:16:19 -07:00
const dispatch = jest.fn();
bot.controlPanelState.homing_and_calibration = true;
const result = mount(<HomingAndCalibration
2018-03-09 02:34:24 -07:00
dispatch={dispatch}
bot={bot}
firmwareConfig={fakeFirmwareConfig().body}
2020-02-07 16:06:40 -07:00
sourceFwConfig={x => ({
value: bot.hardware.mcu_params[x], consistent: true
})}
2018-03-09 02:34:24 -07:00
botDisconnected={false} />);
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
});
});