test output cleanup
parent
0c90e09230
commit
fb48165d68
|
@ -0,0 +1,6 @@
|
|||
import * as React from "react";
|
||||
import { mount } from "enzyme";
|
||||
|
||||
export function svgMount(element: React.ReactElement) {
|
||||
return mount(<svg>{element}</svg>);
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
jest.mock("../util/stop_ie", () => {
|
||||
return {
|
||||
stopIE: jest.fn()
|
||||
};
|
||||
});
|
||||
|
||||
jest.mock("../util/util", () => {
|
||||
return {
|
||||
shortRevision: jest.fn(),
|
||||
trim: jest.fn((s: unknown) => s),
|
||||
defensiveClone: jest.fn((s: unknown) => s)
|
||||
};
|
||||
});
|
||||
|
||||
jest.mock("../i18n", () => {
|
||||
return {
|
||||
detectLanguage: jest.fn(() => Promise.resolve())
|
||||
};
|
||||
});
|
||||
|
||||
jest.mock("i18next", () => {
|
||||
return {
|
||||
init: jest.fn()
|
||||
};
|
||||
});
|
||||
|
||||
jest.mock("../routes", () => {
|
||||
return {
|
||||
attachAppToDom: { mock: "Yeah" }
|
||||
};
|
||||
});
|
||||
|
||||
import { stopIE } from "../util/stop_ie";
|
||||
import { shortRevision } from "../util/util";
|
||||
import { detectLanguage } from "../i18n";
|
||||
import I from "i18next";
|
||||
|
||||
describe("entry file", () => {
|
||||
it("Calls the expected callbacks", async () => {
|
||||
await import("../entry");
|
||||
|
||||
expect(stopIE).toHaveBeenCalled();
|
||||
expect(shortRevision).toHaveBeenCalled();
|
||||
expect(detectLanguage).toHaveBeenCalled();
|
||||
expect(I.init).toHaveBeenCalled();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,32 @@
|
|||
jest.mock("../util/util", () => ({
|
||||
shortRevision: jest.fn(() => "ABCD"),
|
||||
trim: jest.fn((s: unknown) => s),
|
||||
defensiveClone: jest.fn((s: unknown) => s)
|
||||
}));
|
||||
|
||||
jest.mock("../i18n", () => ({
|
||||
detectLanguage: jest.fn(() => Promise.resolve())
|
||||
}));
|
||||
|
||||
jest.mock("../util/stop_ie", () => ({ stopIE: jest.fn() }));
|
||||
jest.mock("i18next", () => ({ init: jest.fn() }));
|
||||
jest.mock("../routes", () => ({ attachAppToDom: { mock: "Yeah" } }));
|
||||
|
||||
import { stopIE } from "../util/stop_ie";
|
||||
import { shortRevision } from "../util/util";
|
||||
import { detectLanguage } from "../i18n";
|
||||
import I from "i18next";
|
||||
|
||||
describe("entry file", () => {
|
||||
it("Calls the expected callbacks", async () => {
|
||||
console.log = jest.fn();
|
||||
|
||||
await import("../entry");
|
||||
|
||||
expect(stopIE).toHaveBeenCalled();
|
||||
expect(shortRevision).toHaveBeenCalled();
|
||||
expect(detectLanguage).toHaveBeenCalled();
|
||||
expect(I.init).toHaveBeenCalled();
|
||||
expect(console.log).toHaveBeenCalledWith("ABCD");
|
||||
});
|
||||
});
|
|
@ -19,11 +19,15 @@ class Kaboom extends React.Component<{}, {}> {
|
|||
|
||||
describe("<ErrorBoundary/>", () => {
|
||||
it("handles exceptions", () => {
|
||||
console.error = jest.fn();
|
||||
const nodes = <ErrorBoundary><Kaboom /></ErrorBoundary>;
|
||||
const el = mount<ErrorBoundary>(nodes);
|
||||
expect(el.text()).toContain("can't render this part of the page");
|
||||
const i = el.instance();
|
||||
expect(i.state.hasError).toBe(true);
|
||||
expect(catchErrors).toHaveBeenCalled();
|
||||
expect(console.error).toHaveBeenCalledTimes(2);
|
||||
expect(console.error).toHaveBeenCalledWith(expect.any(String), Error("ALWAYS"));
|
||||
expect(console.error).toHaveBeenCalledWith(expect.stringContaining("Kaboom"));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
jest.mock("react-redux", () => ({
|
||||
connect: jest.fn()
|
||||
}));
|
||||
jest.mock("react-redux", () => ({ connect: jest.fn() }));
|
||||
jest.mock("../labs/labs_features", () => ({ LabsFeatures: () => <div /> }));
|
||||
|
||||
import * as React from "react";
|
||||
import { fakeState } from "../../__test_support__/fake_state";
|
||||
|
|
|
@ -30,7 +30,7 @@ const LengthInput = (props: LengthInputProps) =>
|
|||
<Col xs={7}>
|
||||
<input
|
||||
type="number"
|
||||
value={props.value}
|
||||
value={"" + props.value}
|
||||
onChange={e => props.dispatch(setWebAppConfigValue(
|
||||
props.setting, e.currentTarget.value))} />
|
||||
</Col>
|
||||
|
|
|
@ -40,6 +40,7 @@ describe("refresh()", () => {
|
|||
const thunk = refresh(device1);
|
||||
const dispatch = jest.fn();
|
||||
const { mock } = dispatch;
|
||||
console.error = jest.fn();
|
||||
thunk(dispatch);
|
||||
setImmediate(() => {
|
||||
expect(dispatch).toHaveBeenCalledTimes(2);
|
||||
|
@ -56,6 +57,9 @@ describe("refresh()", () => {
|
|||
"payload.err.message",
|
||||
"NO ERR MSG FOUND");
|
||||
expect(dispatchPayl).toEqual("Unable to refresh");
|
||||
expect(console.error).toHaveBeenCalledTimes(1);
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
expect.stringContaining("Device"));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -70,8 +74,12 @@ describe("updateViaAjax()", () => {
|
|||
index: buildResourceIndex([fakePeripheral()]).index
|
||||
};
|
||||
payload.uuid = Object.keys(payload.index.all)[0];
|
||||
console.error = jest.fn();
|
||||
updateViaAjax(payload).catch(e => {
|
||||
expect("" + e).toEqual("Error: Just saved a malformed TR.");
|
||||
expect(console.error).toHaveBeenCalledTimes(1);
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
expect.stringContaining("Peripheral"));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -40,6 +40,7 @@ import { fakeState } from "../../../__test_support__/fake_state";
|
|||
import { talk } from "browser-speech";
|
||||
import { globalQueue } from "../../batch_queue";
|
||||
import { MessageType } from "../../../sequences/interfaces";
|
||||
import { FbjsEventName } from "farmbot/dist/constants";
|
||||
|
||||
const A_STRING = expect.any(String);
|
||||
describe("readStatus()", () => {
|
||||
|
@ -238,10 +239,16 @@ describe("onLogs", () => {
|
|||
});
|
||||
|
||||
describe("onPublicBroadcast", () => {
|
||||
const expectBroadcastLog = () =>
|
||||
expect(console.log).toHaveBeenCalledWith(
|
||||
FbjsEventName.publicBroadcast, expect.any(Object));
|
||||
|
||||
it("triggers when appropriate", () => {
|
||||
location.assign = jest.fn();
|
||||
window.confirm = jest.fn(() => true);
|
||||
console.log = jest.fn();
|
||||
onPublicBroadcast({});
|
||||
expectBroadcastLog();
|
||||
expect(window.confirm).toHaveBeenCalledWith(Content.FORCE_REFRESH_CONFIRM);
|
||||
expect(location.assign).toHaveBeenCalled();
|
||||
});
|
||||
|
@ -249,7 +256,9 @@ describe("onPublicBroadcast", () => {
|
|||
it("allows cancellation of refresh", () => {
|
||||
window.confirm = jest.fn(() => false);
|
||||
window.alert = jest.fn();
|
||||
console.log = jest.fn();
|
||||
onPublicBroadcast({});
|
||||
expectBroadcastLog();
|
||||
expect(window.alert).toHaveBeenCalledWith(Content.FORCE_REFRESH_CANCEL_WARNING);
|
||||
expect(location.assign).not.toHaveBeenCalled();
|
||||
});
|
||||
|
|
|
@ -163,10 +163,8 @@ export const onOnline =
|
|||
export const onReconnect =
|
||||
() => warning(t("Attempting to reconnect to the message broker"), t("Offline"));
|
||||
|
||||
export const BROADCAST_CHANNEL = "public_broadcast";
|
||||
|
||||
export function onPublicBroadcast(payl: unknown) {
|
||||
console.log(BROADCAST_CHANNEL, payl);
|
||||
console.log(FbjsEventName.publicBroadcast, payl);
|
||||
if (confirm(t(Content.FORCE_REFRESH_CONFIRM))) {
|
||||
location.assign(window.location.origin || "/");
|
||||
} else {
|
||||
|
|
|
@ -12,6 +12,7 @@ import {
|
|||
getConnectionColor
|
||||
} from "../diagram";
|
||||
import { Color } from "../../../ui/index";
|
||||
import { svgMount } from "../../../__test_support__/svg_mount";
|
||||
|
||||
describe("<ConnectivityDiagram/>", () => {
|
||||
function fakeProps(): ConnectivityDiagramProps {
|
||||
|
@ -58,14 +59,14 @@ describe("<ConnectivityDiagram/>", () => {
|
|||
}
|
||||
|
||||
it("renders diagram", () => {
|
||||
const wrapper = mount(<ConnectivityDiagram {...fakeProps()} />);
|
||||
const wrapper = svgMount(<ConnectivityDiagram {...fakeProps()} />);
|
||||
expect(wrapper.text())
|
||||
.toContain("BrowserWeb AppMessage BrokerFarmBotRaspberry PiF");
|
||||
});
|
||||
|
||||
it("hover", () => {
|
||||
const p = fakeProps();
|
||||
const wrapper = mount(<ConnectivityDiagram {...p} />);
|
||||
const wrapper = svgMount(<ConnectivityDiagram {...p} />);
|
||||
wrapper.find(".connector-hover-area").first().simulate("mouseEnter");
|
||||
expect(p.hover).toHaveBeenCalledWith("EF");
|
||||
});
|
||||
|
@ -130,7 +131,7 @@ describe("<Connector/>", () => {
|
|||
}
|
||||
|
||||
it("renders", () => {
|
||||
const wrapper = mount(<Connector {...fakeProps()} />);
|
||||
const wrapper = svgMount(<Connector {...fakeProps()} />);
|
||||
const lines = wrapper.find("line");
|
||||
expect(lines.length).toEqual(3);
|
||||
expect(lines.at(0).props())
|
||||
|
@ -154,7 +155,7 @@ describe("<Connector/>", () => {
|
|||
it("renders connected color", () => {
|
||||
const p = fakeProps();
|
||||
p.connectionData.connectionStatus = true;
|
||||
const wrapper = mount(<Connector {...p} />);
|
||||
const wrapper = svgMount(<Connector {...p} />);
|
||||
expect(wrapper.find("line").at(1).props().stroke).toEqual(Color.green);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,25 +1,23 @@
|
|||
import * as React from "react";
|
||||
import { DrawnPoint, DrawnPointProps } from "../drawn_point";
|
||||
import { mount } from "enzyme";
|
||||
import {
|
||||
fakeMapTransformProps
|
||||
} from "../../../../__test_support__/map_transform_props";
|
||||
import { svgMount } from "../../../../__test_support__/svg_mount";
|
||||
|
||||
describe("<DrawnPoint/>", () => {
|
||||
function fakeProps(): DrawnPointProps {
|
||||
return {
|
||||
mapTransformProps: fakeMapTransformProps(),
|
||||
data: {
|
||||
cx: 10,
|
||||
cy: 20,
|
||||
r: 30,
|
||||
color: "red"
|
||||
}
|
||||
};
|
||||
}
|
||||
const fakeProps = (): DrawnPointProps => ({
|
||||
mapTransformProps: fakeMapTransformProps(),
|
||||
data: {
|
||||
cx: 10,
|
||||
cy: 20,
|
||||
r: 30,
|
||||
color: "red"
|
||||
}
|
||||
});
|
||||
|
||||
it("renders point", () => {
|
||||
const wrapper = mount(<DrawnPoint {...fakeProps()} />);
|
||||
const wrapper = svgMount(<DrawnPoint {...fakeProps()} />);
|
||||
expect(wrapper.find("g").props().stroke).toEqual("red");
|
||||
expect(wrapper.find("circle").first().props()).toEqual({
|
||||
id: "point-radius", strokeDasharray: "4 5",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as React from "react";
|
||||
import { shallow, mount } from "enzyme";
|
||||
import { shallow } from "enzyme";
|
||||
import {
|
||||
Bugs, BugsProps, showBugResetButton, showBugs, resetBugs, BugsControls
|
||||
} from "../bugs";
|
||||
|
@ -8,6 +8,7 @@ import { range } from "lodash";
|
|||
import {
|
||||
fakeMapTransformProps
|
||||
} from "../../../../__test_support__/map_transform_props";
|
||||
import { svgMount } from "../../../../__test_support__/svg_mount";
|
||||
|
||||
const expectAlive = (value: string) =>
|
||||
expect(getEggStatus(EggKeys.BUGS_ARE_STILL_ALIVE)).toEqual(value);
|
||||
|
@ -22,7 +23,7 @@ describe("<Bugs />", () => {
|
|||
});
|
||||
|
||||
it("renders", () => {
|
||||
const wrapper = shallow(<Bugs {...fakeProps()} />);
|
||||
const wrapper = svgMount(<Bugs {...fakeProps()} />);
|
||||
expect(wrapper.find("image").length).toEqual(10);
|
||||
const firstBug = wrapper.find("image").first();
|
||||
expect(firstBug.props()).toEqual(expect.objectContaining({
|
||||
|
@ -36,8 +37,8 @@ describe("<Bugs />", () => {
|
|||
it("kills bugs", () => {
|
||||
setEggStatus(EggKeys.BUGS_ARE_STILL_ALIVE, "");
|
||||
expectAlive("");
|
||||
const wrapper = mount<Bugs>(<Bugs {...fakeProps()} />);
|
||||
wrapper.instance().state.bugs[0].r = 101;
|
||||
const wrapper = svgMount(<Bugs {...fakeProps()} />);
|
||||
wrapper.find(Bugs).state().bugs[0].r = 101;
|
||||
range(10).map(b =>
|
||||
wrapper.find("image").at(b).simulate("click"));
|
||||
expectAlive("");
|
||||
|
@ -50,7 +51,7 @@ describe("<Bugs />", () => {
|
|||
className: expect.stringContaining("dead"),
|
||||
filter: expect.stringContaining("grayscale")
|
||||
}));
|
||||
expect(wrapper.instance().state.bugs[0]).toEqual(expect.objectContaining({
|
||||
expect(wrapper.find(Bugs).state().bugs[0]).toEqual(expect.objectContaining({
|
||||
alive: false, hp: 50
|
||||
}));
|
||||
});
|
||||
|
|
|
@ -5,7 +5,6 @@ jest.mock("../../../../../history", () => ({
|
|||
|
||||
import * as React from "react";
|
||||
import { PlantLayer } from "../plant_layer";
|
||||
import { shallow } from "enzyme";
|
||||
import {
|
||||
fakePlant, fakePlantTemplate
|
||||
} from "../../../../../__test_support__/fake_state/resources";
|
||||
|
@ -13,29 +12,28 @@ import { PlantLayerProps, GardenPlantProps } from "../../../interfaces";
|
|||
import {
|
||||
fakeMapTransformProps
|
||||
} from "../../../../../__test_support__/map_transform_props";
|
||||
import { svgMount } from "../../../../../__test_support__/svg_mount";
|
||||
|
||||
describe("<PlantLayer/>", () => {
|
||||
function fakeProps(): PlantLayerProps {
|
||||
return {
|
||||
visible: true,
|
||||
plants: [fakePlant()],
|
||||
mapTransformProps: fakeMapTransformProps(),
|
||||
currentPlant: undefined,
|
||||
dragging: false,
|
||||
editing: false,
|
||||
selectedForDel: undefined,
|
||||
dispatch: jest.fn(),
|
||||
zoomLvl: 1,
|
||||
activeDragXY: { x: undefined, y: undefined, z: undefined },
|
||||
animate: true,
|
||||
};
|
||||
}
|
||||
const fakeProps = (): PlantLayerProps => ({
|
||||
visible: true,
|
||||
plants: [fakePlant()],
|
||||
mapTransformProps: fakeMapTransformProps(),
|
||||
currentPlant: undefined,
|
||||
dragging: false,
|
||||
editing: false,
|
||||
selectedForDel: undefined,
|
||||
dispatch: jest.fn(),
|
||||
zoomLvl: 1,
|
||||
activeDragXY: { x: undefined, y: undefined, z: undefined },
|
||||
animate: true,
|
||||
});
|
||||
|
||||
it("shows plants", () => {
|
||||
const p = fakeProps();
|
||||
const wrapper = shallow(<PlantLayer {...p} />);
|
||||
const wrapper = svgMount(<PlantLayer {...p} />);
|
||||
const layer = wrapper.find("#plant-layer");
|
||||
expect(layer.find(".plant-link-wrapper").length).toEqual(1);
|
||||
expect(layer.find(".plant-link-wrapper").length).toEqual(2);
|
||||
["soil-cloud",
|
||||
"plant-icon",
|
||||
"image visibility=\"visible\"",
|
||||
|
@ -50,21 +48,21 @@ describe("<PlantLayer/>", () => {
|
|||
it("toggles visibility off", () => {
|
||||
const p = fakeProps();
|
||||
p.visible = false;
|
||||
const wrapper = shallow(<PlantLayer {...p} />);
|
||||
expect(wrapper.html()).toEqual("<g id=\"plant-layer\"></g>");
|
||||
const wrapper = svgMount(<PlantLayer {...p} />);
|
||||
expect(wrapper.html()).toEqual("<svg><g id=\"plant-layer\"></g></svg>");
|
||||
});
|
||||
|
||||
it("is in clickable mode", () => {
|
||||
mockPath = "/app/designer/plants";
|
||||
const p = fakeProps();
|
||||
const wrapper = shallow(<PlantLayer {...p} />);
|
||||
const wrapper = svgMount(<PlantLayer {...p} />);
|
||||
expect(wrapper.find("Link").props().style).toEqual({});
|
||||
});
|
||||
|
||||
it("is in non-clickable mode", () => {
|
||||
mockPath = "/app/designer/plants/select";
|
||||
const p = fakeProps();
|
||||
const wrapper = shallow(<PlantLayer {...p} />);
|
||||
const wrapper = svgMount(<PlantLayer {...p} />);
|
||||
expect(wrapper.find("Link").props().style)
|
||||
.toEqual({ pointerEvents: "none" });
|
||||
});
|
||||
|
@ -73,7 +71,7 @@ describe("<PlantLayer/>", () => {
|
|||
mockPath = "/app/designer/plants";
|
||||
const p = fakeProps();
|
||||
p.plants[0].body.id = 5;
|
||||
const wrapper = shallow(<PlantLayer {...p} />);
|
||||
const wrapper = svgMount(<PlantLayer {...p} />);
|
||||
expect(wrapper.find("Link").props().to)
|
||||
.toEqual("/app/designer/plants/5");
|
||||
});
|
||||
|
@ -83,7 +81,7 @@ describe("<PlantLayer/>", () => {
|
|||
const p = fakeProps();
|
||||
p.plants = [fakePlantTemplate()];
|
||||
p.plants[0].body.id = 5;
|
||||
const wrapper = shallow(<PlantLayer {...p} />);
|
||||
const wrapper = svgMount(<PlantLayer {...p} />);
|
||||
expect(wrapper.find("Link").props().to)
|
||||
.toEqual("/app/designer/saved_gardens/templates/5");
|
||||
});
|
||||
|
@ -94,7 +92,7 @@ describe("<PlantLayer/>", () => {
|
|||
const plant = fakePlant();
|
||||
p.plants = [plant];
|
||||
p.currentPlant = plant;
|
||||
const wrapper = shallow(<PlantLayer {...p} />);
|
||||
const wrapper = svgMount(<PlantLayer {...p} />);
|
||||
expect(wrapper.find("GardenPlant").props().selected).toEqual(true);
|
||||
});
|
||||
|
||||
|
@ -104,7 +102,7 @@ describe("<PlantLayer/>", () => {
|
|||
const plant = fakePlant();
|
||||
p.plants = [plant];
|
||||
p.selectedForDel = [plant.uuid];
|
||||
const wrapper = shallow(<PlantLayer {...p} />);
|
||||
const wrapper = svgMount(<PlantLayer {...p} />);
|
||||
expect((wrapper.find("GardenPlant").props() as GardenPlantProps).grayscale)
|
||||
.toEqual(true);
|
||||
});
|
||||
|
@ -114,7 +112,7 @@ describe("<PlantLayer/>", () => {
|
|||
const plant = fakePlant();
|
||||
plant.body.id = 1;
|
||||
p.plants = [plant];
|
||||
const wrapper = shallow(<PlantLayer {...p} />);
|
||||
const wrapper = svgMount(<PlantLayer {...p} />);
|
||||
expect((wrapper.find("Link").props()).style).toEqual({});
|
||||
});
|
||||
|
||||
|
@ -123,7 +121,7 @@ describe("<PlantLayer/>", () => {
|
|||
const plant = fakePlant();
|
||||
plant.body.id = 0;
|
||||
p.plants = [plant];
|
||||
const wrapper = shallow(<PlantLayer {...p} />);
|
||||
const wrapper = svgMount(<PlantLayer {...p} />);
|
||||
expect((wrapper.find("Link").props()).style)
|
||||
.toEqual({ pointerEvents: "none" });
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as React from "react";
|
||||
import { mount, shallow } from "enzyme";
|
||||
import { shallow } from "enzyme";
|
||||
import {
|
||||
GardenSensorReading, GardenSensorReadingProps
|
||||
} from "../garden_sensor_reading";
|
||||
|
@ -12,6 +12,7 @@ import {
|
|||
import {
|
||||
fakeTimeSettings
|
||||
} from "../../../../../__test_support__/fake_time_settings";
|
||||
import { svgMount } from "../../../../../__test_support__/svg_mount";
|
||||
|
||||
describe("<GardenSensorReading />", () => {
|
||||
const fakeProps = (): GardenSensorReadingProps => ({
|
||||
|
@ -23,7 +24,7 @@ describe("<GardenSensorReading />", () => {
|
|||
});
|
||||
|
||||
it("renders", () => {
|
||||
const wrapper = mount(<GardenSensorReading {...fakeProps()} />);
|
||||
const wrapper = svgMount(<GardenSensorReading {...fakeProps()} />);
|
||||
expect(wrapper.html()).toContain("sensor-reading-");
|
||||
expect(wrapper.find("circle").length).toEqual(2);
|
||||
});
|
||||
|
@ -31,21 +32,21 @@ describe("<GardenSensorReading />", () => {
|
|||
it("doesn't render", () => {
|
||||
const p = fakeProps();
|
||||
p.sensorReading.body.x = undefined;
|
||||
const wrapper = mount(<GardenSensorReading {...p} />);
|
||||
const wrapper = svgMount(<GardenSensorReading {...p} />);
|
||||
expect(wrapper.find("circle").length).toEqual(0);
|
||||
});
|
||||
|
||||
it("renders sensor name", () => {
|
||||
const p = fakeProps();
|
||||
p.sensorLookup = { 1: "Sensor Name" };
|
||||
const wrapper = mount(<GardenSensorReading {...p} />);
|
||||
const wrapper = svgMount(<GardenSensorReading {...p} />);
|
||||
expect(wrapper.text()).toContain("Sensor Name (pin 1)");
|
||||
});
|
||||
|
||||
it("renders analog reading", () => {
|
||||
const p = fakeProps();
|
||||
p.sensorReading.body.mode = 1;
|
||||
const wrapper = mount(<GardenSensorReading {...p} />);
|
||||
const wrapper = svgMount(<GardenSensorReading {...p} />);
|
||||
expect(wrapper.text()).toContain("value 0 (analog)");
|
||||
});
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import * as React from "react";
|
||||
import { mount } from "enzyme";
|
||||
import {
|
||||
SensorReadingsLayer, SensorReadingsLayerProps
|
||||
} from "../sensor_readings_layer";
|
||||
|
@ -12,6 +11,7 @@ import {
|
|||
import {
|
||||
fakeTimeSettings
|
||||
} from "../../../../../__test_support__/fake_time_settings";
|
||||
import { svgMount } from "../../../../../__test_support__/svg_mount";
|
||||
|
||||
describe("<SensorReadingsLayer />", () => {
|
||||
const fakeProps = (): SensorReadingsLayerProps => ({
|
||||
|
@ -23,7 +23,7 @@ describe("<SensorReadingsLayer />", () => {
|
|||
});
|
||||
|
||||
it("renders", () => {
|
||||
const wrapper = mount(<SensorReadingsLayer {...fakeProps()} />);
|
||||
const wrapper = svgMount(<SensorReadingsLayer {...fakeProps()} />);
|
||||
expect(wrapper.html()).toContain("sensor-readings-layer");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,22 +1,20 @@
|
|||
import * as React from "react";
|
||||
import { mount } from "enzyme";
|
||||
import {
|
||||
ToolbaySlot, Tool, ToolProps, ToolGraphicProps, ToolSlotGraphicProps
|
||||
} from "../tool_graphics";
|
||||
import { BotOriginQuadrant } from "../../../../interfaces";
|
||||
import { Color } from "../../../../../ui";
|
||||
import { svgMount } from "../../../../../__test_support__/svg_mount";
|
||||
|
||||
describe("<ToolbaySlot />", () => {
|
||||
const fakeProps = (): ToolSlotGraphicProps => {
|
||||
return {
|
||||
id: undefined,
|
||||
x: 10,
|
||||
y: 20,
|
||||
pulloutDirection: 0,
|
||||
quadrant: 2,
|
||||
xySwap: false,
|
||||
};
|
||||
};
|
||||
const fakeProps = (): ToolSlotGraphicProps => ({
|
||||
id: undefined,
|
||||
x: 10,
|
||||
y: 20,
|
||||
pulloutDirection: 0,
|
||||
quadrant: 2,
|
||||
xySwap: false,
|
||||
});
|
||||
|
||||
const checkSlotDirection =
|
||||
(direction: number,
|
||||
|
@ -29,7 +27,7 @@ describe("<ToolbaySlot />", () => {
|
|||
p.pulloutDirection = direction;
|
||||
p.quadrant = quadrant;
|
||||
p.xySwap = xySwap;
|
||||
const wrapper = mount(<ToolbaySlot {...p} />);
|
||||
const wrapper = svgMount(<ToolbaySlot {...p} />);
|
||||
expect(wrapper.find("use").props().transform).toEqual(expected);
|
||||
});
|
||||
};
|
||||
|
@ -59,27 +57,23 @@ describe("<ToolbaySlot />", () => {
|
|||
});
|
||||
|
||||
describe("<Tool/>", () => {
|
||||
const fakeToolProps = (): ToolGraphicProps => {
|
||||
return {
|
||||
x: 10,
|
||||
y: 20,
|
||||
hovered: false,
|
||||
setHoverState: jest.fn(),
|
||||
xySwap: false,
|
||||
};
|
||||
};
|
||||
const fakeToolProps = (): ToolGraphicProps => ({
|
||||
x: 10,
|
||||
y: 20,
|
||||
hovered: false,
|
||||
setHoverState: jest.fn(),
|
||||
xySwap: false,
|
||||
});
|
||||
|
||||
const fakeProps = (): ToolProps => {
|
||||
return {
|
||||
tool: "fake tool",
|
||||
toolProps: fakeToolProps()
|
||||
};
|
||||
};
|
||||
const fakeProps = (): ToolProps => ({
|
||||
tool: "fake tool",
|
||||
toolProps: fakeToolProps()
|
||||
});
|
||||
|
||||
const testHoverActions = (toolName: string) => {
|
||||
const p = fakeProps();
|
||||
p.tool = toolName;
|
||||
const wrapper = mount(<Tool {...p} />);
|
||||
const wrapper = svgMount(<Tool {...p} />);
|
||||
wrapper.find("g").simulate("mouseOver");
|
||||
expect(p.toolProps.setHoverState).toHaveBeenCalledWith(true);
|
||||
wrapper.find("g").simulate("mouseLeave");
|
||||
|
@ -87,7 +81,7 @@ describe("<Tool/>", () => {
|
|||
};
|
||||
|
||||
it("renders standard tool styling", () => {
|
||||
const wrapper = mount(<Tool {...fakeProps()} />);
|
||||
const wrapper = svgMount(<Tool {...fakeProps()} />);
|
||||
const props = wrapper.find("circle").last().props();
|
||||
expect(props.r).toEqual(35);
|
||||
expect(props.cx).toEqual(10);
|
||||
|
@ -98,7 +92,7 @@ describe("<Tool/>", () => {
|
|||
it("renders tool hover styling", () => {
|
||||
const p = fakeProps();
|
||||
p.toolProps.hovered = true;
|
||||
const wrapper = mount(<Tool {...p} />);
|
||||
const wrapper = svgMount(<Tool {...p} />);
|
||||
const props = wrapper.find("circle").last().props();
|
||||
expect(props.fill).toEqual(Color.darkGray);
|
||||
});
|
||||
|
@ -110,7 +104,7 @@ describe("<Tool/>", () => {
|
|||
it("renders special tool styling: bin", () => {
|
||||
const p = fakeProps();
|
||||
p.tool = "seedBin";
|
||||
const wrapper = mount(<Tool {...p} />);
|
||||
const wrapper = svgMount(<Tool {...p} />);
|
||||
const elements = wrapper.find("#seed-bin").find("circle");
|
||||
expect(elements.length).toEqual(2);
|
||||
expect(elements.last().props().fill).toEqual("url(#SeedBinGradient)");
|
||||
|
@ -120,7 +114,7 @@ describe("<Tool/>", () => {
|
|||
const p = fakeProps();
|
||||
p.tool = "seedBin";
|
||||
p.toolProps.hovered = true;
|
||||
const wrapper = mount(<Tool {...p} />);
|
||||
const wrapper = svgMount(<Tool {...p} />);
|
||||
p.toolProps.hovered = true;
|
||||
expect(wrapper.find("#seed-bin").find("circle").length).toEqual(3);
|
||||
});
|
||||
|
@ -132,7 +126,7 @@ describe("<Tool/>", () => {
|
|||
it("renders special tool styling: tray", () => {
|
||||
const p = fakeProps();
|
||||
p.tool = "seedTray";
|
||||
const wrapper = mount(<Tool {...p} />);
|
||||
const wrapper = svgMount(<Tool {...p} />);
|
||||
const elements = wrapper.find("#seed-tray");
|
||||
expect(elements.find("circle").length).toEqual(2);
|
||||
expect(elements.find("rect").length).toEqual(1);
|
||||
|
@ -143,7 +137,7 @@ describe("<Tool/>", () => {
|
|||
const p = fakeProps();
|
||||
p.tool = "seedTray";
|
||||
p.toolProps.hovered = true;
|
||||
const wrapper = mount(<Tool {...p} />);
|
||||
const wrapper = svgMount(<Tool {...p} />);
|
||||
p.toolProps.hovered = true;
|
||||
expect(wrapper.find("#seed-tray").find("circle").length).toEqual(3);
|
||||
});
|
||||
|
@ -155,7 +149,7 @@ describe("<Tool/>", () => {
|
|||
it("renders special tool styling: trough", () => {
|
||||
const p = fakeProps();
|
||||
p.tool = "seedTrough";
|
||||
const wrapper = mount(<Tool {...p} />);
|
||||
const wrapper = svgMount(<Tool {...p} />);
|
||||
const elements = wrapper.find("#seed-trough");
|
||||
expect(elements.find("circle").length).toEqual(0);
|
||||
expect(elements.find("rect").length).toEqual(1);
|
||||
|
@ -165,7 +159,7 @@ describe("<Tool/>", () => {
|
|||
const p = fakeProps();
|
||||
p.tool = "seedTrough";
|
||||
p.toolProps.hovered = true;
|
||||
const wrapper = mount(<Tool {...p} />);
|
||||
const wrapper = svgMount(<Tool {...p} />);
|
||||
p.toolProps.hovered = true;
|
||||
expect(wrapper.find("#seed-trough").find("circle").length).toEqual(0);
|
||||
expect(wrapper.find("#seed-trough").find("rect").length).toEqual(1);
|
||||
|
|
|
@ -1,21 +1,19 @@
|
|||
import * as React from "react";
|
||||
import { ToolSlotPoint, TSPProps } from "../tool_slot_point";
|
||||
import { mount } from "enzyme";
|
||||
import {
|
||||
fakeToolSlot, fakeTool
|
||||
} from "../../../../../__test_support__/fake_state/resources";
|
||||
import {
|
||||
fakeMapTransformProps
|
||||
} from "../../../../../__test_support__/map_transform_props";
|
||||
import { svgMount } from "../../../../../__test_support__/svg_mount";
|
||||
|
||||
describe("<ToolSlotPoint/>", () => {
|
||||
function fakeProps(): TSPProps {
|
||||
return {
|
||||
mapTransformProps: fakeMapTransformProps(),
|
||||
botPositionX: undefined,
|
||||
slot: { toolSlot: fakeToolSlot(), tool: fakeTool() }
|
||||
};
|
||||
}
|
||||
const fakeProps = (): TSPProps => ({
|
||||
mapTransformProps: fakeMapTransformProps(),
|
||||
botPositionX: undefined,
|
||||
slot: { toolSlot: fakeToolSlot(), tool: fakeTool() }
|
||||
});
|
||||
|
||||
const testToolSlotGraphics = (tool: 0 | 1, slot: 0 | 1) => {
|
||||
it(`renders ${tool ? "" : "no"} tool and ${slot ? "" : "no"} slot`, () => {
|
||||
|
@ -23,7 +21,7 @@ describe("<ToolSlotPoint/>", () => {
|
|||
const p = fakeProps();
|
||||
if (!tool) { p.slot.tool = undefined; }
|
||||
p.slot.toolSlot.body.pullout_direction = slot;
|
||||
const wrapper = mount(<ToolSlotPoint {...p} />);
|
||||
const wrapper = svgMount(<ToolSlotPoint {...p} />);
|
||||
expect(wrapper.find("circle").length).toEqual(tool);
|
||||
expect(wrapper.find("use").length).toEqual(slot);
|
||||
});
|
||||
|
@ -36,8 +34,8 @@ describe("<ToolSlotPoint/>", () => {
|
|||
it("displays tool name", () => {
|
||||
const p = fakeProps();
|
||||
p.slot.toolSlot.body.pullout_direction = 2;
|
||||
const wrapper = mount(<ToolSlotPoint {...p} />);
|
||||
wrapper.setState({ hovered: true });
|
||||
const wrapper = svgMount(<ToolSlotPoint {...p} />);
|
||||
wrapper.find(ToolSlotPoint).setState({ hovered: true });
|
||||
expect(wrapper.find("text").props().visibility).toEqual("visible");
|
||||
expect(wrapper.find("text").text()).toEqual("Foo");
|
||||
expect(wrapper.find("text").props().dx).toEqual(-40);
|
||||
|
@ -46,28 +44,28 @@ describe("<ToolSlotPoint/>", () => {
|
|||
it("displays 'no tool'", () => {
|
||||
const p = fakeProps();
|
||||
p.slot.tool = undefined;
|
||||
const wrapper = mount(<ToolSlotPoint {...p} />);
|
||||
wrapper.setState({ hovered: true });
|
||||
const wrapper = svgMount(<ToolSlotPoint {...p} />);
|
||||
wrapper.find(ToolSlotPoint).setState({ hovered: true });
|
||||
expect(wrapper.find("text").text()).toEqual("no tool");
|
||||
expect(wrapper.find("text").props().dx).toEqual(40);
|
||||
});
|
||||
|
||||
it("doesn't display tool name", () => {
|
||||
const wrapper = mount(<ToolSlotPoint {...fakeProps()} />);
|
||||
const wrapper = svgMount(<ToolSlotPoint {...fakeProps()} />);
|
||||
expect(wrapper.find("text").props().visibility).toEqual("hidden");
|
||||
});
|
||||
|
||||
it("renders bin", () => {
|
||||
const p = fakeProps();
|
||||
if (p.slot.tool) { p.slot.tool.body.name = "seed bin"; }
|
||||
const wrapper = mount(<ToolSlotPoint {...p} />);
|
||||
const wrapper = svgMount(<ToolSlotPoint {...p} />);
|
||||
expect(wrapper.find("#SeedBinGradient").length).toEqual(1);
|
||||
});
|
||||
|
||||
it("renders tray", () => {
|
||||
const p = fakeProps();
|
||||
if (p.slot.tool) { p.slot.tool.body.name = "seed tray"; }
|
||||
const wrapper = mount(<ToolSlotPoint {...p} />);
|
||||
const wrapper = svgMount(<ToolSlotPoint {...p} />);
|
||||
expect(wrapper.find("#SeedTrayPattern").length).toEqual(1);
|
||||
});
|
||||
|
||||
|
@ -75,14 +73,14 @@ describe("<ToolSlotPoint/>", () => {
|
|||
const p = fakeProps();
|
||||
p.slot.toolSlot.body.gantry_mounted = true;
|
||||
if (p.slot.tool) { p.slot.tool.body.name = "seed trough"; }
|
||||
const wrapper = mount(<ToolSlotPoint {...p} />);
|
||||
const wrapper = svgMount(<ToolSlotPoint {...p} />);
|
||||
expect(wrapper.find("#seed-trough").length).toEqual(1);
|
||||
});
|
||||
|
||||
it("sets hover", () => {
|
||||
const wrapper = mount<ToolSlotPoint>(<ToolSlotPoint {...fakeProps()} />);
|
||||
expect(wrapper.state().hovered).toBeFalsy();
|
||||
wrapper.instance().setHover(true);
|
||||
expect(wrapper.state().hovered).toBeTruthy();
|
||||
const wrapper = svgMount(<ToolSlotPoint {...fakeProps()} />);
|
||||
expect(wrapper.find(ToolSlotPoint).state().hovered).toBeFalsy();
|
||||
(wrapper.find(ToolSlotPoint).instance() as ToolSlotPoint).setHover(true);
|
||||
expect(wrapper.find(ToolSlotPoint).state().hovered).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -22,6 +22,7 @@ describe("<RunTour />", () => {
|
|||
});
|
||||
|
||||
describe("<Tour />", () => {
|
||||
console.log = jest.fn();
|
||||
const fakeCallbackData = (data: Partial<CallBackProps>): CallBackProps => ({
|
||||
action: data.action || "start",
|
||||
index: data.index || 0,
|
||||
|
|
|
@ -10,28 +10,28 @@ const FIRMWARE_MISSING_ALERT: Alert = {
|
|||
created_at: 123,
|
||||
problem_tag: "farmbot_os.firmware.missing",
|
||||
priority: 100,
|
||||
slug: "slug",
|
||||
slug: "slug1",
|
||||
};
|
||||
|
||||
const SEED_DATA_MISSING_ALERT: Alert = {
|
||||
created_at: 123,
|
||||
problem_tag: "api.seed_data.missing",
|
||||
priority: 300,
|
||||
slug: "slug",
|
||||
slug: "slug3",
|
||||
};
|
||||
|
||||
const UNKNOWN_ALERT: Alert = {
|
||||
created_at: 123,
|
||||
problem_tag: "farmbot_os.firmware.alert",
|
||||
priority: 200,
|
||||
slug: "slug",
|
||||
slug: "slug2",
|
||||
};
|
||||
|
||||
const UNKNOWN_ALERT_2: Alert = {
|
||||
created_at: 456,
|
||||
problem_tag: "farmbot_os.firmware.alert",
|
||||
priority: 100,
|
||||
slug: "slug",
|
||||
slug: "slug4",
|
||||
};
|
||||
|
||||
describe("<Alerts />", () => {
|
||||
|
@ -85,8 +85,8 @@ describe("<FirmwareAlerts />", () => {
|
|||
it("renders alerts", () => {
|
||||
const p = fakeProps();
|
||||
p.bot.hardware.alerts = {
|
||||
"slug1": FIRMWARE_MISSING_ALERT,
|
||||
"slug2": UNKNOWN_ALERT
|
||||
[FIRMWARE_MISSING_ALERT.slug]: FIRMWARE_MISSING_ALERT,
|
||||
[UNKNOWN_ALERT.slug]: UNKNOWN_ALERT
|
||||
};
|
||||
const wrapper = mount(<FirmwareAlerts {...p} />);
|
||||
expect(wrapper.text()).toContain("1");
|
||||
|
|
|
@ -31,6 +31,8 @@ describe("getArrayStatus()", () => {
|
|||
|
||||
describe("sanityCheck", () => {
|
||||
it("crashes on malformed TaggedResources", () => {
|
||||
console.error = jest.fn();
|
||||
expect(() => sanityCheck({})).toThrow("Bad kind, uuid, or body: {}");
|
||||
expect(console.error).toHaveBeenCalledWith("{}");
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue