add mapTransformProps to test support

pull/788/head
gabrielburnworth 2018-04-12 20:36:16 -07:00
parent d2dcf660a7
commit 9cf19193bd
32 changed files with 169 additions and 173 deletions

View File

@ -0,0 +1,9 @@
import { MapTransformProps } from "../farm_designer/map/interfaces";
export const fakeMapTransformProps = (): MapTransformProps => {
return {
quadrant: 2,
gridSize: { x: 3000, y: 1500 },
xySwap: false,
};
};

View File

@ -319,7 +319,7 @@ fieldset {
}
}
.webcam-stream-unavailable text {
.webcam-stream-unavailable p {
width: 100%;
position: absolute;
top: 50%;

View File

@ -3,6 +3,7 @@ import { BotExtents } from "../bot_extents";
import { shallow } from "enzyme";
import { bot } from "../../../__test_support__/fake_state/bot";
import { BotExtentsProps } from "../interfaces";
import { fakeMapTransformProps } from "../../../__test_support__/map_transform_props";
describe("<VirtualFarmBot/>", () => {
function fakeProps(): BotExtentsProps {
@ -10,9 +11,7 @@ describe("<VirtualFarmBot/>", () => {
mcuParams.movement_stop_at_home_x = 1;
mcuParams.movement_stop_at_home_y = 1;
return {
mapTransformProps: {
quadrant: 2, gridSize: { x: 3000, y: 1500 }
},
mapTransformProps: fakeMapTransformProps(),
stopAtHome: { x: true, y: true },
botSize: {
x: { value: 3000, isDefault: true },
@ -23,7 +22,7 @@ describe("<VirtualFarmBot/>", () => {
it("renders home lines", () => {
const p = fakeProps();
const wrapper = shallow(<BotExtents {...p } />);
const wrapper = shallow(<BotExtents {...p} />);
const homeLines = wrapper.find("#home-lines").find("line");
expect(homeLines.at(0).props()).toEqual({ "x1": 2, "x2": 2, "y1": 2, "y2": 1500 });
expect(homeLines.at(1).props()).toEqual({ "x1": 2, "x2": 3000, "y1": 2, "y2": 2 });
@ -38,7 +37,7 @@ describe("<VirtualFarmBot/>", () => {
x: { value: 100, isDefault: false },
y: { value: 100, isDefault: false }
};
const wrapper = shallow(<BotExtents {...p } />);
const wrapper = shallow(<BotExtents {...p} />);
const homeLines = wrapper.find("#home-lines").find("line");
expect(homeLines.at(0).props()).toEqual({ "x1": 2, "x2": 2, "y1": 2, "y2": 100 });
expect(homeLines.at(1).props()).toEqual({ "x1": 2, "x2": 100, "y1": 2, "y2": 2 });
@ -54,7 +53,7 @@ describe("<VirtualFarmBot/>", () => {
x: { value: 3000, isDefault: true },
y: { value: 100, isDefault: false }
};
const wrapper = shallow(<BotExtents {...p } />);
const wrapper = shallow(<BotExtents {...p} />);
const homeLines = wrapper.find("#home-lines").find("line");
expect(homeLines.at(0).props()).toEqual({ "x1": 2, "x2": 3000, "y1": 2, "y2": 2 });
expect(homeLines.at(1).html()).toBeFalsy();
@ -71,7 +70,7 @@ describe("<VirtualFarmBot/>", () => {
x: { value: 100, isDefault: false },
y: { value: 100, isDefault: false }
};
const wrapper = shallow(<BotExtents {...p } />);
const wrapper = shallow(<BotExtents {...p} />);
const homeLines = wrapper.find("#home-lines").find("line");
expect(homeLines.at(0).html()).toBeFalsy();
expect(homeLines.at(1).html()).toBeFalsy();
@ -87,7 +86,7 @@ describe("<VirtualFarmBot/>", () => {
x: { value: 100, isDefault: false },
y: { value: 100, isDefault: false }
};
const wrapper = shallow(<BotExtents {...p } />);
const wrapper = shallow(<BotExtents {...p} />);
const homeLines = wrapper.find("#home-lines").find("line");
expect(homeLines.at(0).props()).toEqual({ "x1": 2998, "x2": 2998, "y1": 2, "y2": 100 });
expect(homeLines.at(1).props()).toEqual({ "x1": 2998, "x2": 2900, "y1": 2, "y2": 2 });
@ -100,7 +99,7 @@ describe("<VirtualFarmBot/>", () => {
const p = fakeProps();
p.stopAtHome.x = false;
p.stopAtHome.y = false;
const wrapper = shallow(<BotExtents {...p } />);
const wrapper = shallow(<BotExtents {...p} />);
const homeLines = wrapper.find("#home-lines").find("line");
expect(homeLines.at(0).html()).toBeFalsy();
expect(homeLines.at(1).html()).toBeFalsy();

View File

@ -4,13 +4,12 @@ import { shallow } from "enzyme";
import { DragHelpersProps } from "../interfaces";
import { fakePlant } from "../../../__test_support__/fake_state/resources";
import { Color } from "../../../ui/index";
import { fakeMapTransformProps } from "../../../__test_support__/map_transform_props";
describe("<DragHelpers/>", () => {
function fakeProps(): DragHelpersProps {
return {
mapTransformProps: {
quadrant: 2, gridSize: { x: 3000, y: 1500 }
},
mapTransformProps: fakeMapTransformProps(),
plant: fakePlant(),
dragging: false,
zoomLvl: 1.8,
@ -20,7 +19,7 @@ describe("<DragHelpers/>", () => {
}
it("doesn't render drag helpers", () => {
const wrapper = shallow(<DragHelpers {...fakeProps() } />);
const wrapper = shallow(<DragHelpers {...fakeProps()} />);
expect(wrapper.find("text").length).toEqual(0);
expect(wrapper.find("rect").length).toBeLessThanOrEqual(1);
expect(wrapper.find("use").length).toEqual(0);
@ -29,7 +28,7 @@ describe("<DragHelpers/>", () => {
it("renders drag helpers", () => {
const p = fakeProps();
p.dragging = true;
const wrapper = shallow(<DragHelpers {...p } />);
const wrapper = shallow(<DragHelpers {...p} />);
expect(wrapper.find("#coordinates-tooltip").length).toEqual(1);
expect(wrapper.find("#long-crosshair").length).toEqual(1);
expect(wrapper.find("#short-crosshair").length).toEqual(1);
@ -42,7 +41,7 @@ describe("<DragHelpers/>", () => {
p.dragging = true;
p.plant.body.x = 104;
p.plant.body.y = 199;
const wrapper = shallow(<DragHelpers {...p } />);
const wrapper = shallow(<DragHelpers {...p} />);
expect(wrapper.find("text").length).toEqual(1);
expect(wrapper.find("text").text()).toEqual("100, 200");
expect(wrapper.find("text").props().fontSize).toEqual("1.25rem");
@ -53,7 +52,7 @@ describe("<DragHelpers/>", () => {
const p = fakeProps();
p.dragging = true;
p.zoomLvl = 0.9;
const wrapper = shallow(<DragHelpers {...p } />);
const wrapper = shallow(<DragHelpers {...p} />);
expect(wrapper.find("text").length).toEqual(1);
expect(wrapper.find("text").text()).toEqual("100, 200");
expect(wrapper.find("text").props().fontSize).toEqual("3rem");
@ -64,7 +63,7 @@ describe("<DragHelpers/>", () => {
const p = fakeProps();
p.dragging = true;
p.plant.body.id = 5;
const wrapper = shallow(<DragHelpers {...p } />);
const wrapper = shallow(<DragHelpers {...p} />);
const crosshair = wrapper.find("#short-crosshair");
expect(crosshair.length).toEqual(1);
const segment = crosshair.find("#crosshair-segment-5");
@ -83,7 +82,7 @@ describe("<DragHelpers/>", () => {
const p = fakeProps();
p.dragging = true;
p.zoomLvl = 0.9;
const wrapper = shallow(<DragHelpers {...p } />);
const wrapper = shallow(<DragHelpers {...p} />);
const crosshair = wrapper.find("#short-crosshair");
expect(crosshair.length).toEqual(1);
expect(crosshair.find("rect").first().props())
@ -98,7 +97,7 @@ describe("<DragHelpers/>", () => {
p.plant.body.x = 100;
p.plant.body.y = 100;
p.activeDragXY = { x: 100, y: 0, z: 0 };
const wrapper = shallow(<DragHelpers {...p } />);
const wrapper = shallow(<DragHelpers {...p} />);
const indicators = wrapper.find("#alignment-indicator");
expect(indicators.length).toEqual(1);
const segment = indicators.find("#alignment-indicator-segment-5");
@ -119,7 +118,7 @@ describe("<DragHelpers/>", () => {
p.plant.body.x = 100;
p.plant.body.y = 100;
p.activeDragXY = { x: 0, y: 100, z: 0 };
const wrapper = shallow(<DragHelpers {...p } />);
const wrapper = shallow(<DragHelpers {...p} />);
const indicator = wrapper.find("#alignment-indicator");
const segments = indicator.find("use");
expect(segments.length).toEqual(2);
@ -136,7 +135,7 @@ describe("<DragHelpers/>", () => {
p.plant.body.x = 100;
p.plant.body.y = 100;
p.activeDragXY = { x: 100, y: 100, z: 0 };
const wrapper = shallow(<DragHelpers {...p } />);
const wrapper = shallow(<DragHelpers {...p} />);
const indicator = wrapper.find("#alignment-indicator");
const masterSegment = indicator.find("#alignment-indicator-segment-6");
const segmentProps = masterSegment.find("rect").props();

View File

@ -1,13 +1,12 @@
import * as React from "react";
import { DrawnPoint, DrawnPointProps } from "../drawn_point";
import { mount } from "enzyme";
import { fakeMapTransformProps } from "../../../__test_support__/map_transform_props";
describe("<DrawnPoint/>", () => {
function fakeProps(): DrawnPointProps {
return {
mapTransformProps: {
quadrant: 2, gridSize: { x: 3000, y: 1500 }
},
mapTransformProps: fakeMapTransformProps(),
data: {
cx: 10,
cy: 20,
@ -18,7 +17,7 @@ describe("<DrawnPoint/>", () => {
}
it("renders point", () => {
const wrapper = mount(<DrawnPoint {...fakeProps() } />);
const wrapper = mount(<DrawnPoint {...fakeProps()} />);
expect(wrapper.find("g").props().stroke).toEqual("red");
expect(wrapper.find("circle").first().props()).toEqual({
id: "point-radius", strokeDasharray: "4 5",

View File

@ -19,13 +19,12 @@ import { GardenPlantProps } from "../interfaces";
import { fakePlant } from "../../../__test_support__/fake_state/resources";
import { BooleanSetting } from "../../../session_keys";
import { Actions } from "../../../constants";
import { fakeMapTransformProps } from "../../../__test_support__/map_transform_props";
describe("<GardenPlant/>", () => {
function fakeProps(): GardenPlantProps {
return {
mapTransformProps: {
quadrant: 2, gridSize: { x: 3000, y: 1500 }
},
mapTransformProps: fakeMapTransformProps(),
plant: fakePlant(),
selected: false,
grayscale: false,
@ -39,7 +38,7 @@ describe("<GardenPlant/>", () => {
it("renders plant", () => {
mockStorj[BooleanSetting.disable_animations] = true;
const wrapper = shallow(<GardenPlant {...fakeProps() } />);
const wrapper = shallow(<GardenPlant {...fakeProps()} />);
expect(wrapper.find("image").length).toEqual(1);
expect(wrapper.find("image").props().opacity).toEqual(1);
expect(wrapper.find("text").length).toEqual(0);
@ -50,14 +49,14 @@ describe("<GardenPlant/>", () => {
it("renders plant animations", () => {
mockStorj[BooleanSetting.disable_animations] = false;
const wrapper = shallow(<GardenPlant {...fakeProps() } />);
const wrapper = shallow(<GardenPlant {...fakeProps()} />);
expect(wrapper.find(".soil-cloud").length).toEqual(1);
expect(wrapper.find(".animate").length).toEqual(1);
});
it("Calls the onClick callback", () => {
const p = fakeProps();
const wrapper = shallow(<GardenPlant {...p } />);
const wrapper = shallow(<GardenPlant {...p} />);
wrapper.find("image").at(0).simulate("click");
expect(p.dispatch).toHaveBeenCalledWith({
type: Actions.SELECT_PLANT,
@ -67,7 +66,7 @@ describe("<GardenPlant/>", () => {
it("begins hover", () => {
const p = fakeProps();
const wrapper = shallow(<GardenPlant {...p } />);
const wrapper = shallow(<GardenPlant {...p} />);
wrapper.find("image").at(0).simulate("mouseEnter");
expect(p.dispatch).toHaveBeenCalledWith({
type: Actions.HOVER_PLANT_LIST_ITEM,
@ -77,7 +76,7 @@ describe("<GardenPlant/>", () => {
it("ends hover", () => {
const p = fakeProps();
const wrapper = shallow(<GardenPlant {...p } />);
const wrapper = shallow(<GardenPlant {...p} />);
wrapper.find("image").at(0).simulate("mouseLeave");
expect(p.dispatch).toHaveBeenCalledWith({
type: Actions.HOVER_PLANT_LIST_ITEM,
@ -87,14 +86,14 @@ describe("<GardenPlant/>", () => {
it("has color", () => {
const p = fakeProps();
const wrapper = shallow(<GardenPlant {...p } />);
const wrapper = shallow(<GardenPlant {...p} />);
expect(wrapper.find("image").props().filter).toEqual("");
});
it("has no color", () => {
const p = fakeProps();
p.grayscale = true;
const wrapper = shallow(<GardenPlant {...p } />);
const wrapper = shallow(<GardenPlant {...p} />);
expect(wrapper.find("image").props().filter).toEqual("url(#grayscale)");
});
});

View File

@ -3,19 +3,18 @@ import { GardenPoint } from "../garden_point";
import { shallow } from "enzyme";
import { GardenPointProps } from "../interfaces";
import { fakePoint } from "../../../__test_support__/fake_state/resources";
import { fakeMapTransformProps } from "../../../__test_support__/map_transform_props";
describe("<GardenPoint/>", () => {
function fakeProps(): GardenPointProps {
return {
mapTransformProps: {
quadrant: 2, gridSize: { x: 3000, y: 1500 }
},
mapTransformProps: fakeMapTransformProps(),
point: fakePoint()
};
}
it("renders point", () => {
const wrapper = shallow(<GardenPoint {...fakeProps() } />);
const wrapper = shallow(<GardenPoint {...fakeProps()} />);
expect(wrapper.find("#point-radius").props().r).toEqual(100);
expect(wrapper.find("#point-center").props().r).toEqual(2);
});

View File

@ -2,6 +2,7 @@ import * as React from "react";
import { Grid } from "../grid";
import { shallow } from "enzyme";
import { GridProps } from "../interfaces";
import { fakeMapTransformProps } from "../../../__test_support__/map_transform_props";
describe("<Grid/>", () => {
beforeEach(function () {
@ -10,16 +11,14 @@ describe("<Grid/>", () => {
function fakeProps(): GridProps {
return {
mapTransformProps: {
quadrant: 2, gridSize: { x: 3000, y: 1500 }
},
mapTransformProps: fakeMapTransformProps(),
dispatch: jest.fn(),
onClick: jest.fn()
};
}
it("renders grid", () => {
const wrapper = shallow(<Grid {...fakeProps() } />);
const wrapper = shallow(<Grid {...fakeProps()} />);
expect(wrapper.find("#major-grid").props().width).toEqual(3000);
expect(wrapper.find("#minor-grid").props().width).toEqual(3000);
expect(wrapper.find("#axis-arrows").find("line").first().props())

View File

@ -2,19 +2,18 @@ import * as React from "react";
import { MapBackground } from "../map_background";
import { shallow } from "enzyme";
import { MapBackgroundProps } from "../interfaces";
import { fakeMapTransformProps } from "../../../__test_support__/map_transform_props";
describe("<MapBackground/>", () => {
function fakeProps(): MapBackgroundProps {
return {
mapTransformProps: {
quadrant: 2, gridSize: { x: 3000, y: 1500 }
},
mapTransformProps: fakeMapTransformProps(),
plantAreaOffset: { x: 100, y: 100 }
};
}
it("renders map background", () => {
const wrapper = shallow(<MapBackground {...fakeProps() } />);
const wrapper = shallow(<MapBackground {...fakeProps()} />);
expect(wrapper.find("#bed-interior").props().width).toEqual(3180);
expect(wrapper.find("#bed-border").props().width).toEqual(3200);
});

View File

@ -4,6 +4,7 @@ import { MapImage, MapImageProps } from "../map_image";
import { SpecialStatus } from "../../../resources/tagged_resources";
import { cloneDeep } from "lodash";
import { trim } from "../../../util";
import { fakeMapTransformProps } from "../../../__test_support__/map_transform_props";
describe("<MapImage />", () => {
const fakeProps = (): MapImageProps => {
@ -29,15 +30,12 @@ describe("<MapImage />", () => {
scale: undefined,
calibrationZ: undefined
},
mapTransformProps: {
gridSize: { x: 0, y: 0 },
quadrant: 1
},
mapTransformProps: fakeMapTransformProps(),
};
};
it("doesn't render image", () => {
const wrapper = mount(<MapImage {...fakeProps() } />);
const wrapper = mount(<MapImage {...fakeProps()} />);
expect(wrapper.html()).toEqual("<image></image>");
});
@ -77,10 +75,9 @@ describe("<MapImage />", () => {
scale: "0.8041",
calibrationZ: "0"
};
INPUT_SET_1.mapTransformProps = {
gridSize: { x: 5900, y: 2900 },
quadrant: 3
};
INPUT_SET_1.mapTransformProps = fakeMapTransformProps();
INPUT_SET_1.mapTransformProps.gridSize = { x: 5900, y: 2900 },
INPUT_SET_1.mapTransformProps.quadrant = 3;
INPUT_SET_1.sizeOverride = { width: 480, height: 640 };
const INPUT_SET_2 = cloneDeep(INPUT_SET_1);

View File

@ -1,6 +1,7 @@
import * as React from "react";
import { SelectionBox, SelectionBoxProps } from "../selection_box";
import { shallow } from "enzyme";
import { fakeMapTransformProps } from "../../../__test_support__/map_transform_props";
describe("<SelectionBox/>", () => {
function fakeProps(): SelectionBoxProps {
@ -11,14 +12,12 @@ describe("<SelectionBox/>", () => {
x1: 240,
y1: 130
},
mapTransformProps: {
quadrant: 2, gridSize: { x: 3000, y: 1500 }
}
mapTransformProps: fakeMapTransformProps(),
};
}
it("renders selection box", () => {
const wrapper = shallow(<SelectionBox {...fakeProps() } />);
const wrapper = shallow(<SelectionBox {...fakeProps()} />);
const boxProps = wrapper.find("rect").props();
expect(boxProps.x).toEqual(40);
expect(boxProps.y).toEqual(30);
@ -29,14 +28,14 @@ describe("<SelectionBox/>", () => {
it("doesn't render selection box: partially undefined", () => {
const p = fakeProps();
p.selectionBox.x1 = undefined;
const wrapper = shallow(<SelectionBox {...p } />);
const wrapper = shallow(<SelectionBox {...p} />);
expect(wrapper.html()).toEqual("<g id=\"selection-box\"></g>");
});
it("renders selection box: quadrant 4", () => {
const p = fakeProps();
p.mapTransformProps.quadrant = 4;
const wrapper = shallow(<SelectionBox {...p } />);
const wrapper = shallow(<SelectionBox {...p} />);
const boxProps = wrapper.find("rect").props();
expect(boxProps.x).toEqual(2760);
expect(boxProps.y).toEqual(1370);

View File

@ -11,6 +11,7 @@ import {
import { shallow } from "enzyme";
import { SpreadOverlapHelperProps } from "../interfaces";
import { fakePlant } from "../../../__test_support__/fake_state/resources";
import { fakeMapTransformProps } from "../../../__test_support__/map_transform_props";
describe("<SpreadOverlapHelper/>", () => {
function fakeProps(): SpreadOverlapHelperProps {
@ -19,9 +20,7 @@ describe("<SpreadOverlapHelper/>", () => {
plant.body.y = 100;
plant.body.radius = 25;
return {
mapTransformProps: {
quadrant: 2, gridSize: { x: 3000, y: 1500 }
},
mapTransformProps: fakeMapTransformProps(),
plant,
dragging: false,
zoomLvl: 1,
@ -36,7 +35,7 @@ describe("<SpreadOverlapHelper/>", () => {
// Center distance: 900mm (inactive plant at x=100, y=100)
// Overlap: -650mm (default spread = radius * 10 = 250mm)
// Percentage overlap of inactive plant: 0%
const wrapper = shallow(<SpreadOverlapHelper {...p } />);
const wrapper = shallow(<SpreadOverlapHelper {...p} />);
const indicator = wrapper.find(".overlap-circle").props();
expect(indicator.fill).toEqual("none");
});
@ -47,7 +46,7 @@ describe("<SpreadOverlapHelper/>", () => {
// Center distance: 240mm (inactive plant at x=100, y=100)
// Overlap: 10mm (default spread = radius * 10 = 250mm)
// Percentage overlap of inactive plant: 4%
const wrapper = shallow(<SpreadOverlapHelper {...p } />);
const wrapper = shallow(<SpreadOverlapHelper {...p} />);
const indicator = wrapper.find(".overlap-circle").props();
expect(indicator.fill).toEqual("rgba(41, 141, 0, 0.04)"); // "green"
});
@ -58,7 +57,7 @@ describe("<SpreadOverlapHelper/>", () => {
// Center distance: 200mm (inactive plant at x=100, y=100)
// Overlap: 50mm (default spread = radius * 10 = 250mm)
// Percentage overlap of inactive plant: 20%
const wrapper = shallow(<SpreadOverlapHelper {...p } />);
const wrapper = shallow(<SpreadOverlapHelper {...p} />);
const indicator = wrapper.find(".overlap-circle").props();
expect(indicator.fill).toEqual("rgba(204, 255, 0, 0.2)"); // "yellow"
});
@ -69,7 +68,7 @@ describe("<SpreadOverlapHelper/>", () => {
// Center distance: 150mm (inactive plant at x=100, y=100)
// Overlap: 100mm (default spread = radius * 10 = 250mm)
// Percentage overlap of inactive plant: 40%
const wrapper = shallow(<SpreadOverlapHelper {...p } />);
const wrapper = shallow(<SpreadOverlapHelper {...p} />);
const indicator = wrapper.find(".overlap-circle").props();
expect(indicator.fill).toEqual("rgba(255, 102, 0, 0.3)"); // "orange"
});
@ -80,7 +79,7 @@ describe("<SpreadOverlapHelper/>", () => {
// Center distance: 125mm (inactive plant at x=100, y=100)
// Overlap: 125mm (default spread = radius * 10 = 250mm)
// Percentage overlap of inactive plant: 50%
const wrapper = shallow(<SpreadOverlapHelper {...p } />);
const wrapper = shallow(<SpreadOverlapHelper {...p} />);
const indicator = wrapper.find(".overlap-circle").props();
expect(indicator.fill).toEqual("rgba(255, 20, 0, 0.3)"); // "red"
});
@ -91,7 +90,7 @@ describe("<SpreadOverlapHelper/>", () => {
// Center distance: 50mm (inactive plant at x=100, y=100)
// Overlap: 200mm (default spread = radius * 10 = 250mm)
// Percentage overlap of inactive plant: 80%
const wrapper = shallow(<SpreadOverlapHelper {...p } />);
const wrapper = shallow(<SpreadOverlapHelper {...p} />);
const indicator = wrapper.find(".overlap-circle").props();
expect(indicator.fill).toEqual("rgba(255, 0, 0, 0.3)"); // "red"
});
@ -102,7 +101,7 @@ describe("<SpreadOverlapHelper/>", () => {
// Center distance: 0mm (inactive plant at x=100, y=100)
// Overlap: 250mm (default spread = radius * 10 = 250mm)
// Percentage overlap of inactive plant: 100%
const wrapper = shallow(<SpreadOverlapHelper {...p } />);
const wrapper = shallow(<SpreadOverlapHelper {...p} />);
const indicator = wrapper.find(".overlap-circle").props();
expect(indicator.fill).toEqual("rgba(255, 0, 0, 0.3)"); // "red"
});

View File

@ -1,6 +1,7 @@
import * as React from "react";
import { TargetCoordinate, TargetCoordinateProps } from "../target_coordinate";
import { shallow } from "enzyme";
import { fakeMapTransformProps } from "../../../__test_support__/map_transform_props";
describe("<TargetCoordinate/>", () => {
function fakeProps(): TargetCoordinateProps {
@ -10,14 +11,12 @@ describe("<TargetCoordinate/>", () => {
y: 200,
z: 0
},
mapTransformProps: {
quadrant: 2, gridSize: { x: 3000, y: 1500 }
}
mapTransformProps: fakeMapTransformProps(),
};
}
it("renders target", () => {
const wrapper = shallow(<TargetCoordinate {...fakeProps() } />);
const wrapper = shallow(<TargetCoordinate {...fakeProps()} />);
const boxProps = wrapper.find("rect").props();
expect(boxProps.x).toEqual(90);
expect(boxProps.y).toEqual(198);

View File

@ -2,13 +2,12 @@ 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";
describe("<ToolSlotPoint/>", () => {
function fakeProps(): TSPProps {
return {
mapTransformProps: {
quadrant: 2, gridSize: { x: 3000, y: 1500 }
},
mapTransformProps: fakeMapTransformProps(),
slot: { toolSlot: fakeToolSlot(), tool: fakeTool() }
};
}
@ -42,28 +41,28 @@ describe("<ToolSlotPoint/>", () => {
it("displays 'no tool'", () => {
const p = fakeProps();
p.slot.tool = undefined;
const wrapper = mount(<ToolSlotPoint {...p } />);
const wrapper = mount(<ToolSlotPoint {...p} />);
wrapper.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 = mount(<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 = mount(<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 = mount(<ToolSlotPoint {...p} />);
expect(wrapper.find("#SeedTrayPattern").length).toEqual(1);
});
});

View File

@ -9,6 +9,7 @@ import {
import { McuParams } from "farmbot";
import { AxisNumberProperty, BotSize, MapTransformProps } from "../interfaces";
import { StepsPerMmXY } from "../../../devices/interfaces";
import { fakeMapTransformProps } from "../../../__test_support__/map_transform_props";
describe("Utils", () => {
it("rounds a number", () => {
@ -20,7 +21,7 @@ describe("Utils", () => {
describe("translateScreenToGarden()", () => {
it("translates screen coords to garden coords: zoomLvl = 1", () => {
const result = translateScreenToGarden({
mapTransformProps: { quadrant: 2, gridSize: { x: 3000, y: 1500 } },
mapTransformProps: fakeMapTransformProps(),
page: { x: 520, y: 212 },
scroll: { left: 10, top: 20 },
zoomLvl: 1,
@ -31,7 +32,7 @@ describe("translateScreenToGarden()", () => {
it("translates screen coords to garden coords: zoomLvl < 1", () => {
const result = translateScreenToGarden({
mapTransformProps: { quadrant: 2, gridSize: { x: 3000, y: 1500 } },
mapTransformProps: fakeMapTransformProps(),
page: { x: 1132, y: 382 },
scroll: { left: 10, top: 20 },
zoomLvl: 0.33,
@ -42,7 +43,7 @@ describe("translateScreenToGarden()", () => {
it("translates screen coords to garden coords: zoomLvl > 1", () => {
const result = translateScreenToGarden({
mapTransformProps: { quadrant: 2, gridSize: { x: 3000, y: 1500 } },
mapTransformProps: fakeMapTransformProps(),
page: { x: 1132, y: 382 },
scroll: { left: 10, top: 20 },
zoomLvl: 1.5,
@ -52,8 +53,11 @@ describe("translateScreenToGarden()", () => {
});
it("translates screen coords to garden coords: other case", () => {
const fakeMTP = fakeMapTransformProps();
fakeMTP.quadrant = 3;
fakeMTP.gridSize = { x: 300, y: 150 };
const result = translateScreenToGarden({
mapTransformProps: { quadrant: 3, gridSize: { x: 300, y: 150 } },
mapTransformProps: fakeMTP,
page: { x: 332, y: 132 },
scroll: { left: 10, top: 20 },
zoomLvl: 0.75,
@ -173,7 +177,8 @@ describe("getMapSize()", () => {
});
describe("transformXY", () => {
const gridSize = { x: 2000, y: 1000 };
const mapTransformProps = fakeMapTransformProps();
mapTransformProps.gridSize = { x: 2000, y: 1000 };
type QXY = { qx: number, qy: number };
@ -188,43 +193,50 @@ describe("transformXY", () => {
it("calculates transformed coordinate: quadrant 2", () => {
const original = { qx: 100, qy: 200 };
const transformed = { qx: 100, qy: 200 };
const transformProps = { quadrant: 2, gridSize };
transformCheck(original, transformed, transformProps);
mapTransformProps.quadrant = 2;
transformCheck(original, transformed, mapTransformProps);
});
it("calculates transformed coordinate: quadrant 4", () => {
const original = { qx: 100, qy: 200 };
const transformed = { qx: 1900, qy: 800 };
const transformProps = { quadrant: 4, gridSize };
transformCheck(original, transformed, transformProps);
mapTransformProps.quadrant = 4;
transformCheck(original, transformed, mapTransformProps);
});
it("calculates transformed coordinate: quadrant 4 (outside of grid)", () => {
const original = { qx: 2200, qy: 1100 };
const transformed = { qx: -200, qy: -100 };
const transformProps = { quadrant: 4, gridSize };
transformCheck(original, transformed, transformProps);
mapTransformProps.quadrant = 4;
transformCheck(original, transformed, mapTransformProps);
});
});
describe("transformForQuadrant()", () => {
const mapTransformProps = fakeMapTransformProps();
mapTransformProps.gridSize = { x: 200, y: 100 };
it("calculates transform for quadrant 1", () => {
expect(transformForQuadrant({ quadrant: 1, gridSize: { x: 200, y: 100 } }))
mapTransformProps.quadrant = 1;
expect(transformForQuadrant(mapTransformProps))
.toEqual("scale(-1, 1) translate(-200, 0)");
});
it("calculates transform for quadrant 2", () => {
expect(transformForQuadrant({ quadrant: 2, gridSize: { x: 200, y: 100 } }))
mapTransformProps.quadrant = 2;
expect(transformForQuadrant(mapTransformProps))
.toEqual("scale(1, 1) translate(0, 0)");
});
it("calculates transform for quadrant 3", () => {
expect(transformForQuadrant({ quadrant: 3, gridSize: { x: 200, y: 100 } }))
mapTransformProps.quadrant = 3;
expect(transformForQuadrant(mapTransformProps))
.toEqual("scale(1, -1) translate(0, -100)");
});
it("calculates transform for quadrant 4", () => {
expect(transformForQuadrant({ quadrant: 4, gridSize: { x: 200, y: 100 } }))
mapTransformProps.quadrant = 4;
expect(transformForQuadrant(mapTransformProps))
.toEqual("scale(-1, -1) translate(-200, -100)");
});
});

View File

@ -3,15 +3,14 @@ import { shallow, mount } from "enzyme";
import { Bugs, BugsProps, showBugResetButton, showBugs, resetBugs } from "../bugs";
import { EggKeys, setEggStatus, getEggStatus } from "../status";
import { range } from "lodash";
import { fakeMapTransformProps } from "../../../../__test_support__/map_transform_props";
const expectAlive = (value: string) =>
expect(getEggStatus(EggKeys.BUGS_ARE_STILL_ALIVE)).toEqual(value);
describe("<Bugs />", () => {
const fakeProps = (): BugsProps => ({
mapTransformProps: {
quadrant: 2, gridSize: { x: 3000, y: 1500 }
},
mapTransformProps: fakeMapTransformProps(),
botSize: {
x: { value: 3000, isDefault: true },
y: { value: 1500, isDefault: true }

View File

@ -36,6 +36,7 @@ import { isNumber } from "lodash";
import { TargetCoordinate } from "./target_coordinate";
import { DrawnPoint } from "./drawn_point";
import { Bugs, showBugs } from "./easter_eggs/bugs";
import { BooleanSetting } from "../../session_keys";
export enum Mode {
none = "none",
@ -70,7 +71,8 @@ export class GardenMap extends
get mapTransformProps(): MapTransformProps {
return {
quadrant: this.props.botOriginQuadrant,
gridSize: this.props.gridSize
gridSize: this.props.gridSize,
xySwap: !!this.props.getConfigValue(BooleanSetting.xy_swap),
};
}

View File

@ -45,6 +45,7 @@ export interface GardenMapLegendProps {
export type MapTransformProps = {
quadrant: BotOriginQuadrant,
gridSize: AxisNumberProperty
xySwap: boolean;
};
export interface GardenPlantProps {

View File

@ -2,15 +2,14 @@ import * as React from "react";
import { DragHelperLayer, DragHelperLayerProps } from "../drag_helper_layer";
import { shallow } from "enzyme";
import { fakePlant } from "../../../../__test_support__/fake_state/resources";
import { fakeMapTransformProps } from "../../../../__test_support__/map_transform_props";
describe("<DragHelperLayer/>", () => {
function fakeProps(): DragHelperLayerProps {
return {
currentPlant: fakePlant(),
editing: true,
mapTransformProps: {
quadrant: 2, gridSize: { x: 3000, y: 1500 }
},
mapTransformProps: fakeMapTransformProps(),
dragging: true,
zoomLvl: 1.8,
activeDragXY: { x: undefined, y: undefined, z: undefined },
@ -20,7 +19,7 @@ describe("<DragHelperLayer/>", () => {
it("shows drag helpers", () => {
const p = fakeProps();
const wrapper = shallow(<DragHelperLayer {...p } />);
const wrapper = shallow(<DragHelperLayer {...p} />);
["drag-helpers",
"coordinates-tooltip",
"long-crosshair",
@ -31,7 +30,7 @@ describe("<DragHelperLayer/>", () => {
it("doesn't show drag helpers", () => {
const p = fakeProps();
p.editing = false;
const wrapper = shallow(<DragHelperLayer {...p } />);
const wrapper = shallow(<DragHelperLayer {...p} />);
expect(wrapper.html()).toEqual("<g id=\"drag-helper-layer\"></g>");
});
});

View File

@ -2,6 +2,7 @@ import * as React from "react";
import { FarmBotLayer } from "../farmbot_layer";
import { shallow } from "enzyme";
import { FarmBotLayerProps } from "../../interfaces";
import { fakeMapTransformProps } from "../../../../__test_support__/map_transform_props";
describe("<FarmBotLayer/>", () => {
function fakeProps(): FarmBotLayerProps {
@ -12,9 +13,7 @@ describe("<FarmBotLayer/>", () => {
scaled_encoders: { x: undefined, y: undefined, z: undefined },
raw_encoders: { x: undefined, y: undefined, z: undefined },
},
mapTransformProps: {
quadrant: 1, gridSize: { x: 3000, y: 1500 }
},
mapTransformProps: fakeMapTransformProps(),
stopAtHome: { x: true, y: true },
botSize: {
x: { value: 3000, isDefault: true },
@ -28,7 +27,7 @@ describe("<FarmBotLayer/>", () => {
it("shows layer elements", () => {
const p = fakeProps();
const result = shallow(<FarmBotLayer {...p } />);
const result = shallow(<FarmBotLayer {...p} />);
const layer = result.find("#farmbot-layer");
expect(layer.find("#virtual-farmbot")).toBeTruthy();
expect(layer.find("#extents")).toBeTruthy();
@ -37,7 +36,7 @@ describe("<FarmBotLayer/>", () => {
it("toggles visibility off", () => {
const p = fakeProps();
p.visible = false;
const result = shallow(<FarmBotLayer {...p } />);
const result = shallow(<FarmBotLayer {...p} />);
expect(result.html()).toEqual("<g id=\"farmbot-layer\"></g>");
});
});

View File

@ -2,6 +2,7 @@ import * as React from "react";
import { HoveredPlantLayer, HoveredPlantLayerProps } from "../hovered_plant_layer";
import { shallow } from "enzyme";
import { fakePlant } from "../../../../__test_support__/fake_state/resources";
import { fakeMapTransformProps } from "../../../../__test_support__/map_transform_props";
describe("<HoveredPlantLayer/>", () => {
function fakeProps(): HoveredPlantLayerProps {
@ -23,16 +24,14 @@ describe("<HoveredPlantLayer/>", () => {
},
hoveredPlant: fakePlant(),
isEditing: false,
mapTransformProps: {
quadrant: 2, gridSize: { x: 3000, y: 1500 }
}
mapTransformProps: fakeMapTransformProps(),
};
}
it("shows hovered plant icon", () => {
const p = fakeProps();
p.designer.hoveredPlant.icon = "fake icon";
const wrapper = shallow(<HoveredPlantLayer {...p } />);
const wrapper = shallow(<HoveredPlantLayer {...p} />);
const icon = wrapper.find("image").props();
expect(icon.visibility).toBeTruthy();
expect(icon.opacity).toEqual(1);
@ -44,7 +43,7 @@ describe("<HoveredPlantLayer/>", () => {
const p = fakeProps();
p.designer.hoveredPlant.icon = "fake icon";
p.currentPlant = fakePlant();
const wrapper = shallow(<HoveredPlantLayer {...p } />);
const wrapper = shallow(<HoveredPlantLayer {...p} />);
expect(wrapper.find("#selected-plant-indicators").length).toEqual(1);
expect(wrapper.find("Circle").length).toEqual(1);
expect(wrapper.find("Circle").props().selected).toBeTruthy();
@ -55,7 +54,7 @@ describe("<HoveredPlantLayer/>", () => {
it("doesn't show hovered plant icon", () => {
const p = fakeProps();
const wrapper = shallow(<HoveredPlantLayer {...p } />);
const wrapper = shallow(<HoveredPlantLayer {...p} />);
expect(wrapper.html()).toEqual("<g id=\"hovered-plant-layer\"></g>");
});
});

View File

@ -2,6 +2,7 @@ import * as React from "react";
import { ImageLayer, ImageLayerProps } from "../image_layer";
import { shallow } from "enzyme";
import { fakeImage, fakeWebAppConfig } from "../../../../__test_support__/fake_state/resources";
import { fakeMapTransformProps } from "../../../../__test_support__/map_transform_props";
const mockConfig = fakeWebAppConfig();
jest.mock("../../../../resources/selectors", () => {
@ -19,9 +20,7 @@ describe("<ImageLayer/>", () => {
return {
visible: true,
images: [image],
mapTransformProps: {
quadrant: 2, gridSize: { x: 3000, y: 1500 }
},
mapTransformProps: fakeMapTransformProps(),
cameraCalibrationData: {
offset: { x: "0", y: "0" },
origin: "TOP_LEFT",

View File

@ -16,15 +16,14 @@ import { PlantLayer } from "../plant_layer";
import { shallow } from "enzyme";
import { fakePlant } from "../../../../__test_support__/fake_state/resources";
import { PlantLayerProps } from "../../interfaces";
import { fakeMapTransformProps } from "../../../../__test_support__/map_transform_props";
describe("<PlantLayer/>", () => {
function fakeProps(): PlantLayerProps {
return {
visible: true,
plants: [fakePlant()],
mapTransformProps: {
quadrant: 2, gridSize: { x: 3000, y: 1500 }
},
mapTransformProps: fakeMapTransformProps(),
currentPlant: undefined,
dragging: false,
editing: false,
@ -38,7 +37,7 @@ describe("<PlantLayer/>", () => {
it("shows plants", () => {
const p = fakeProps();
const wrapper = shallow(<PlantLayer {...p } />);
const wrapper = shallow(<PlantLayer {...p} />);
const layer = wrapper.find("#plant-layer");
expect(layer.find(".plant-link-wrapper").length).toEqual(1);
["soil-cloud",
@ -55,21 +54,21 @@ describe("<PlantLayer/>", () => {
it("toggles visibility off", () => {
const p = fakeProps();
p.visible = false;
const wrapper = shallow(<PlantLayer {...p } />);
const wrapper = shallow(<PlantLayer {...p} />);
expect(wrapper.html()).toEqual("<g id=\"plant-layer\"></g>");
});
it("is in clickable mode", () => {
mockPath = "/app/designer/plants";
const p = fakeProps();
const wrapper = shallow(<PlantLayer {...p } />);
const wrapper = shallow(<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 = shallow(<PlantLayer {...p} />);
expect(wrapper.find("Link").props().style)
.toEqual({ pointerEvents: "none" });
});

View File

@ -2,21 +2,20 @@ import * as React from "react";
import { PointLayer, PointLayerProps } from "../point_layer";
import { shallow } from "enzyme";
import { fakePoint } from "../../../../__test_support__/fake_state/resources";
import { fakeMapTransformProps } from "../../../../__test_support__/map_transform_props";
describe("<PointLayer/>", () => {
function fakeProps(): PointLayerProps {
return {
visible: true,
points: [fakePoint()],
mapTransformProps: {
quadrant: 2, gridSize: { x: 3000, y: 1500 }
}
mapTransformProps: fakeMapTransformProps(),
};
}
it("shows points", () => {
const p = fakeProps();
const wrapper = shallow(<PointLayer {...p } />);
const wrapper = shallow(<PointLayer {...p} />);
const layer = wrapper.find("#point-layer");
expect(layer.find("GardenPoint").html()).toContain("r=\"100\"");
});
@ -24,7 +23,7 @@ describe("<PointLayer/>", () => {
it("toggles visibility off", () => {
const p = fakeProps();
p.visible = false;
const wrapper = shallow(<PointLayer {...p } />);
const wrapper = shallow(<PointLayer {...p} />);
const layer = wrapper.find("#point-layer");
expect(layer.find("GardenPoint").length).toEqual(0);
});

View File

@ -2,6 +2,7 @@ import * as React from "react";
import { SpreadLayer, SpreadLayerProps } from "../spread_layer";
import { shallow } from "enzyme";
import { fakePlant } from "../../../../__test_support__/fake_state/resources";
import { fakeMapTransformProps } from "../../../../__test_support__/map_transform_props";
describe("<SpreadLayer/>", () => {
function fakeProps(): SpreadLayerProps {
@ -9,9 +10,7 @@ describe("<SpreadLayer/>", () => {
visible: true,
plants: [fakePlant()],
currentPlant: undefined,
mapTransformProps: {
quadrant: 2, gridSize: { x: 3000, y: 1500 }
},
mapTransformProps: fakeMapTransformProps(),
dragging: false,
zoomLvl: 1.8,
activeDragXY: { x: undefined, y: undefined, z: undefined },
@ -22,7 +21,7 @@ describe("<SpreadLayer/>", () => {
it("shows spread", () => {
const p = fakeProps();
const wrapper = shallow(<SpreadLayer {...p } />);
const wrapper = shallow(<SpreadLayer {...p} />);
const layer = wrapper.find("#spread-layer");
expect(layer.find("SpreadCircle").html()).toContain("r=\"125\"");
});
@ -30,7 +29,7 @@ describe("<SpreadLayer/>", () => {
it("toggles visibility off", () => {
const p = fakeProps();
p.visible = false;
const wrapper = shallow(<SpreadLayer {...p } />);
const wrapper = shallow(<SpreadLayer {...p} />);
const layer = wrapper.find("#spread-layer");
expect(layer.find("SpreadCircle").length).toEqual(0);
});

View File

@ -9,6 +9,7 @@ jest.mock("../../../../history", () => ({
import * as React from "react";
import { ToolSlotLayer, ToolSlotLayerProps } from "../tool_slot_layer";
import { fakeMapTransformProps } from "../../../../__test_support__/map_transform_props";
import { fakeResource } from "../../../../__test_support__/fake_resource";
import { ToolSlotPointer } from "../../../../interfaces";
import { shallow } from "enzyme";
@ -34,28 +35,26 @@ describe("<ToolSlotLayer/>", () => {
return {
visible: false,
slots: [{ toolSlot, tool: undefined }],
mapTransformProps: {
quadrant: 1, gridSize: { x: 3000, y: 1500 }
},
mapTransformProps: fakeMapTransformProps(),
dispatch: jest.fn()
};
}
it("toggles visibility off", () => {
const result = shallow(<ToolSlotLayer {...fakeProps() } />);
const result = shallow(<ToolSlotLayer {...fakeProps()} />);
expect(result.find("ToolSlotPoint").length).toEqual(0);
});
it("toggles visibility on", () => {
const p = fakeProps();
p.visible = true;
const result = shallow(<ToolSlotLayer {...p } />);
const result = shallow(<ToolSlotLayer {...p} />);
expect(result.find("ToolSlotPoint").length).toEqual(1);
});
it("navigates to tools page", async () => {
mockPath = "/app/designer/plants";
const p = fakeProps();
const wrapper = shallow(<ToolSlotLayer {...p } />);
const wrapper = shallow(<ToolSlotLayer {...p} />);
const tools = wrapper.find("g").first();
await tools.simulate("click");
expect(mockHistory).toHaveBeenCalledWith("/app/tools");
@ -64,7 +63,7 @@ describe("<ToolSlotLayer/>", () => {
it("doesn't navigate to tools page", async () => {
mockPath = "/app/designer/plants/1";
const p = fakeProps();
const wrapper = shallow(<ToolSlotLayer {...p } />);
const wrapper = shallow(<ToolSlotLayer {...p} />);
const tools = wrapper.find("g").first();
await tools.simulate("click");
expect(mockHistory).not.toHaveBeenCalled();
@ -74,7 +73,7 @@ describe("<ToolSlotLayer/>", () => {
it("is in non-clickable mode", () => {
mockPath = "/app/designer/plants/select";
const p = fakeProps();
const wrapper = shallow(<ToolSlotLayer {...p } />);
const wrapper = shallow(<ToolSlotLayer {...p} />);
expect(wrapper.find("g").props().style)
.toEqual({ pointerEvents: "none" });
});

View File

@ -3,15 +3,14 @@ import { shallow } from "enzyme";
import { BotOriginQuadrant } from "../../../interfaces";
import { BotFigure, BotFigureProps } from "../bot_figure";
import { Color } from "../../../../ui/index";
import { fakeMapTransformProps } from "../../../../__test_support__/map_transform_props";
describe("<BotFigure/>", () => {
function fakeProps(): BotFigureProps {
return {
name: "",
position: { x: 0, y: 0, z: 0 },
mapTransformProps: {
quadrant: 1, gridSize: { x: 3000, y: 1500 }
},
mapTransformProps: fakeMapTransformProps(),
plantAreaOffset: { x: 100, y: 100 }
};
}

View File

@ -16,15 +16,14 @@ import * as React from "react";
import { shallow } from "enzyme";
import { BotPeripheralsProps, BotPeripherals } from "../bot_peripherals";
import { BooleanSetting } from "../../../../session_keys";
import { fakeMapTransformProps } from "../../../../__test_support__/map_transform_props";
describe("<BotPeripherals/>", () => {
function fakeProps(): BotPeripheralsProps {
return {
peripherals: [{ label: "", value: false }],
position: { x: 0, y: 0, z: 0 },
mapTransformProps: {
quadrant: 2, gridSize: { x: 3000, y: 1500 }
},
mapTransformProps: fakeMapTransformProps(),
plantAreaOffset: { x: 100, y: 100 }
};
}
@ -34,7 +33,7 @@ describe("<BotPeripherals/>", () => {
const p = fakeProps();
p.peripherals[0].label = name;
p.peripherals[0].value = false;
const wrapper = shallow(<BotPeripherals {...p } />);
const wrapper = shallow(<BotPeripherals {...p} />);
expect(wrapper.find(`#${name}`).length).toEqual(0);
});
}
@ -42,11 +41,11 @@ describe("<BotPeripherals/>", () => {
function animationToggle(
props: BotPeripheralsProps, enabled: number, disabled: number) {
mockStorj[BooleanSetting.disable_animations] = false;
const wrapperEnabled = shallow(<BotPeripherals {...props } />);
const wrapperEnabled = shallow(<BotPeripherals {...props} />);
expect(wrapperEnabled.find("use").length).toEqual(enabled);
mockStorj[BooleanSetting.disable_animations] = true;
const wrapperDisabled = shallow(<BotPeripherals {...props } />);
const wrapperDisabled = shallow(<BotPeripherals {...props} />);
expect(wrapperDisabled.find("use").length).toEqual(disabled);
}
@ -54,7 +53,7 @@ describe("<BotPeripherals/>", () => {
const p = fakeProps();
p.peripherals[0].label = "lights";
p.peripherals[0].value = true;
const wrapper = shallow(<BotPeripherals {...p } />);
const wrapper = shallow(<BotPeripherals {...p} />);
expect(wrapper.find("#lights").length).toEqual(1);
expect(wrapper.find("rect").last().props()).toEqual({
fill: "url(#LightingGradient)",
@ -66,7 +65,7 @@ describe("<BotPeripherals/>", () => {
const p = fakeProps();
p.peripherals[0].label = "water valve";
p.peripherals[0].value = true;
const wrapper = shallow(<BotPeripherals {...p } />);
const wrapper = shallow(<BotPeripherals {...p} />);
expect(wrapper.find("#water").length).toEqual(1);
expect(wrapper.find("circle").last().props()).toEqual({
cx: 0, cy: 0, fill: "rgb(11, 83, 148)", fillOpacity: 0.2, r: 55
@ -78,7 +77,7 @@ describe("<BotPeripherals/>", () => {
const p = fakeProps();
p.peripherals[0].label = "vacuum pump";
p.peripherals[0].value = true;
const wrapper = shallow(<BotPeripherals {...p } />);
const wrapper = shallow(<BotPeripherals {...p} />);
expect(wrapper.find("#vacuum").length).toEqual(1);
expect(wrapper.find("circle").last().props()).toEqual({
fill: "url(#WaveGradient)", cx: 0, cy: 0, r: 100

View File

@ -1,6 +1,7 @@
import * as React from "react";
import { shallow } from "enzyme";
import { BotTrail, BotTrailProps, VirtualTrail } from "../bot_trail";
import { fakeMapTransformProps } from "../../../../__test_support__/map_transform_props";
describe("<BotTrail/>", () => {
function fakeProps(): BotTrailProps {
@ -12,9 +13,7 @@ describe("<BotTrail/>", () => {
{ coord: { x: 4, y: 4 }, water: 20 }]);
return {
position: { x: 0, y: 0, z: 0 },
mapTransformProps: {
quadrant: 2, gridSize: { x: 3000, y: 1500 }
},
mapTransformProps: fakeMapTransformProps(),
peripherals: []
};
}

View File

@ -16,6 +16,7 @@ import { VirtualFarmBot } from "../index";
import { shallow } from "enzyme";
import { VirtualFarmBotProps } from "../../interfaces";
import { Dictionary } from "farmbot";
import { fakeMapTransformProps } from "../../../../__test_support__/map_transform_props";
describe("<VirtualFarmBot/>", () => {
function fakeProps(): VirtualFarmBotProps {
@ -25,9 +26,7 @@ describe("<VirtualFarmBot/>", () => {
scaled_encoders: { x: undefined, y: undefined, z: undefined },
raw_encoders: { x: undefined, y: undefined, z: undefined },
},
mapTransformProps: {
quadrant: 1, gridSize: { x: 3000, y: 1500 }
},
mapTransformProps: fakeMapTransformProps(),
plantAreaOffset: { x: 100, y: 100 },
peripherals: [],
eStopStatus: false
@ -35,7 +34,7 @@ describe("<VirtualFarmBot/>", () => {
}
it("shows bot position", () => {
const wrapper = shallow(<VirtualFarmBot {...fakeProps() } />);
const wrapper = shallow(<VirtualFarmBot {...fakeProps()} />);
const figures = wrapper.find("BotFigure");
expect(figures.length).toEqual(1);
expect(figures.last().props().name).toEqual("motor-position");
@ -43,13 +42,13 @@ describe("<VirtualFarmBot/>", () => {
it("shows trail", () => {
mockStorj["display_trail"] = true;
const wrapper = shallow(<VirtualFarmBot {...fakeProps() } />);
const wrapper = shallow(<VirtualFarmBot {...fakeProps()} />);
expect(wrapper.find("BotTrail").length).toEqual(1);
});
it("shows encoder position", () => {
mockStorj["encoder_figure"] = true;
const wrapper = shallow(<VirtualFarmBot {...fakeProps() } />);
const wrapper = shallow(<VirtualFarmBot {...fakeProps()} />);
const figures = wrapper.find("BotFigure");
expect(figures.length).toEqual(2);
expect(figures.last().props().name).toEqual("encoder-position");

View File

@ -3,14 +3,13 @@ import { shallow } from "enzyme";
import {
NegativePositionLabel, NegativePositionLabelProps
} from "../negative_position_labels";
import { fakeMapTransformProps } from "../../../../__test_support__/map_transform_props";
describe("<NegativePositionLabel />", () => {
const fakeProps = (): NegativePositionLabelProps => {
return {
position: { x: 1234, y: undefined, z: undefined },
mapTransformProps: {
quadrant: 1, gridSize: { x: 3000, y: 1500 }
},
mapTransformProps: fakeMapTransformProps(),
plantAreaOffset: { x: 100, y: 100 }
};
};

View File

@ -24,9 +24,9 @@ export class FallbackImg extends React.Component<Props, State> {
fallback = () => {
return <div className="webcam-stream-unavailable">
<img src={this.props.fallback} style={{ maxWidth: "100%" }} />
<text>
<p>
{t("Unable to load webcam feed.")}
</text>
</p>
</div>;
}