Tests pass

pull/991/head
Rick Carlino 2018-09-17 10:55:18 -05:00
parent 94ce6919c8
commit 17ea86a378
3 changed files with 21 additions and 17 deletions

View File

@ -1,12 +1,10 @@
import { history, push } from "../history";
jest.mock("takeme", () => ({ navigate: jest.fn() }));
import { navigate } from "takeme";
import { push } from "../history";
describe("push()", () => {
it("calls history with a URL", () => {
const URL = "/wow.html";
const oldFn = history.push;
history.push = jest.fn();
push(URL);
expect(history.push).toHaveBeenCalledWith(URL);
history.push = oldFn;
push("/app/wow.html");
expect(navigate).toHaveBeenCalledWith("/wow.html");
});
});

View File

@ -2,6 +2,7 @@ import { navigate } from "takeme";
import { maybeStripLegacyUrl } from "./link";
export const push = (url: string) => {
debugger;
navigate(maybeStripLegacyUrl(url));
};
export const getPathArray = () => location.pathname.split("/");

View File

@ -11,13 +11,18 @@ interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
export const maybeStripLegacyUrl =
(url: string) => url.startsWith("/app") ? url.replace("/app", "") : url;
export const Link: React.SFC<LinkProps> = (props) => <a
{...props}
href={props.to}
onClick={(e: React.MouseEvent<HTMLAnchorElement>) => {
e.preventDefault();
/** BEGIN LEGACY SHIMS */
const { onClick, to } = props;
navigate(maybeStripLegacyUrl(to));
onClick && onClick(e);
}} />;
export class Link extends React.Component<LinkProps, {}> {
render() {
const { props } = this;
return <a
{...props}
href={props.to}
onClick={(e: React.MouseEvent<HTMLAnchorElement>) => {
e.preventDefault();
/** BEGIN LEGACY SHIMS */
const { onClick, to } = props;
navigate(maybeStripLegacyUrl(to));
onClick && onClick(e);
}} />;
}
}