plant deselection improvements
parent
886a5a1bf4
commit
db6ed1c498
|
@ -4,18 +4,17 @@ jest.mock("../../../history", () => ({
|
|||
push: mockHistory,
|
||||
getCurrentLocation: jest.fn()
|
||||
.mockImplementationOnce(() => {
|
||||
return { pathname: "/app/designer/plants" }
|
||||
return { pathname: "/app/designer/plants" };
|
||||
})
|
||||
.mockImplementationOnce(() => {
|
||||
return { pathname: "/app/designer/plants/1/edit" }
|
||||
return { pathname: "/app/designer/plants/1/edit" };
|
||||
})
|
||||
.mockImplementationOnce(() => {
|
||||
return { pathname: "/app/designer/plants/1" }
|
||||
return { pathname: "/app/designer/plants/1" };
|
||||
})
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
import * as React from "react";
|
||||
import { Grid } from "../grid";
|
||||
import { shallow } from "enzyme";
|
||||
|
@ -48,13 +47,13 @@ describe("<Grid/>", () => {
|
|||
const p = fakeProps();
|
||||
const wrapper = shallow(<Grid {...p } />);
|
||||
const gridArea = wrapper.find("g").first();
|
||||
gridArea.simulate("click") // no plant info open
|
||||
gridArea.simulate("click"); // no plant info open
|
||||
expect(mockHistory).not.toHaveBeenCalled();
|
||||
expect(p.dispatch).not.toHaveBeenCalled();
|
||||
gridArea.simulate("click") // plant edit open
|
||||
gridArea.simulate("click"); // plant edit open
|
||||
expect(mockHistory).not.toHaveBeenCalled();
|
||||
expect(p.dispatch).not.toHaveBeenCalled();
|
||||
gridArea.simulate("click") // plant info open
|
||||
gridArea.simulate("click"); // plant info open
|
||||
expect(mockHistory).toHaveBeenCalledWith("/app/designer/plants");
|
||||
expect(p.dispatch).toHaveBeenCalledWith({
|
||||
payload: undefined, type: "SELECT_PLANT"
|
||||
|
|
|
@ -10,7 +10,13 @@ export function Grid(props: GridProps) {
|
|||
if (!isNaN(parseInt(currentPath.split("/").slice(-1)[0]))) {
|
||||
// A plant is selected and plant info is open. Unselect and close it.
|
||||
props.dispatch({ type: "SELECT_PLANT", payload: undefined });
|
||||
history.push("/app/designer/plants")
|
||||
props.dispatch({
|
||||
type: "TOGGLE_HOVERED_PLANT", payload: {
|
||||
icon: undefined,
|
||||
plantUUID: undefined
|
||||
}
|
||||
});
|
||||
history.push("/app/designer/plants");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -56,11 +56,8 @@ describe("<ToolSlotLayer/>", () => {
|
|||
const p = fakeProps();
|
||||
const wrapper = shallow(<ToolSlotLayer {...p } />);
|
||||
const tools = wrapper.find("g").first();
|
||||
await tools.simulate("click")
|
||||
await tools.simulate("click");
|
||||
expect(mockHistory).toHaveBeenCalledWith("/app/tools");
|
||||
expect(p.dispatch).toHaveBeenCalledWith({
|
||||
payload: undefined, type: "SELECT_PLANT"
|
||||
});
|
||||
});
|
||||
|
||||
it("doesn't navigate to tools page", async () => {
|
||||
|
@ -70,7 +67,7 @@ describe("<ToolSlotLayer/>", () => {
|
|||
const p = fakeProps();
|
||||
const wrapper = shallow(<ToolSlotLayer {...p } />);
|
||||
const tools = wrapper.find("g").first();
|
||||
await tools.simulate("click")
|
||||
await tools.simulate("click");
|
||||
expect(mockHistory).not.toHaveBeenCalled();
|
||||
expect(p.dispatch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
|
|
@ -16,8 +16,7 @@ export function ToolSlotLayer(props: ToolSlotLayerProps) {
|
|||
const canClickTool = !(pathArray[3] === "plants" && pathArray.length > 4);
|
||||
function goToToolsPage() {
|
||||
if (canClickTool) {
|
||||
props.dispatch({ type: "SELECT_PLANT", payload: undefined });
|
||||
return Promise.resolve().then(() => history.push("/app/tools"))
|
||||
history.push("/app/tools");
|
||||
}
|
||||
}
|
||||
const { slots, visible, mapTransformProps } = props;
|
||||
|
|
|
@ -37,7 +37,7 @@ describe("<PlantInventoryItem />", () => {
|
|||
wrapper.simulate("mouseLeave");
|
||||
expect(dispatch).toBeCalledWith({
|
||||
payload: {
|
||||
icon: undefined,
|
||||
icon: "",
|
||||
plantUUID: undefined
|
||||
},
|
||||
type: "TOGGLE_HOVERED_PLANT"
|
||||
|
|
|
@ -15,7 +15,7 @@ export class PlantInfo extends PlantInfoBase {
|
|||
this.props.dispatch({ type: "SELECT_PLANT", payload: undefined });
|
||||
this.props.dispatch({
|
||||
type: "TOGGLE_HOVERED_PLANT", payload: {
|
||||
plantUUID: undefined, icon: undefined
|
||||
plantUUID: undefined, icon: ""
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -40,7 +40,7 @@ export class PlantInventoryItem extends
|
|||
case "leave":
|
||||
dispatch({
|
||||
type: "TOGGLE_HOVERED_PLANT", payload: {
|
||||
plantUUID: undefined, icon: undefined
|
||||
plantUUID: undefined, icon: ""
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
|
|
@ -39,5 +39,6 @@ export let designer = generateReducer<DesignerState>(initialState)
|
|||
})
|
||||
.add<TaggedResource>(Actions.DESTROY_RESOURCE_OK, (s, { payload }) => {
|
||||
s.selectedPlants = undefined;
|
||||
s.hoveredPlant = { plantUUID: undefined, icon: "" };
|
||||
return s;
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue