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

52 lines
1.4 KiB
TypeScript
Raw Normal View History

2017-11-10 14:55:30 -07:00
import * as React from "react";
import {
2020-02-28 09:35:32 -07:00
EncoderType, EncoderTypeProps, LOOKUP, findByType, isEncoderValue,
} from "../encoder_type";
2017-11-10 14:55:30 -07:00
import { shallow } from "enzyme";
import { FBSelect } from "../../../../ui/index";
2017-12-14 16:39:52 -07:00
import { Encoder } from "farmbot";
2017-11-10 14:55:30 -07:00
describe("<EncoderType/>", () => {
2019-06-03 17:41:59 -06:00
const fakeProps = (): EncoderTypeProps => ({
hardware: {
encoder_type_x: 1,
encoder_type_y: 1,
encoder_type_z: 1
},
onChange: jest.fn(),
});
2017-11-10 14:55:30 -07:00
it("renders default content", () => {
2019-06-03 17:41:59 -06:00
const wrapper = shallow(<EncoderType {...fakeProps()} />);
expect(wrapper.find(FBSelect).length).toEqual(3);
});
it("changes encoder type", () => {
const p = fakeProps();
const wrapper = shallow(<EncoderType {...p} />);
wrapper.find(FBSelect).first().simulate("change", { label: "", value: 1 });
expect(p.onChange).toHaveBeenCalledWith("encoder_type_x", 1);
2017-11-10 14:55:30 -07:00
});
});
2017-12-14 16:39:52 -07:00
describe("findByType", () => {
it("handles undefined", () => {
expect(findByType(undefined)).toBe(LOOKUP.DEFAULT);
});
it("Handles known values like Encoder.differential", () => {
expect(findByType(Encoder.differential)).toBe(LOOKUP[Encoder.differential]);
});
it("Handles bad values like NaN", () => {
expect(findByType(-99)).toBe(LOOKUP.DEFAULT);
});
});
describe("isEncoderValue", () => {
it("determines typefulness", () => {
expect(isEncoderValue(-9)).toBeFalsy();
expect(isEncoderValue(Encoder.quadrature)).toBeTruthy();
});
});