2017-11-10 14:55:30 -07:00
|
|
|
import * as React from "react";
|
2018-01-20 07:46:44 -07:00
|
|
|
import {
|
2020-02-28 09:35:32 -07:00
|
|
|
EncoderType, EncoderTypeProps, LOOKUP, findByType, isEncoderValue,
|
2018-01-20 07:46:44 -07:00
|
|
|
} from "../encoder_type";
|
2017-11-10 14:55:30 -07:00
|
|
|
import { shallow } from "enzyme";
|
2018-01-20 07:46:44 -07:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|