Use another defaultProps method for NavButton

Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
This commit is contained in:
Mcat12
2019-06-17 16:52:07 -07:00
parent 87ad853e3d
commit e692d271b7
3 changed files with 26 additions and 13 deletions
+8 -2
View File
@@ -15,10 +15,10 @@ import React, { MouseEventHandler } from "react";
export interface NavButtonProps {
name: string;
icon: string;
onClick?: MouseEventHandler;
onClick: MouseEventHandler;
}
export default ({ name, icon, onClick = () => {} }: NavButtonProps) => (
const NavButton = ({ name, icon, onClick }: NavButtonProps) => (
<li className="nav-item">
<a
href="#"
@@ -33,3 +33,9 @@ export default ({ name, icon, onClick = () => {} }: NavButtonProps) => (
</a>
</li>
);
NavButton.defaultProps = {
onClick: () => {}
};
export default NavButton;
@@ -84,7 +84,8 @@ describe("EnableDisable", () => {
wrapper
.find(NavButton)
.at(buttonIndex)
.props().onClick!({} as MouseEvent);
.props()
.onClick({} as MouseEvent);
// Wait for the setStatus promise to resolve
await tick();
@@ -128,7 +129,10 @@ describe("EnableDisable", () => {
wrapper.setState({ processing: true });
wrapper.find(NavButton).props().onClick!({} as MouseEvent);
wrapper
.find(NavButton)
.props()
.onClick({} as MouseEvent);
expect(setStatus).not.toHaveBeenCalled();
});
@@ -147,7 +151,10 @@ describe("EnableDisable", () => {
/>
);
wrapper.find(NavButton).props().onClick!({} as MouseEvent);
wrapper
.find(NavButton)
.props()
.onClick({} as MouseEvent);
wrapper.unmount();
@@ -168,7 +175,10 @@ describe("EnableDisable", () => {
/>
);
wrapper.find(NavButton).props().onClick!({} as MouseEvent);
wrapper
.find(NavButton)
.props()
.onClick({} as MouseEvent);
expect(wrapper.state().processing).toBeTruthy();
@@ -216,7 +226,8 @@ describe("EnableDisable", () => {
wrapper
.find(NavButton)
.last()
.props().onClick!({} as MouseEvent);
.props()
.onClick({} as MouseEvent);
expect(wrapper.find(Modal).props().isOpen).toBeTruthy();
});
@@ -8,7 +8,7 @@
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
import React from "react";
import React, { MouseEvent } from "react";
import { shallow } from "enzyme";
import Sidebar, { NavList, PiholeNavDropdown, PiholeNavItem } from "../Sidebar";
import api from "../../../util/api";
@@ -207,11 +207,7 @@ it("should hide the sidebar on mobile when an item is clicked", () => {
document.body.classList.add("sidebar-show");
expect(document.body.classList).toContain("sidebar-show");
// @ts-ignore
wrapper
.find(NavLink)
.props()
.onClick();
wrapper.find(NavLink).props().onClick!({} as MouseEvent<HTMLAnchorElement>);
expect(document.body.classList).not.toContain("sidebar-show");
});