Update tests for create_points.tsx
parent
ee5efd02d0
commit
e0473eb795
|
@ -12,11 +12,41 @@ jest.mock("../../../farmware/weed_detector/actions", () => ({
|
|||
|
||||
import * as React from "react";
|
||||
import { mount, shallow } from "enzyme";
|
||||
import { CreatePoints, CreatePointsProps } from "../create_points";
|
||||
import {
|
||||
CreatePoints,
|
||||
CreatePointsProps,
|
||||
mapStateToProps
|
||||
} from "../create_points";
|
||||
import { initSave } from "../../../api/crud";
|
||||
import { deletePoints } from "../../../farmware/weed_detector/actions";
|
||||
import { Actions } from "../../../constants";
|
||||
import { clickButton } from "../../../__test_support__/helpers";
|
||||
import { fakeState } from "../../../__test_support__/fake_state";
|
||||
import { DeepPartial } from "redux";
|
||||
import { CurrentPointPayl } from "../../interfaces";
|
||||
|
||||
const FAKE_POINT: CurrentPointPayl =
|
||||
({ name: "My Point", cx: 13, cy: 22, r: 345, color: "red" });
|
||||
|
||||
describe("mapStateToProps", () => {
|
||||
it("maps state to props", () => {
|
||||
const state = fakeState();
|
||||
state
|
||||
.resources
|
||||
.consumers
|
||||
.farm_designer
|
||||
.currentPoint = FAKE_POINT;
|
||||
const result = mapStateToProps(state);
|
||||
const { currentPoint } = result;
|
||||
expect(currentPoint).toBeTruthy();
|
||||
if (currentPoint) {
|
||||
expect(currentPoint.cx).toEqual(13);
|
||||
expect(currentPoint.cy).toEqual(22);
|
||||
} else {
|
||||
fail("Nope");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("<CreatePoints />", () => {
|
||||
const fakeProps = (): CreatePointsProps => {
|
||||
|
@ -28,12 +58,49 @@ describe("<CreatePoints />", () => {
|
|||
};
|
||||
};
|
||||
|
||||
const fakeInstance = () => {
|
||||
const props = fakeProps();
|
||||
props.currentPoint = FAKE_POINT;
|
||||
return new CreatePoints(props);
|
||||
};
|
||||
|
||||
it("renders", () => {
|
||||
const wrapper = mount(<CreatePoints {...fakeProps()} />);
|
||||
["create point", "cancel", "delete", "x", "y", "radius", "color"]
|
||||
.map(string => expect(wrapper.text().toLowerCase()).toContain(string));
|
||||
});
|
||||
|
||||
it("updates specific fields", () => {
|
||||
const i = fakeInstance();
|
||||
const updater = i.updateValue("color");
|
||||
type Event = React.SyntheticEvent<HTMLInputElement>;
|
||||
const e: DeepPartial<Event> = {
|
||||
currentTarget: {
|
||||
value: "cheerful hue"
|
||||
}
|
||||
};
|
||||
updater(e as Event);
|
||||
expect(i.props.currentPoint).toBeTruthy();
|
||||
expect(i.props.dispatch).toHaveBeenCalledWith({
|
||||
payload: {
|
||||
color: "cheerful hue",
|
||||
cx: 13,
|
||||
cy: 22,
|
||||
name: "My Point",
|
||||
r: 345,
|
||||
},
|
||||
type: "SET_CURRENT_POINT_DATA",
|
||||
});
|
||||
});
|
||||
|
||||
it("updates current point", () => {
|
||||
const p = fakeInstance();
|
||||
p.updateCurrentPoint();
|
||||
expect(p.props.dispatch).toHaveBeenCalledWith({
|
||||
type: "SET_CURRENT_POINT_DATA",
|
||||
payload: { cx: 13, cy: 22, name: "My Point", r: 345, color: "red" },
|
||||
});
|
||||
});
|
||||
it("creates point", () => {
|
||||
const wrapper = mount(<CreatePoints {...fakeProps()} />);
|
||||
wrapper.setState({ cx: 10, cy: 20, r: 30, color: "red" });
|
||||
|
@ -95,26 +162,17 @@ describe("<CreatePoints />", () => {
|
|||
const p = fakeProps();
|
||||
p.currentPoint = { cx: 1, cy: 2, r: 3, color: "blue" };
|
||||
const wrapper = shallow<CreatePoints>(<CreatePoints {...p} />);
|
||||
wrapper.instance().getPointData();
|
||||
expect(wrapper.instance().state).toEqual({
|
||||
color: "blue", cx: 1, cy: 2, r: 3
|
||||
const i = wrapper.instance();
|
||||
expect(i.state).toEqual({});
|
||||
expect(i.getPointData()).toEqual({
|
||||
name: undefined,
|
||||
cx: 1,
|
||||
cy: 2,
|
||||
r: 3,
|
||||
color: "blue"
|
||||
});
|
||||
});
|
||||
|
||||
// Rewrite coming soon - RC
|
||||
// it("fills the state with default data", () => {
|
||||
// const wrapper = shallow<CreatePoints>(<CreatePoints {...fakeProps()} />);
|
||||
// wrapper.instance().getPointData();
|
||||
// const props = {
|
||||
// color: "green",
|
||||
// cx: 3.21,
|
||||
// cy: 1.23,
|
||||
// r: 15,
|
||||
// name: "Created Point"
|
||||
// };
|
||||
// expect(wrapper.instance().state).toEqual(props);
|
||||
// });
|
||||
|
||||
it("unmounts", () => {
|
||||
const p = fakeProps();
|
||||
const wrapper = shallow(<CreatePoints {...p} />);
|
||||
|
|
|
@ -88,7 +88,7 @@ export class CreatePoints
|
|||
this.setState({
|
||||
cx: undefined,
|
||||
cy: undefined,
|
||||
r: DEFAULTS.r,
|
||||
r: undefined,
|
||||
color: undefined
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue