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

93 lines
3.2 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-07-15 16:53:28 -06:00
import {
2020-02-28 09:35:32 -07:00
fakeFbosConfig,
2019-07-15 16:53:28 -06:00
} from "../../../../__test_support__/fake_state/resources";
2019-02-26 20:12:02 -07:00
import {
2020-02-28 09:35:32 -07:00
buildResourceIndex,
2019-02-26 20:12:02 -07:00
} 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-07-15 16:53:28 -06:00
import {
2020-02-28 09:35:32 -07:00
fakeTimeSettings,
2019-07-15 16:53:28 -06:00
} 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
2018-03-10 02:09:03 -07:00
it("Disconnected with valid FirmwareConfig", () => {
const p = fakeProps();
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();
const wrapper = shallow(<BoardType {...p} />);
2017-10-04 00:53:26 -06:00
wrapper.find("FBSelect").simulate("change",
{ label: "firmware_hardware", value: "farmduino" });
2019-07-15 16:53:28 -06:00
expect(edit).toHaveBeenCalledWith(fakeConfig, {
firmware_hardware: "farmduino"
});
2019-02-26 20:12:02 -07:00
expect(save).toHaveBeenCalledWith(fakeConfig.uuid);
2017-09-27 21:41:34 -06:00
});
2018-03-13 19:32:19 -06:00
2019-07-15 16:53:28 -06:00
it("deosn't call updateConfig", () => {
const p = fakeProps();
const wrapper = shallow(<BoardType {...p} />);
wrapper.find("FBSelect").simulate("change",
{ label: "firmware_hardware", value: "unknown" });
expect(edit).not.toHaveBeenCalled();
expect(save).not.toHaveBeenCalled();
});
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([
2018-03-13 19:32:19 -06:00
{ label: "Arduino/RAMPS (Genesis v1.2)", value: "arduino" },
{ label: "Farmduino (Genesis v1.3)", value: "farmduino" },
2019-07-15 16:53:28 -06:00
{ label: "Farmduino (Genesis v1.4)", value: "farmduino_k14" },
2020-02-15 11:29:31 -07:00
{ label: "Farmduino (Genesis v1.5)", value: "farmduino_k15" },
{ label: "Farmduino (Express v1.0)", value: "express_k10" },
{ label: "None", value: "none" },
2019-07-15 16:53:28 -06:00
]);
2018-03-13 19:32:19 -06:00
});
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([
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" },
2019-12-27 13:30:58 -07:00
{ label: "Farmduino (Genesis v1.5)", value: "farmduino_k15" },
2019-05-03 13:50:27 -06:00
{ label: "Farmduino (Express v1.0)", value: "express_k10" },
2019-07-15 16:53:28 -06:00
{ label: "None", value: "none" },
2019-05-03 13:50:27 -06:00
]);
});
2017-09-20 01:27:37 -06:00
});