From fb48165d68372d811edeff0408a52c82508ee9fb Mon Sep 17 00:00:00 2001 From: gabrielburnworth Date: Wed, 5 Jun 2019 13:48:18 -0700 Subject: [PATCH] test output cleanup --- frontend/__test_support__/svg_mount.tsx | 6 ++ frontend/__tests__/entry.tsx | 47 ------------- frontend/__tests__/entry_test.tsx | 32 +++++++++ frontend/__tests__/error_boundary_test.tsx | 4 ++ frontend/account/__tests__/index_test.tsx | 5 +- .../account/components/map_size_setting.tsx | 2 +- .../__tests__/crud_malformed_data_tests.ts | 8 +++ .../__tests__/connect_device/index_test.ts | 9 +++ frontend/connectivity/connect_device.ts | 4 +- .../connectivity/__tests__/diagram_test.tsx | 9 +-- .../__tests__/drawn_point_test.tsx | 24 ++++--- .../map/easter_eggs/__tests__/bugs_test.tsx | 11 ++-- .../plants/__tests__/plant_layer_test.tsx | 54 ++++++++------- .../__tests__/garden_sensor_reading_test.tsx | 11 ++-- .../__tests__/sensor_readings_layer_test.tsx | 4 +- .../__tests__/tool_graphics_test.tsx | 66 +++++++++---------- .../__tests__/tool_slot_point_test.tsx | 40 ++++++----- frontend/help/__tests__/tour_test.tsx | 1 + frontend/messages/__tests__/alerts_test.tsx | 12 ++-- .../__tests__/tagged_resource_test.ts | 2 + 20 files changed, 177 insertions(+), 174 deletions(-) create mode 100644 frontend/__test_support__/svg_mount.tsx delete mode 100644 frontend/__tests__/entry.tsx create mode 100644 frontend/__tests__/entry_test.tsx diff --git a/frontend/__test_support__/svg_mount.tsx b/frontend/__test_support__/svg_mount.tsx new file mode 100644 index 000000000..5a880fb3c --- /dev/null +++ b/frontend/__test_support__/svg_mount.tsx @@ -0,0 +1,6 @@ +import * as React from "react"; +import { mount } from "enzyme"; + +export function svgMount(element: React.ReactElement) { + return mount({element}); +} diff --git a/frontend/__tests__/entry.tsx b/frontend/__tests__/entry.tsx deleted file mode 100644 index a6c102a8a..000000000 --- a/frontend/__tests__/entry.tsx +++ /dev/null @@ -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(); - }); -}); diff --git a/frontend/__tests__/entry_test.tsx b/frontend/__tests__/entry_test.tsx new file mode 100644 index 000000000..244adabe5 --- /dev/null +++ b/frontend/__tests__/entry_test.tsx @@ -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"); + }); +}); diff --git a/frontend/__tests__/error_boundary_test.tsx b/frontend/__tests__/error_boundary_test.tsx index 3d15b0367..224731b7e 100644 --- a/frontend/__tests__/error_boundary_test.tsx +++ b/frontend/__tests__/error_boundary_test.tsx @@ -19,11 +19,15 @@ class Kaboom extends React.Component<{}, {}> { describe("", () => { it("handles exceptions", () => { + console.error = jest.fn(); const nodes = ; const el = mount(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")); }); }); diff --git a/frontend/account/__tests__/index_test.tsx b/frontend/account/__tests__/index_test.tsx index 46b1f2ee4..1de21ef36 100644 --- a/frontend/account/__tests__/index_test.tsx +++ b/frontend/account/__tests__/index_test.tsx @@ -1,6 +1,5 @@ -jest.mock("react-redux", () => ({ - connect: jest.fn() -})); +jest.mock("react-redux", () => ({ connect: jest.fn() })); +jest.mock("../labs/labs_features", () => ({ LabsFeatures: () =>
})); import * as React from "react"; import { fakeState } from "../../__test_support__/fake_state"; diff --git a/frontend/account/components/map_size_setting.tsx b/frontend/account/components/map_size_setting.tsx index c93c50975..97864932a 100644 --- a/frontend/account/components/map_size_setting.tsx +++ b/frontend/account/components/map_size_setting.tsx @@ -30,7 +30,7 @@ const LengthInput = (props: LengthInputProps) => props.dispatch(setWebAppConfigValue( props.setting, e.currentTarget.value))} /> diff --git a/frontend/api/__tests__/crud_malformed_data_tests.ts b/frontend/api/__tests__/crud_malformed_data_tests.ts index f14e80c85..bf7e88221 100644 --- a/frontend/api/__tests__/crud_malformed_data_tests.ts +++ b/frontend/api/__tests__/crud_malformed_data_tests.ts @@ -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")); }); }); }); diff --git a/frontend/connectivity/__tests__/connect_device/index_test.ts b/frontend/connectivity/__tests__/connect_device/index_test.ts index 81cd5dd71..7a2610e13 100644 --- a/frontend/connectivity/__tests__/connect_device/index_test.ts +++ b/frontend/connectivity/__tests__/connect_device/index_test.ts @@ -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(); }); diff --git a/frontend/connectivity/connect_device.ts b/frontend/connectivity/connect_device.ts index 16d221d70..0959e9b0f 100644 --- a/frontend/connectivity/connect_device.ts +++ b/frontend/connectivity/connect_device.ts @@ -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 { diff --git a/frontend/devices/connectivity/__tests__/diagram_test.tsx b/frontend/devices/connectivity/__tests__/diagram_test.tsx index 48b93c113..d031c7ac0 100644 --- a/frontend/devices/connectivity/__tests__/diagram_test.tsx +++ b/frontend/devices/connectivity/__tests__/diagram_test.tsx @@ -12,6 +12,7 @@ import { getConnectionColor } from "../diagram"; import { Color } from "../../../ui/index"; +import { svgMount } from "../../../__test_support__/svg_mount"; describe("", () => { function fakeProps(): ConnectivityDiagramProps { @@ -58,14 +59,14 @@ describe("", () => { } it("renders diagram", () => { - const wrapper = mount(); + const wrapper = svgMount(); expect(wrapper.text()) .toContain("BrowserWeb AppMessage BrokerFarmBotRaspberry PiF"); }); it("hover", () => { const p = fakeProps(); - const wrapper = mount(); + const wrapper = svgMount(); wrapper.find(".connector-hover-area").first().simulate("mouseEnter"); expect(p.hover).toHaveBeenCalledWith("EF"); }); @@ -130,7 +131,7 @@ describe("", () => { } it("renders", () => { - const wrapper = mount(); + const wrapper = svgMount(); const lines = wrapper.find("line"); expect(lines.length).toEqual(3); expect(lines.at(0).props()) @@ -154,7 +155,7 @@ describe("", () => { it("renders connected color", () => { const p = fakeProps(); p.connectionData.connectionStatus = true; - const wrapper = mount(); + const wrapper = svgMount(); expect(wrapper.find("line").at(1).props().stroke).toEqual(Color.green); }); }); diff --git a/frontend/farm_designer/map/drawn_point/__tests__/drawn_point_test.tsx b/frontend/farm_designer/map/drawn_point/__tests__/drawn_point_test.tsx index 59b0a118c..fcfae6612 100644 --- a/frontend/farm_designer/map/drawn_point/__tests__/drawn_point_test.tsx +++ b/frontend/farm_designer/map/drawn_point/__tests__/drawn_point_test.tsx @@ -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("", () => { - 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(); + const wrapper = svgMount(); expect(wrapper.find("g").props().stroke).toEqual("red"); expect(wrapper.find("circle").first().props()).toEqual({ id: "point-radius", strokeDasharray: "4 5", diff --git a/frontend/farm_designer/map/easter_eggs/__tests__/bugs_test.tsx b/frontend/farm_designer/map/easter_eggs/__tests__/bugs_test.tsx index bd8f903cc..84f8bbb3a 100644 --- a/frontend/farm_designer/map/easter_eggs/__tests__/bugs_test.tsx +++ b/frontend/farm_designer/map/easter_eggs/__tests__/bugs_test.tsx @@ -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("", () => { }); it("renders", () => { - const wrapper = shallow(); + const wrapper = svgMount(); expect(wrapper.find("image").length).toEqual(10); const firstBug = wrapper.find("image").first(); expect(firstBug.props()).toEqual(expect.objectContaining({ @@ -36,8 +37,8 @@ describe("", () => { it("kills bugs", () => { setEggStatus(EggKeys.BUGS_ARE_STILL_ALIVE, ""); expectAlive(""); - const wrapper = mount(); - wrapper.instance().state.bugs[0].r = 101; + const wrapper = svgMount(); + 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("", () => { 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 })); }); diff --git a/frontend/farm_designer/map/layers/plants/__tests__/plant_layer_test.tsx b/frontend/farm_designer/map/layers/plants/__tests__/plant_layer_test.tsx index 8fdbdc59d..9537cb8a9 100644 --- a/frontend/farm_designer/map/layers/plants/__tests__/plant_layer_test.tsx +++ b/frontend/farm_designer/map/layers/plants/__tests__/plant_layer_test.tsx @@ -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("", () => { - 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(); + const wrapper = svgMount(); 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("", () => { it("toggles visibility off", () => { const p = fakeProps(); p.visible = false; - const wrapper = shallow(); - expect(wrapper.html()).toEqual(""); + const wrapper = svgMount(); + expect(wrapper.html()).toEqual(""); }); it("is in clickable mode", () => { mockPath = "/app/designer/plants"; const p = fakeProps(); - const wrapper = shallow(); + const wrapper = svgMount(); expect(wrapper.find("Link").props().style).toEqual({}); }); it("is in non-clickable mode", () => { mockPath = "/app/designer/plants/select"; const p = fakeProps(); - const wrapper = shallow(); + const wrapper = svgMount(); expect(wrapper.find("Link").props().style) .toEqual({ pointerEvents: "none" }); }); @@ -73,7 +71,7 @@ describe("", () => { mockPath = "/app/designer/plants"; const p = fakeProps(); p.plants[0].body.id = 5; - const wrapper = shallow(); + const wrapper = svgMount(); expect(wrapper.find("Link").props().to) .toEqual("/app/designer/plants/5"); }); @@ -83,7 +81,7 @@ describe("", () => { const p = fakeProps(); p.plants = [fakePlantTemplate()]; p.plants[0].body.id = 5; - const wrapper = shallow(); + const wrapper = svgMount(); expect(wrapper.find("Link").props().to) .toEqual("/app/designer/saved_gardens/templates/5"); }); @@ -94,7 +92,7 @@ describe("", () => { const plant = fakePlant(); p.plants = [plant]; p.currentPlant = plant; - const wrapper = shallow(); + const wrapper = svgMount(); expect(wrapper.find("GardenPlant").props().selected).toEqual(true); }); @@ -104,7 +102,7 @@ describe("", () => { const plant = fakePlant(); p.plants = [plant]; p.selectedForDel = [plant.uuid]; - const wrapper = shallow(); + const wrapper = svgMount(); expect((wrapper.find("GardenPlant").props() as GardenPlantProps).grayscale) .toEqual(true); }); @@ -114,7 +112,7 @@ describe("", () => { const plant = fakePlant(); plant.body.id = 1; p.plants = [plant]; - const wrapper = shallow(); + const wrapper = svgMount(); expect((wrapper.find("Link").props()).style).toEqual({}); }); @@ -123,7 +121,7 @@ describe("", () => { const plant = fakePlant(); plant.body.id = 0; p.plants = [plant]; - const wrapper = shallow(); + const wrapper = svgMount(); expect((wrapper.find("Link").props()).style) .toEqual({ pointerEvents: "none" }); }); diff --git a/frontend/farm_designer/map/layers/sensor_readings/__tests__/garden_sensor_reading_test.tsx b/frontend/farm_designer/map/layers/sensor_readings/__tests__/garden_sensor_reading_test.tsx index 39558efcc..da50043b9 100644 --- a/frontend/farm_designer/map/layers/sensor_readings/__tests__/garden_sensor_reading_test.tsx +++ b/frontend/farm_designer/map/layers/sensor_readings/__tests__/garden_sensor_reading_test.tsx @@ -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("", () => { const fakeProps = (): GardenSensorReadingProps => ({ @@ -23,7 +24,7 @@ describe("", () => { }); it("renders", () => { - const wrapper = mount(); + const wrapper = svgMount(); expect(wrapper.html()).toContain("sensor-reading-"); expect(wrapper.find("circle").length).toEqual(2); }); @@ -31,21 +32,21 @@ describe("", () => { it("doesn't render", () => { const p = fakeProps(); p.sensorReading.body.x = undefined; - const wrapper = mount(); + const wrapper = svgMount(); expect(wrapper.find("circle").length).toEqual(0); }); it("renders sensor name", () => { const p = fakeProps(); p.sensorLookup = { 1: "Sensor Name" }; - const wrapper = mount(); + const wrapper = svgMount(); expect(wrapper.text()).toContain("Sensor Name (pin 1)"); }); it("renders analog reading", () => { const p = fakeProps(); p.sensorReading.body.mode = 1; - const wrapper = mount(); + const wrapper = svgMount(); expect(wrapper.text()).toContain("value 0 (analog)"); }); diff --git a/frontend/farm_designer/map/layers/sensor_readings/__tests__/sensor_readings_layer_test.tsx b/frontend/farm_designer/map/layers/sensor_readings/__tests__/sensor_readings_layer_test.tsx index 17c9e33e1..f4fde4dee 100644 --- a/frontend/farm_designer/map/layers/sensor_readings/__tests__/sensor_readings_layer_test.tsx +++ b/frontend/farm_designer/map/layers/sensor_readings/__tests__/sensor_readings_layer_test.tsx @@ -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("", () => { const fakeProps = (): SensorReadingsLayerProps => ({ @@ -23,7 +23,7 @@ describe("", () => { }); it("renders", () => { - const wrapper = mount(); + const wrapper = svgMount(); expect(wrapper.html()).toContain("sensor-readings-layer"); }); }); diff --git a/frontend/farm_designer/map/layers/tool_slots/__tests__/tool_graphics_test.tsx b/frontend/farm_designer/map/layers/tool_slots/__tests__/tool_graphics_test.tsx index 30ce0ea92..fc7579cb9 100644 --- a/frontend/farm_designer/map/layers/tool_slots/__tests__/tool_graphics_test.tsx +++ b/frontend/farm_designer/map/layers/tool_slots/__tests__/tool_graphics_test.tsx @@ -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("", () => { - 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("", () => { p.pulloutDirection = direction; p.quadrant = quadrant; p.xySwap = xySwap; - const wrapper = mount(); + const wrapper = svgMount(); expect(wrapper.find("use").props().transform).toEqual(expected); }); }; @@ -59,27 +57,23 @@ describe("", () => { }); describe("", () => { - 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(); + const wrapper = svgMount(); wrapper.find("g").simulate("mouseOver"); expect(p.toolProps.setHoverState).toHaveBeenCalledWith(true); wrapper.find("g").simulate("mouseLeave"); @@ -87,7 +81,7 @@ describe("", () => { }; it("renders standard tool styling", () => { - const wrapper = mount(); + const wrapper = svgMount(); const props = wrapper.find("circle").last().props(); expect(props.r).toEqual(35); expect(props.cx).toEqual(10); @@ -98,7 +92,7 @@ describe("", () => { it("renders tool hover styling", () => { const p = fakeProps(); p.toolProps.hovered = true; - const wrapper = mount(); + const wrapper = svgMount(); const props = wrapper.find("circle").last().props(); expect(props.fill).toEqual(Color.darkGray); }); @@ -110,7 +104,7 @@ describe("", () => { it("renders special tool styling: bin", () => { const p = fakeProps(); p.tool = "seedBin"; - const wrapper = mount(); + const wrapper = svgMount(); 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("", () => { const p = fakeProps(); p.tool = "seedBin"; p.toolProps.hovered = true; - const wrapper = mount(); + const wrapper = svgMount(); p.toolProps.hovered = true; expect(wrapper.find("#seed-bin").find("circle").length).toEqual(3); }); @@ -132,7 +126,7 @@ describe("", () => { it("renders special tool styling: tray", () => { const p = fakeProps(); p.tool = "seedTray"; - const wrapper = mount(); + const wrapper = svgMount(); 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("", () => { const p = fakeProps(); p.tool = "seedTray"; p.toolProps.hovered = true; - const wrapper = mount(); + const wrapper = svgMount(); p.toolProps.hovered = true; expect(wrapper.find("#seed-tray").find("circle").length).toEqual(3); }); @@ -155,7 +149,7 @@ describe("", () => { it("renders special tool styling: trough", () => { const p = fakeProps(); p.tool = "seedTrough"; - const wrapper = mount(); + const wrapper = svgMount(); 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("", () => { const p = fakeProps(); p.tool = "seedTrough"; p.toolProps.hovered = true; - const wrapper = mount(); + const wrapper = svgMount(); p.toolProps.hovered = true; expect(wrapper.find("#seed-trough").find("circle").length).toEqual(0); expect(wrapper.find("#seed-trough").find("rect").length).toEqual(1); diff --git a/frontend/farm_designer/map/layers/tool_slots/__tests__/tool_slot_point_test.tsx b/frontend/farm_designer/map/layers/tool_slots/__tests__/tool_slot_point_test.tsx index e7ba938b8..b07a57af0 100644 --- a/frontend/farm_designer/map/layers/tool_slots/__tests__/tool_slot_point_test.tsx +++ b/frontend/farm_designer/map/layers/tool_slots/__tests__/tool_slot_point_test.tsx @@ -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("", () => { - 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("", () => { const p = fakeProps(); if (!tool) { p.slot.tool = undefined; } p.slot.toolSlot.body.pullout_direction = slot; - const wrapper = mount(); + const wrapper = svgMount(); expect(wrapper.find("circle").length).toEqual(tool); expect(wrapper.find("use").length).toEqual(slot); }); @@ -36,8 +34,8 @@ describe("", () => { it("displays tool name", () => { const p = fakeProps(); p.slot.toolSlot.body.pullout_direction = 2; - const wrapper = mount(); - wrapper.setState({ hovered: true }); + const wrapper = svgMount(); + 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("", () => { it("displays 'no tool'", () => { const p = fakeProps(); p.slot.tool = undefined; - const wrapper = mount(); - wrapper.setState({ hovered: true }); + const wrapper = svgMount(); + 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(); + const wrapper = svgMount(); 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(); + const wrapper = svgMount(); 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(); + const wrapper = svgMount(); expect(wrapper.find("#SeedTrayPattern").length).toEqual(1); }); @@ -75,14 +73,14 @@ describe("", () => { const p = fakeProps(); p.slot.toolSlot.body.gantry_mounted = true; if (p.slot.tool) { p.slot.tool.body.name = "seed trough"; } - const wrapper = mount(); + const wrapper = svgMount(); expect(wrapper.find("#seed-trough").length).toEqual(1); }); it("sets hover", () => { - const wrapper = mount(); - expect(wrapper.state().hovered).toBeFalsy(); - wrapper.instance().setHover(true); - expect(wrapper.state().hovered).toBeTruthy(); + const wrapper = svgMount(); + expect(wrapper.find(ToolSlotPoint).state().hovered).toBeFalsy(); + (wrapper.find(ToolSlotPoint).instance() as ToolSlotPoint).setHover(true); + expect(wrapper.find(ToolSlotPoint).state().hovered).toBeTruthy(); }); }); diff --git a/frontend/help/__tests__/tour_test.tsx b/frontend/help/__tests__/tour_test.tsx index 05988be11..9873ff556 100644 --- a/frontend/help/__tests__/tour_test.tsx +++ b/frontend/help/__tests__/tour_test.tsx @@ -22,6 +22,7 @@ describe("", () => { }); describe("", () => { + console.log = jest.fn(); const fakeCallbackData = (data: Partial): CallBackProps => ({ action: data.action || "start", index: data.index || 0, diff --git a/frontend/messages/__tests__/alerts_test.tsx b/frontend/messages/__tests__/alerts_test.tsx index 2afaa92f8..fcfb13494 100644 --- a/frontend/messages/__tests__/alerts_test.tsx +++ b/frontend/messages/__tests__/alerts_test.tsx @@ -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("", () => { @@ -85,8 +85,8 @@ describe("", () => { 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(); expect(wrapper.text()).toContain("1"); diff --git a/frontend/resources/__tests__/tagged_resource_test.ts b/frontend/resources/__tests__/tagged_resource_test.ts index 20f63c2ed..111b6b5d0 100644 --- a/frontend/resources/__tests__/tagged_resource_test.ts +++ b/frontend/resources/__tests__/tagged_resource_test.ts @@ -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("{}"); }); });