homing, calibration, zero row tests

pull/365/head
gabrielburnworth 2017-07-28 18:58:24 -07:00
parent 039ca5a9f2
commit 2017e35707
9 changed files with 132 additions and 5 deletions

View File

@ -10,7 +10,11 @@ export let bot: Everything["bot"] = {
"danger_zone": false
},
"hardware": {
"mcu_params": {},
"mcu_params": {
encoder_enabled_x: 1,
encoder_enabled_y: 1,
encoder_enabled_z: 0
},
"jobs": {},
"location_data": {
"position": {

View File

@ -0,0 +1,25 @@
import { axisTrackingStatus } from "../axis_tracking_status";
import { bot } from "../../../__test_support__/fake_state/bot";
const expected =
[
{
"axis": "x",
"disabled": false
},
{
"axis": "y",
"disabled": false
},
{
"axis": "z",
"disabled": true
}
];
describe("axisTrackingStatus()", () => {
it("returns axis status", () => {
let result = axisTrackingStatus(bot.hardware.mcu_params);
expect(result).toEqual(expected);
});
});

View File

@ -0,0 +1,28 @@
jest.mock("../../../device", () => ({
devices: {
current: {
calibrate: jest.fn()
}
}
}));
import * as React from "react";
import { mount } from "enzyme";
import { CalibrationRow } from "../calibration_row";
import { bot } from "../../../__test_support__/fake_state/bot";
import { devices } from "../../../device";
describe("<HomingRow />", () => {
beforeEach(function () {
jest.clearAllMocks();
});
it("calls device", () => {
let { mock } = devices.current.calibrate as jest.Mock<{}>;
let result = mount(<CalibrationRow hardware={bot.hardware.mcu_params} />);
let thunkx = result.find("LockableButton").at(0).simulate("click");
let thunky = result.find("LockableButton").at(1).simulate("click");
let thunkz = result.find("LockableButton").at(2).simulate("click");
expect(mock.calls.length).toEqual(2);
expect(mock.calls[0][0].axis).toEqual("x");
expect(mock.calls[1][0].axis).toEqual("y");
});
});

View File

@ -0,0 +1,41 @@
jest.mock("../../../device", () => ({
devices: {
current: {
findHome: jest.fn()
}
}
}));
import * as React from "react";
import { mount } from "enzyme";
import { HomingRow } from "../homing_row";
import { bot } from "../../../__test_support__/fake_state/bot";
import { devices } from "../../../device";
describe("<HomingRow />", () => {
beforeEach(function () {
jest.clearAllMocks();
});
// TODO: fix this test
// Code being run is {t("HOME {{axis}}", { axis })}
// Result string is "HOME {{axis}}HOME {{axis}}HOME {{axis}}"
// Console example (result is "HOME {{ax}}"):
// let ax = "x";
// console.log(t("HOME {{ax}}", { ax }));
// it("renders three buttons", () => {
// const wrapper = mount(<HomingRow hardware={bot.hardware.mcu_params} />);
// let txt = wrapper.text();
// ["X", "Y", "Z"].map(function (axis) {
// expect(txt).toContain(`HOME ${axis}`);
// });
// });
it("calls device", () => {
let { mock } = devices.current.findHome as jest.Mock<{}>;
let result = mount(<HomingRow hardware={bot.hardware.mcu_params} />);
let thunkx = result.find("LockableButton").at(0).simulate("click");
let thunky = result.find("LockableButton").at(1).simulate("click");
let thunkz = result.find("LockableButton").at(2).simulate("click");
expect(mock.calls.length).toEqual(2);
expect(mock.calls[0][0].axis).toEqual("x");
expect(mock.calls[1][0].axis).toEqual("y");
});
});

View File

@ -0,0 +1,29 @@
jest.mock("../../../device", () => ({
devices: {
current: {
setZero: jest.fn()
}
}
}));
import * as React from "react";
import { mount } from "enzyme";
import { ZeroRow } from "../zero_row";
import { bot } from "../../../__test_support__/fake_state/bot";
import { devices } from "../../../device";
describe("<HomingRow />", () => {
beforeEach(function () {
jest.clearAllMocks();
});
it("calls device", () => {
let { mock } = devices.current.setZero as jest.Mock<{}>;
let result = mount(<ZeroRow />);
let thunkx = result.find("ZeroButton").at(0).simulate("click");
let thunky = result.find("ZeroButton").at(1).simulate("click");
let thunkz = result.find("ZeroButton").at(2).simulate("click");
expect(mock.calls.length).toEqual(3);
expect(mock.calls[0][0]).toEqual("x");
expect(mock.calls[1][0]).toEqual("y");
expect(mock.calls[2][0]).toEqual("z");
});
});

View File

@ -29,5 +29,5 @@ export function enabledAxisMap(h: McuParams): Record<Xyz, boolean> {
x: !!(h.encoder_enabled_x || h.movement_enable_endpoints_x),
y: !!(h.encoder_enabled_y || h.movement_enable_endpoints_y),
z: !!(h.encoder_enabled_z || h.movement_enable_endpoints_z)
}
};
}

View File

@ -39,7 +39,7 @@ export function CalibrationRow(props: CalibrationRowProps) {
onClick={() => calibrate(axis)}>
{t("CALIBRATE {{axis}}", { axis })}
</LockableButton>
</Col>
</Col>;
})}
</Row>;
}

View File

@ -30,7 +30,7 @@ export function HomingRow(props: HomingRowProps) {
<LockableButton disabled={disabled} onClick={() => findHome(axis)}>
{t("HOME {{axis}}", { axis })}
</LockableButton>
</Col>
</Col>;
})}
</Row>;
}

View File

@ -33,7 +33,7 @@ export function ZeroRow() {
{AXES.map((axis) => {
return <Col xs={2} key={axis}>
<ZeroButton axis={axis} />
</Col>
</Col>;
})}
</Row>;
}