Farmbot-Web-App/frontend/devices/components/hardware_settings/__tests__/calibration_row_test.tsx

42 lines
1.4 KiB
TypeScript
Raw Normal View History

2017-07-28 19:58:24 -06:00
import * as React from "react";
import { mount } from "enzyme";
import { CalibrationRow } from "../calibration_row";
import { bot } from "../../../../__test_support__/fake_state/bot";
2020-02-15 11:29:09 -07:00
import { CalibrationRowProps } from "../../interfaces";
2020-02-18 12:21:09 -07:00
import { DeviceSetting } from "../../../../constants";
2020-02-15 11:29:09 -07:00
describe("<CalibrationRow />", () => {
const fakeProps = (): CalibrationRowProps => ({
type: "calibrate",
hardware: bot.hardware.mcu_params,
botDisconnected: false,
action: jest.fn(),
toolTip: "calibrate",
2020-02-18 12:21:09 -07:00
title: DeviceSetting.calibration,
2020-02-15 11:29:09 -07:00
axisTitle: "calibrate",
});
2017-07-28 19:58:24 -06:00
it("calls device", () => {
2020-02-15 11:29:09 -07:00
const p = fakeProps();
const result = mount(<CalibrationRow {...p} />);
p.hardware.encoder_enabled_x = 1;
p.hardware.encoder_enabled_y = 1;
p.hardware.encoder_enabled_z = 0;
[0, 1, 2].map(i => result.find("LockableButton").at(i).simulate("click"));
expect(p.action).toHaveBeenCalledTimes(2);
["y", "x"].map(x => expect(p.action).toHaveBeenCalledWith(x));
});
it("is not disabled", () => {
const p = fakeProps();
p.type = "zero";
const result = mount(<CalibrationRow {...p} />);
p.hardware.encoder_enabled_x = 0;
p.hardware.encoder_enabled_y = 1;
p.hardware.encoder_enabled_z = 0;
2017-12-01 01:47:17 -07:00
[0, 1, 2].map(i => result.find("LockableButton").at(i).simulate("click"));
2020-02-15 11:29:09 -07:00
expect(p.action).toHaveBeenCalledTimes(3);
["x", "y", "z"].map(x => expect(p.action).toHaveBeenCalledWith(x));
2017-07-28 19:58:24 -06:00
});
});