Farmbot-Web-App/frontend/controls/move/__tests__/move_test.tsx

86 lines
2.7 KiB
TypeScript
Raw Normal View History

2019-12-27 11:37:54 -07:00
const mockDevice = { moveAbsolute: jest.fn(() => Promise.resolve()) };
jest.mock("../../../device", () => ({ getDevice: () => mockDevice }));
2018-05-01 23:25:09 -06:00
2019-12-27 11:37:54 -07:00
jest.mock("../../../config_storage/actions", () => ({
toggleWebAppBool: jest.fn(),
2018-05-01 23:25:09 -06:00
}));
2017-12-14 20:46:32 -07:00
2019-12-27 11:37:54 -07:00
jest.mock("../../../account/dev/dev_support", () => ({
DevSettings: {
futureFeaturesEnabled: () => false,
}
}));
2018-04-12 17:55:38 -06:00
2017-08-02 15:59:18 -06:00
import * as React from "react";
2018-08-29 18:55:25 -06:00
import { mount, shallow } from "enzyme";
2017-08-02 15:59:18 -06:00
import { Move } from "../move";
2018-07-31 18:48:43 -06:00
import { bot } from "../../../__test_support__/fake_state/bot";
2017-12-14 20:46:32 -07:00
import { MoveProps } from "../interfaces";
2018-07-31 18:48:43 -06:00
import { toggleWebAppBool } from "../../../config_storage/actions";
2018-05-01 23:25:09 -06:00
import { Dictionary } from "farmbot";
2018-07-31 18:48:43 -06:00
import { BooleanSetting } from "../../../session_keys";
import { Actions } from "../../../constants";
import { clickButton } from "../../../__test_support__/helpers";
2017-08-02 15:59:18 -06:00
describe("<Move />", () => {
2018-05-01 23:25:09 -06:00
const mockConfig: Dictionary<boolean> = {};
2019-12-27 11:37:54 -07:00
const fakeProps = (): MoveProps => ({
dispatch: jest.fn(),
bot: bot,
arduinoBusy: false,
firmwareSettings: bot.hardware.mcu_params,
getWebAppConfigVal: jest.fn((key) => (mockConfig[key])),
env: {},
2020-02-07 16:06:40 -07:00
firmwareHardware: undefined,
2019-12-27 11:37:54 -07:00
});
2017-12-14 20:46:32 -07:00
2017-08-02 15:59:18 -06:00
it("has default elements", () => {
2018-03-09 02:34:24 -07:00
const wrapper = mount(<Move {...fakeProps()} />);
const txt = wrapper.text().toLowerCase();
2017-12-14 20:46:32 -07:00
["move amount (mm)", "110100100010000", "x axisy axisz axis", "motor", "go"]
.map(string => expect(txt).toContain(string));
2017-08-02 15:59:18 -06:00
});
it("has only raw encoder data display", () => {
2017-12-14 20:46:32 -07:00
const p = fakeProps();
2018-05-01 23:25:09 -06:00
mockConfig.raw_encoders = true;
2017-12-14 20:46:32 -07:00
const wrapper = mount(<Move {...p} />);
const txt = wrapper.text().toLowerCase();
2017-08-02 15:59:18 -06:00
expect(txt).toContain("raw");
expect(txt).not.toContain("scaled");
});
it("has both encoder data displays", () => {
2017-12-14 20:46:32 -07:00
const p = fakeProps();
2018-05-01 23:25:09 -06:00
mockConfig.raw_encoders = true;
mockConfig.scaled_encoders = true;
2017-12-14 20:46:32 -07:00
const wrapper = mount(<Move {...p} />);
const txt = wrapper.text().toLowerCase();
2017-08-02 15:59:18 -06:00
expect(txt).toContain("raw");
expect(txt).toContain("scaled");
});
2017-12-14 20:46:32 -07:00
it("toggle: invert jog button", () => {
2018-11-09 13:43:51 -07:00
const wrapper = mount<Move>(<Move {...fakeProps()} />);
wrapper.instance().toggle(BooleanSetting.xy_swap)();
2018-05-01 23:25:09 -06:00
expect(toggleWebAppBool).toHaveBeenCalledWith(BooleanSetting.xy_swap);
2017-12-14 20:46:32 -07:00
});
2018-05-01 23:25:09 -06:00
it("changes step size", () => {
const p = fakeProps();
const wrapper = mount(<Move {...p} />);
2019-06-04 16:07:24 -06:00
clickButton(wrapper, 0, "1");
2018-05-01 23:25:09 -06:00
expect(p.dispatch).toHaveBeenCalledWith({
type: Actions.CHANGE_STEP_SIZE,
payload: 1
});
2017-12-14 20:46:32 -07:00
});
2018-08-29 18:55:25 -06:00
it("displays motor position plot", () => {
mockConfig.show_motor_plot = true;
const wrapper = shallow(<Move {...fakeProps()} />);
expect(wrapper.html()).toContain("motor-position-plot");
});
2017-08-02 15:59:18 -06:00
});