Farmbot-Web-App/frontend/devices/components/fbos_settings/__tests__/board_type_test.tsx

137 lines
5.1 KiB
TypeScript
Raw Normal View History

2019-02-26 20:12:02 -07:00
jest.mock("../../../../api/crud", () => ({
edit: jest.fn(),
save: jest.fn(),
2017-10-04 00:53:26 -06:00
}));
2017-09-20 01:27:37 -06:00
import * as React from "react";
2017-10-04 00:53:26 -06:00
import { mount, shallow } from "enzyme";
2017-09-20 01:27:37 -06:00
import { BoardType } from "../board_type";
2018-01-27 02:29:13 -07:00
import { BoardTypeProps } from "../interfaces";
2018-01-28 20:25:19 -07:00
import { fakeState } from "../../../../__test_support__/fake_state";
2019-02-26 20:12:02 -07:00
import { fakeFbosConfig } from "../../../../__test_support__/fake_state/resources";
import {
buildResourceIndex
} from "../../../../__test_support__/resource_index_builder";
import { edit, save } from "../../../../api/crud";
2019-04-09 20:31:25 -06:00
import { bot } from "../../../../__test_support__/fake_state/bot";
2019-04-11 21:17:01 -06:00
import { fakeTimeSettings } from "../../../../__test_support__/fake_time_settings";
2017-09-20 01:27:37 -06:00
describe("<BoardType/>", () => {
2019-02-26 20:12:02 -07:00
const fakeConfig = fakeFbosConfig();
const state = fakeState();
state.resources = buildResourceIndex([fakeConfig]);
const fakeProps = (): BoardTypeProps => ({
2019-04-09 20:31:25 -06:00
bot,
2019-07-12 14:39:40 -06:00
alerts: [],
2019-02-26 20:12:02 -07:00
dispatch: jest.fn(x => x(jest.fn(), () => state)),
sourceFbosConfig: () => ({ value: true, consistent: true }),
shouldDisplay: () => false,
2019-04-09 20:31:25 -06:00
botOnline: true,
2019-04-11 21:17:01 -06:00
timeSettings: fakeTimeSettings(),
2019-02-26 20:12:02 -07:00
});
2018-01-27 02:29:13 -07:00
2017-09-20 01:27:37 -06:00
it("Farmduino", () => {
2018-01-27 02:29:13 -07:00
const p = fakeProps();
2019-04-09 20:31:25 -06:00
p.bot.hardware.informational_settings.firmware_version = "5.0.3.F";
2018-01-27 02:29:13 -07:00
const wrapper = mount(<BoardType {...p} />);
2017-09-20 01:27:37 -06:00
expect(wrapper.text()).toContain("Farmduino");
});
2018-03-13 19:32:19 -06:00
it("Farmduino k1.4", () => {
2018-01-27 02:29:13 -07:00
const p = fakeProps();
2019-04-09 20:31:25 -06:00
p.bot.hardware.informational_settings.firmware_version = "5.0.3.G";
2018-01-27 02:29:13 -07:00
const wrapper = mount(<BoardType {...p} />);
2018-03-13 19:32:19 -06:00
expect(wrapper.text()).toContain("1.4");
2017-09-20 01:27:37 -06:00
});
2019-05-03 13:50:27 -06:00
it("Farmduino Express k1.0", () => {
const p = fakeProps();
p.bot.hardware.informational_settings.firmware_version = "5.0.3.E";
const wrapper = mount(<BoardType {...p} />);
expect(wrapper.text()).toContain("Express");
});
2018-03-13 19:32:19 -06:00
it("Arduino/RAMPS", () => {
2018-01-27 02:29:13 -07:00
const p = fakeProps();
2019-04-09 20:31:25 -06:00
p.bot.hardware.informational_settings.firmware_version = "5.0.3.R";
2019-05-03 13:50:27 -06:00
const wrapper = mount<BoardType>(<BoardType {...p} />);
expect(wrapper.text()).toContain("Arduino/RAMPS");
});
it("changes boardType", () => {
const p = fakeProps();
p.bot.hardware.informational_settings.firmware_version = "5.0.3.R";
const wrapper = mount<BoardType>(<BoardType {...p} />);
2017-10-04 00:53:26 -06:00
expect(wrapper.text()).toContain("Arduino/RAMPS");
2019-05-03 13:50:27 -06:00
expect(wrapper.state().boardType).toEqual("arduino");
p.bot.hardware.informational_settings.firmware_version = "5.0.3.F";
wrapper.setProps(p);
expect(wrapper.state().boardType).toEqual("farmduino");
2017-09-20 01:27:37 -06:00
});
2017-09-27 21:41:34 -06:00
it("Undefined", () => {
2018-01-27 02:29:13 -07:00
const p = fakeProps();
2019-04-09 20:31:25 -06:00
p.bot.hardware.informational_settings.firmware_version = undefined;
2018-01-27 02:29:13 -07:00
const wrapper = mount(<BoardType {...p} />);
2017-10-04 00:53:26 -06:00
expect(wrapper.text()).toContain("None");
2017-09-20 01:27:37 -06:00
});
2017-09-27 21:41:34 -06:00
it("Disconnected", () => {
2018-01-27 02:29:13 -07:00
const p = fakeProps();
2019-04-09 20:31:25 -06:00
p.bot.hardware.informational_settings.firmware_version = "Arduino Disconnected!";
2018-03-13 19:32:19 -06:00
expect(mount(<BoardType {...p} />).text()).toContain("None");
2019-04-09 20:31:25 -06:00
p.bot.hardware.informational_settings.firmware_version = "disconnected";
2018-03-13 19:32:19 -06:00
expect(mount(<BoardType {...p} />).text()).toContain("None");
2017-10-04 00:53:26 -06:00
});
2018-03-10 02:09:03 -07:00
it("Stubbed", () => {
const p = fakeProps();
2019-04-09 20:31:25 -06:00
p.bot.hardware.informational_settings.firmware_version = "STUBFW";
2018-03-10 02:09:03 -07:00
const wrapper = mount(<BoardType {...p} />);
expect(wrapper.text()).toContain("None");
});
it("Disconnected with valid FirmwareConfig", () => {
const p = fakeProps();
2019-04-09 20:31:25 -06:00
p.bot.hardware.informational_settings.firmware_version = "Arduino Disconnected!";
2018-03-10 02:09:03 -07:00
p.sourceFbosConfig = () => ({ value: "farmduino", consistent: false });
const wrapper = mount(<BoardType {...p} />);
expect(wrapper.text()).toContain("Farmduino");
});
2017-10-04 00:53:26 -06:00
it("calls updateConfig", () => {
2018-01-27 02:29:13 -07:00
const p = fakeProps();
2019-04-09 20:31:25 -06:00
p.bot.hardware.informational_settings.firmware_version = "Arduino Disconnected!";
2018-01-27 02:29:13 -07:00
const wrapper = shallow(<BoardType {...p} />);
2017-10-04 00:53:26 -06:00
wrapper.find("FBSelect").simulate("change",
{ label: "firmware_hardware", value: "farmduino" });
2019-02-26 20:12:02 -07:00
expect(edit).toHaveBeenCalledWith(fakeConfig, { firmware_hardware: "farmduino" });
expect(save).toHaveBeenCalledWith(fakeConfig.uuid);
2017-09-27 21:41:34 -06:00
});
2018-03-13 19:32:19 -06:00
it("displays standard boards", () => {
const wrapper = shallow(<BoardType {...fakeProps()} />);
2019-07-12 08:06:58 -06:00
const { list } = wrapper.find("FBSelect").props();
expect(list).toEqual([
{ label: "None", value: "none" },
2018-03-13 19:32:19 -06:00
{ label: "Arduino/RAMPS (Genesis v1.2)", value: "arduino" },
{ label: "Farmduino (Genesis v1.3)", value: "farmduino" },
{ label: "Farmduino (Genesis v1.4)", value: "farmduino_k14" }]);
});
2019-05-03 13:50:27 -06:00
it("displays new boards", () => {
const p = fakeProps();
p.shouldDisplay = () => true;
const wrapper = shallow(<BoardType {...p} />);
2019-07-12 08:06:58 -06:00
const { list } = wrapper.find("FBSelect").props();
expect(list).toEqual([
{ label: "None", value: "none" },
2019-05-03 13:50:27 -06:00
{ label: "Arduino/RAMPS (Genesis v1.2)", value: "arduino" },
{ label: "Farmduino (Genesis v1.3)", value: "farmduino" },
{ label: "Farmduino (Genesis v1.4)", value: "farmduino_k14" },
{ label: "Farmduino (Express v1.0)", value: "express_k10" },
]);
});
2017-09-20 01:27:37 -06:00
});