clean up test output

pull/1576/head
gabrielburnworth 2019-11-19 10:34:11 -08:00
parent 8f626c2833
commit 27214fa0a4
4 changed files with 33 additions and 22 deletions

View File

@ -1,10 +1,7 @@
jest.mock("../../../../../history", () => ({
history: { push: jest.fn() },
}));
jest.mock("../../../../../history", () => ({ history: { push: jest.fn() } }));
import * as React from "react";
import { GardenPoint } from "../garden_point";
import { shallow, mount } from "enzyme";
import { GardenPointProps } from "../../../interfaces";
import { fakePoint } from "../../../../../__test_support__/fake_state/resources";
import {
@ -12,6 +9,7 @@ import {
} from "../../../../../__test_support__/map_transform_props";
import { Actions } from "../../../../../constants";
import { history } from "../../../../../history";
import { svgMount } from "../../../../../__test_support__/svg_mount";
describe("<GardenPoint/>", () => {
const fakeProps = (): GardenPointProps => ({
@ -22,7 +20,7 @@ describe("<GardenPoint/>", () => {
});
it("renders point", () => {
const wrapper = shallow(<GardenPoint {...fakeProps()} />);
const wrapper = svgMount(<GardenPoint {...fakeProps()} />);
expect(wrapper.find("#point-radius").props().r).toEqual(100);
expect(wrapper.find("#point-center").props().r).toEqual(2);
expect(wrapper.find("#point-radius").props().fill).toEqual("transparent");
@ -30,7 +28,7 @@ describe("<GardenPoint/>", () => {
it("hovers point", () => {
const p = fakeProps();
const wrapper = shallow(<GardenPoint {...p} />);
const wrapper = svgMount(<GardenPoint {...p} />);
wrapper.find("g").simulate("mouseEnter");
expect(p.dispatch).toHaveBeenCalledWith({
type: Actions.TOGGLE_HOVERED_POINT,
@ -41,13 +39,13 @@ describe("<GardenPoint/>", () => {
it("is hovered", () => {
const p = fakeProps();
p.hovered = true;
const wrapper = mount(<GardenPoint {...p} />);
const wrapper = svgMount(<GardenPoint {...p} />);
expect(wrapper.find("#point-radius").props().fill).toEqual("green");
});
it("un-hovers point", () => {
const p = fakeProps();
const wrapper = shallow(<GardenPoint {...p} />);
const wrapper = svgMount(<GardenPoint {...p} />);
wrapper.find("g").simulate("mouseLeave");
expect(p.dispatch).toHaveBeenCalledWith({
type: Actions.TOGGLE_HOVERED_POINT,
@ -58,7 +56,7 @@ describe("<GardenPoint/>", () => {
it("opens point info", () => {
const p = fakeProps();
p.point.body.name = "weed";
const wrapper = shallow(<GardenPoint {...p} />);
const wrapper = svgMount(<GardenPoint {...p} />);
wrapper.find("g").simulate("click");
expect(history.push).toHaveBeenCalledWith(
`/app/designer/weeds/${p.point.body.id}`);

View File

@ -1,11 +1,11 @@
import * as React from "react";
import { PointLayer, PointLayerProps } from "../point_layer";
import { mount } from "enzyme";
import { fakePoint } from "../../../../../__test_support__/fake_state/resources";
import {
fakeMapTransformProps
} from "../../../../../__test_support__/map_transform_props";
import { GardenPoint } from "../garden_point";
import { svgMount } from "../../../../../__test_support__/svg_mount";
describe("<PointLayer/>", () => {
function fakeProps(): PointLayerProps {
@ -20,7 +20,7 @@ describe("<PointLayer/>", () => {
it("shows points", () => {
const p = fakeProps();
const wrapper = mount(<PointLayer {...p} />);
const wrapper = svgMount(<PointLayer {...p} />);
const layer = wrapper.find("#point-layer");
expect(layer.find(GardenPoint).html()).toContain("r=\"100\"");
});
@ -28,7 +28,7 @@ describe("<PointLayer/>", () => {
it("toggles visibility off", () => {
const p = fakeProps();
p.visible = false;
const wrapper = mount(<PointLayer {...p} />);
const wrapper = svgMount(<PointLayer {...p} />);
const layer = wrapper.find("#point-layer");
expect(layer.find(GardenPoint).length).toEqual(0);
});

View File

@ -1,7 +1,7 @@
jest.mock("../../../api/crud", () => ({ edit: jest.fn() }));
import * as React from "react";
import { mount, shallow } from "enzyme";
import { shallow } from "enzyme";
import { PathInfoBar, nn, NNPath, PathInfoBarProps } from "../paths";
import {
fakePlant, fakePointGroup
@ -12,6 +12,7 @@ import {
import { Actions } from "../../../constants";
import { edit } from "../../../api/crud";
import { error } from "../../../toast/toast";
import { svgMount } from "../../../__test_support__/svg_mount";
describe("<PathInfoBar />", () => {
const fakeProps = (): PathInfoBarProps => ({
@ -82,13 +83,13 @@ describe("<NNPath />", () => {
});
it("doesn't render optimized path", () => {
const wrapper = mount(<NNPath {...fakeProps()} />);
expect(wrapper.html()).toEqual("<g></g>");
const wrapper = svgMount(<NNPath {...fakeProps()} />);
expect(wrapper.html()).toEqual("<svg><g></g></svg>");
});
it("renders optimized path", () => {
localStorage.setItem("try_it", "ok");
const wrapper = mount(<NNPath {...fakeProps()} />);
expect(wrapper.html()).not.toEqual("<g></g>");
const wrapper = svgMount(<NNPath {...fakeProps()} />);
expect(wrapper.html()).not.toEqual("<svg><g></g></svg>");
});
});

View File

@ -10,6 +10,7 @@ const expectedVariable = (data_value: Point | Tool | Coordinate) =>
describe("convertDDItoDeclaration()", () => {
it("handles malformed items", () => {
console.error = jest.fn();
const result = convertDDItoVariable({
identifierLabel: "Y",
allowedVariableNodes,
@ -20,6 +21,8 @@ describe("convertDDItoDeclaration()", () => {
}
});
expect(result).toEqual(undefined);
expect(console.error).toHaveBeenCalledWith(
"WARNING: Don't know how to handle something_else");
});
it("handles point groups", () => {
@ -61,7 +64,9 @@ describe("convertDDItoDeclaration()", () => {
it("returns location data: tool", () => {
const dropdown = { headingId: "Tool", label: "Generic Tool", value: 1 };
const variable =
convertDDItoVariable({ identifierLabel: label, allowedVariableNodes, dropdown });
convertDDItoVariable({
identifierLabel: label, allowedVariableNodes, dropdown
});
expect(variable).toEqual(expectedVariable({
kind: "tool", args: { tool_id: 1 }
}));
@ -70,7 +75,9 @@ describe("convertDDItoDeclaration()", () => {
it("returns location data: Plant", () => {
const dropdown = { headingId: "Plant", label: "Mint", value: 1 };
const variable =
convertDDItoVariable({ identifierLabel: label, allowedVariableNodes, dropdown });
convertDDItoVariable({
identifierLabel: label, allowedVariableNodes, dropdown
});
expect(variable).toEqual(expectedVariable({
kind: "point", args: { pointer_id: 1, pointer_type: "Plant" }
}));
@ -89,7 +96,8 @@ describe("convertDDItoDeclaration()", () => {
const expected = expectedVariable(NOTHING_SELECTED);
expected.kind = "variable_declaration";
const variable = convertDDItoVariable({
identifierLabel: label, allowedVariableNodes: AllowedVariableNodes.parameter,
identifierLabel: label,
allowedVariableNodes: AllowedVariableNodes.parameter,
dropdown: NO_VALUE_SELECTED_DDI()
});
expect(variable).toEqual(expected);
@ -116,7 +124,9 @@ describe("convertDDItoDeclaration()", () => {
});
it("returns location data: parameter_declaration", () => {
const dropdown = ({ headingId: "parameter", label: "Parent0", value: "parent0" });
const dropdown = ({
headingId: "parameter", label: "Parent0", value: "parent0"
});
const variable = convertDDItoVariable({
identifierLabel: "parent",
allowedVariableNodes,
@ -132,7 +142,9 @@ describe("convertDDItoDeclaration()", () => {
});
it("returns location data: identifier", () => {
const dropdown = ({ headingId: "parameter", label: "Parent0", value: "parent0" });
const dropdown = ({
headingId: "parameter", label: "Parent0", value: "parent0"
});
const variable = convertDDItoVariable({
identifierLabel: "parent",
allowedVariableNodes: AllowedVariableNodes.identifier,