Tests pass
parent
94ce6919c8
commit
17ea86a378
|
@ -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");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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("/");
|
||||
|
|
|
@ -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);
|
||||
}} />;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue