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

45 lines
1.2 KiB
TypeScript
Raw Normal View History

2017-11-10 14:55:30 -07:00
import * as React from "react";
import {
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/>", () => {
it("renders default content", () => {
const props: EncoderTypeProps = {
hardware: {
encoder_type_x: 1,
encoder_type_y: 1,
encoder_type_z: 1
},
onChange: jest.fn()
};
const el = shallow(<EncoderType {...props} />);
expect(el.find(FBSelect).length).toEqual(3);
// EncoderType
});
});
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();
});
});