Farmbot-Web-App/frontend/devices/__tests__/devices_test.tsx

63 lines
2.1 KiB
TypeScript
Raw Normal View History

import * as React from "react";
import { shallow, render } from "enzyme";
2019-09-23 12:56:35 -06:00
import { RawDevices as Devices } from "../devices";
import { Props } from "../interfaces";
import { auth } from "../../__test_support__/fake_state/token";
import { bot } from "../../__test_support__/fake_state/bot";
2017-11-30 20:43:35 -07:00
import {
fakeDevice, buildResourceIndex, FAKE_RESOURCES
} from "../../__test_support__/resource_index_builder";
import { FarmbotOsSettings } from "../components/farmbot_os_settings";
2019-04-09 23:17:03 -06:00
import { fakeTimeSettings } from "../../__test_support__/fake_time_settings";
2019-06-03 17:41:59 -06:00
import { HardwareSettings } from "../components/hardware_settings";
describe("<Devices/>", () => {
2019-04-09 18:45:51 -06:00
const fakeProps = (): Props => ({
userToApi: undefined,
userToMqtt: undefined,
botToMqtt: undefined,
auth: auth,
bot: bot,
deviceAccount: fakeDevice(),
images: [],
2017-11-30 20:43:35 -07:00
dispatch: jest.fn(),
2018-01-27 02:29:13 -07:00
resources: buildResourceIndex(FAKE_RESOURCES).index,
2019-06-03 17:41:59 -06:00
sourceFbosConfig: () => ({ value: undefined, consistent: true }),
2018-03-09 02:34:24 -07:00
sourceFwConfig: jest.fn(),
2018-03-08 21:03:02 -07:00
shouldDisplay: jest.fn(),
firmwareConfig: undefined,
isValidFbosConfig: false,
2018-11-01 11:17:18 -06:00
env: {},
saveFarmwareEnv: jest.fn(),
2019-04-09 23:17:03 -06:00
timeSettings: fakeTimeSettings(),
2019-07-12 14:39:40 -06:00
alerts: [],
});
it("renders relevant panels", () => {
2019-04-09 18:45:51 -06:00
const el = shallow(<Devices {...fakeProps()} />);
expect(el.find(FarmbotOsSettings).length).toBe(1);
});
2019-04-09 18:45:51 -06:00
it("crashes when logged out", () => {
const p = fakeProps();
p.auth = undefined;
expect(() => render(<Devices {...p} />)).toThrow();
});
it("has correct connection status", () => {
const p = fakeProps();
p.botToMqtt = { at: 123, state: "up" };
2019-04-09 18:45:51 -06:00
const wrapper = shallow(<Devices {...p} />);
expect(wrapper.find(FarmbotOsSettings).props().botToMqttLastSeen)
2019-09-05 12:18:18 -06:00
.toEqual(123);
});
2019-06-03 17:41:59 -06:00
it("provides correct firmwareHardware value", () => {
const p = fakeProps();
p.sourceFbosConfig = () => ({ value: "arduino", consistent: true });
const wrapper = shallow(<Devices {...p} />);
expect(wrapper.find(HardwareSettings).props().firmwareHardware)
.toEqual("arduino");
});
});