Farmbot-Web-App/frontend/farm_designer/weeds/__tests__/weeds_edit_test.tsx

66 lines
1.9 KiB
TypeScript
Raw Normal View History

2019-10-23 14:08:38 -06:00
let mockPath = "/app/designer/weeds/1";
jest.mock("../../../history", () => ({
getPathArray: jest.fn(() => mockPath.split("/")),
history: { push: jest.fn() }
}));
import * as React from "react";
2019-11-20 12:48:55 -07:00
import { mount, shallow } from "enzyme";
2019-10-23 14:08:38 -06:00
import {
2020-02-28 09:35:32 -07:00
RawEditWeed as EditWeed, EditWeedProps, mapStateToProps,
2019-10-23 14:08:38 -06:00
} from "../weeds_edit";
import { fakeWeed } from "../../../__test_support__/fake_state/resources";
2019-10-23 14:08:38 -06:00
import { fakeState } from "../../../__test_support__/fake_state";
import {
2020-02-28 09:35:32 -07:00
buildResourceIndex,
2019-10-23 14:08:38 -06:00
} from "../../../__test_support__/resource_index_builder";
2019-11-20 12:48:55 -07:00
import { Actions } from "../../../constants";
2019-12-10 13:09:52 -07:00
import { DesignerPanelHeader } from "../../designer_panel";
2019-10-23 14:08:38 -06:00
describe("<EditWeed />", () => {
const fakeProps = (): EditWeedProps => ({
dispatch: jest.fn(),
findPoint: () => undefined,
});
it("redirects", () => {
mockPath = "/app/designer/weeds";
const wrapper = mount(<EditWeed {...fakeProps()} />);
expect(wrapper.text()).toContain("Redirecting...");
});
it("renders", () => {
mockPath = "/app/designer/weeds/1";
const p = fakeProps();
const weed = fakeWeed();
weed.body.id = 1;
p.findPoint = () => weed;
2019-10-23 14:08:38 -06:00
const wrapper = mount(<EditWeed {...p} />);
expect(wrapper.text().toLowerCase()).toContain("edit");
});
2019-11-20 12:48:55 -07:00
it("goes back", () => {
mockPath = "/app/designer/weeds/1";
const p = fakeProps();
const weed = fakeWeed();
weed.body.id = 1;
p.findPoint = () => weed;
2019-11-20 12:48:55 -07:00
const wrapper = shallow(<EditWeed {...p} />);
wrapper.find(DesignerPanelHeader).simulate("back");
expect(p.dispatch).toHaveBeenCalledWith({
type: Actions.TOGGLE_HOVERED_POINT, payload: undefined
});
});
2019-10-23 14:08:38 -06:00
});
describe("mapStateToProps()", () => {
it("returns props", () => {
const state = fakeState();
const weed = fakeWeed();
weed.body.id = 1;
state.resources = buildResourceIndex([weed]);
2019-10-23 14:08:38 -06:00
const props = mapStateToProps(state);
expect(props.findPoint(1)).toEqual(weed);
2019-10-23 14:08:38 -06:00
});
});