Farmbot-Web-App/frontend/controls/__tests__/controls_test.tsx

82 lines
2.7 KiB
TypeScript
Raw Normal View History

import * as React from "react";
import { mount } from "enzyme";
2019-09-23 12:56:35 -06:00
import { RawControls as Controls } from "../controls";
import { bot } from "../../__test_support__/fake_state/bot";
2018-03-10 00:17:53 -07:00
import {
2019-06-14 16:59:11 -06:00
fakePeripheral, fakeWebcamFeed, fakeSensor
2018-03-10 00:17:53 -07:00
} from "../../__test_support__/fake_state/resources";
import { Dictionary } from "farmbot";
import { Props } from "../interfaces";
2019-04-09 23:17:03 -06:00
import { fakeTimeSettings } from "../../__test_support__/fake_time_settings";
2019-04-09 12:02:10 -06:00
describe("<Controls />", () => {
2018-05-01 23:25:09 -06:00
const mockConfig: Dictionary<boolean> = {};
2019-06-07 18:26:32 -06:00
const fakeProps = (): Props => ({
dispatch: jest.fn(),
bot: bot,
feeds: [fakeWebcamFeed()],
peripherals: [fakePeripheral()],
sensors: [fakeSensor()],
botToMqttStatus: "up",
firmwareSettings: bot.hardware.mcu_params,
shouldDisplay: () => true,
getWebAppConfigVal: jest.fn((key) => (mockConfig[key])),
sensorReadings: [],
timeSettings: fakeTimeSettings(),
});
it("shows webcam widget", () => {
2018-05-01 23:25:09 -06:00
mockConfig.hide_webcam_widget = false;
2018-03-09 02:34:24 -07:00
const wrapper = mount(<Controls {...fakeProps()} />);
const txt = wrapper.text().toLowerCase();
2018-03-10 00:17:53 -07:00
["webcam", "move", "peripherals", "sensors"]
.map(string => expect(txt).toContain(string));
});
it("hides webcam widget", () => {
2018-05-01 23:25:09 -06:00
mockConfig.hide_webcam_widget = true;
2018-03-09 02:34:24 -07:00
const wrapper = mount(<Controls {...fakeProps()} />);
const txt = wrapper.text().toLowerCase();
2018-03-10 00:17:53 -07:00
["move", "peripherals", "sensors"]
.map(string => expect(txt).toContain(string));
expect(txt).not.toContain("webcam");
});
2018-03-10 00:17:53 -07:00
2019-06-07 18:26:32 -06:00
it("shows sensors widget", () => {
mockConfig.hide_webcam_widget = false;
mockConfig.hide_sensors = false;
const wrapper = mount(<Controls {...fakeProps()} />);
const txt = wrapper.text().toLowerCase();
["webcam", "move", "peripherals", "sensors"]
.map(string => expect(txt).toContain(string));
});
it("hides sensors widget", () => {
mockConfig.hide_webcam_widget = true;
mockConfig.hide_sensors = true;
const wrapper = mount(<Controls {...fakeProps()} />);
const txt = wrapper.text().toLowerCase();
["move", "peripherals"]
.map(string => expect(txt).toContain(string));
["webcam", "sensors"]
.map(string => expect(txt).not.toContain(string));
});
2018-07-19 23:48:32 -06:00
it("doesn't show sensor readings widget", () => {
const p = fakeProps();
2019-06-14 16:59:11 -06:00
mockConfig.hide_sensors = true;
2018-07-19 23:48:32 -06:00
const wrapper = mount(<Controls {...p} />);
const txt = wrapper.text().toLowerCase();
expect(txt).not.toContain("sensor history");
});
it("shows sensor readings widget", () => {
const p = fakeProps();
2019-06-14 16:59:11 -06:00
mockConfig.hide_sensors = false;
2018-07-19 23:48:32 -06:00
const wrapper = mount(<Controls {...p} />);
const txt = wrapper.text().toLowerCase();
expect(txt).toContain("sensor history");
});
});