close mobile nav menu upon page navigation
This commit is contained in:
parent
6bbf47b6f6
commit
ca24cb694e
26
webpack/farm_designer/__tests__/actions_test.ts
Normal file
26
webpack/farm_designer/__tests__/actions_test.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
jest.mock("../../api/crud", () => ({
|
||||
edit: jest.fn()
|
||||
}));
|
||||
|
||||
import { movePlant } from "../actions";
|
||||
import { MovePlantProps } from "../interfaces";
|
||||
import { fakePlant } from "../../__test_support__/fake_state/resources";
|
||||
import { edit } from "../../api/crud";
|
||||
|
||||
describe("movePlant", () => {
|
||||
it("updates plant", () => {
|
||||
const payload: MovePlantProps = {
|
||||
deltaX: 1,
|
||||
deltaY: 2,
|
||||
plant: fakePlant()
|
||||
};
|
||||
const { mock } = edit as jest.Mock<{}>;
|
||||
movePlant(payload);
|
||||
const oldPlant = mock.calls[0][0];
|
||||
expect(oldPlant.body.x).toBe(100);
|
||||
expect(oldPlant.body.y).toBe(200);
|
||||
const update = mock.calls[0][1];
|
||||
expect(update.x).toBe(101);
|
||||
expect(update.y).toBe(202);
|
||||
});
|
||||
});
|
12
webpack/nav/__tests__/nav_links_test.tsx
Normal file
12
webpack/nav/__tests__/nav_links_test.tsx
Normal file
|
@ -0,0 +1,12 @@
|
|||
import * as React from "react";
|
||||
import { shallow } from "enzyme";
|
||||
import { NavLinks } from "../nav_links";
|
||||
|
||||
describe("NavLinks", () => {
|
||||
it("toggles the mobile nav menu", () => {
|
||||
const toggle = jest.fn();
|
||||
const wrapper = shallow(<NavLinks toggle={(x) => () => toggle(x)} />);
|
||||
wrapper.find("Link").first().simulate("click");
|
||||
expect(toggle).toHaveBeenCalledWith("mobileMenuOpen");
|
||||
});
|
||||
});
|
|
@ -1,10 +1,7 @@
|
|||
import * as React from "react";
|
||||
import { Link } from "react-router";
|
||||
import * as _ from "lodash";
|
||||
|
||||
import { history } from "../history";
|
||||
import { NavLinksProps } from "./interfaces";
|
||||
import { isMobile } from "../util";
|
||||
|
||||
export const links = [
|
||||
{ name: "Farm Designer", icon: "leaf", slug: "designer" },
|
||||
|
@ -18,7 +15,6 @@ export const links = [
|
|||
|
||||
export const NavLinks = (props: NavLinksProps) => {
|
||||
const currPath = history.getCurrentLocation().pathname;
|
||||
const maybeToggle = () => isMobile() ? props.toggle("mobileMenuOpen") : _.noop;
|
||||
return (
|
||||
<div className="links">
|
||||
<div className="nav-links">
|
||||
|
@ -29,7 +25,7 @@ export const NavLinks = (props: NavLinksProps) => {
|
|||
to={"/app/" + link.slug}
|
||||
className={`${isActive}`}
|
||||
key={link.slug}
|
||||
onClick={maybeToggle()}>
|
||||
onClick={props.toggle("mobileMenuOpen")}>
|
||||
<i className={`fa fa-${link.icon}`} />
|
||||
{link.name}
|
||||
</Link>
|
||||
|
|
Loading…
Reference in a new issue