+
{MessageNotFound}
@@ -32,5 +32,3 @@ const NotFoundPage: FunctionComponent = () => {
);
};
-
-export default NotFoundPage;
diff --git a/starsky/starsky/clientapp/src/pages/preferences-page.tsx b/starsky/starsky/clientapp/src/pages/preferences-page.tsx
index 0997dccffc..27bd60c3f8 100644
--- a/starsky/starsky/clientapp/src/pages/preferences-page.tsx
+++ b/starsky/starsky/clientapp/src/pages/preferences-page.tsx
@@ -1,7 +1,7 @@
import { FunctionComponent } from "react";
-import Preferences from "../containers/preferences/preferences";
+import { Preferences } from "../containers/preferences/preferences";
-const PreferencesPage: FunctionComponent = () => {
+export const PreferencesPage: FunctionComponent = () => {
return
;
};
diff --git a/starsky/starsky/clientapp/src/pages/search-page.tsx b/starsky/starsky/clientapp/src/pages/search-page.tsx
index 53e6965470..20732d6cb9 100644
--- a/starsky/starsky/clientapp/src/pages/search-page.tsx
+++ b/starsky/starsky/clientapp/src/pages/search-page.tsx
@@ -7,7 +7,7 @@ import useSearchList from "../hooks/use-searchlist";
import { PageType } from "../interfaces/IDetailView";
import { URLPath } from "../shared/url-path";
-const SearchPage: FunctionComponent = () => {
+export const SearchPage: FunctionComponent = () => {
const history = useLocation();
const urlObject = new URLPath().StringToIUrl(history.location.search);
diff --git a/starsky/starsky/clientapp/src/pages/trash-page.tsx b/starsky/starsky/clientapp/src/pages/trash-page.tsx
index c29c6d5726..1d1de61665 100644
--- a/starsky/starsky/clientapp/src/pages/trash-page.tsx
+++ b/starsky/starsky/clientapp/src/pages/trash-page.tsx
@@ -7,7 +7,7 @@ import useSearchList from "../hooks/use-searchlist";
import { PageType } from "../interfaces/IDetailView";
import { URLPath } from "../shared/url-path";
-const TrashPage: FunctionComponent = () => {
+export const TrashPage: FunctionComponent = () => {
const history = useLocation();
const urlObject = new URLPath().StringToIUrl(history.location.search);
diff --git a/starsky/starsky/clientapp/src/router-app/router-app.spec.tsx b/starsky/starsky/clientapp/src/router-app/router-app.spec.tsx
index bfa0aa7527..0e2ecf70a1 100644
--- a/starsky/starsky/clientapp/src/router-app/router-app.spec.tsx
+++ b/starsky/starsky/clientapp/src/router-app/router-app.spec.tsx
@@ -1,83 +1,131 @@
import { render } from "@testing-library/react";
-import { RouterProvider, createMemoryRouter } from "react-router-dom";
-import * as ContentPage from "../pages/content-page";
-import * as ImportPage from "../pages/import-page";
-import * as LoginPage from "../pages/login-page";
+import * as Import from "../containers/import/import";
+import * as Login from "../containers/login";
+import * as MediaContent from "../containers/media-content";
+import * as Preferences from "../containers/preferences/preferences";
+import * as useSearchList from "../hooks/use-searchlist";
+import { ISearchList } from "../hooks/use-searchlist";
import * as NotFoundPage from "../pages/not-found-page";
import * as SearchPage from "../pages/search-page";
import * as TrashPage from "../pages/trash-page";
-import RouterApp, { RoutesConfig } from "./router-app";
+import RouterApp, { Router, RoutesConfig } from "./router-app";
+
describe("Router", () => {
it("default", () => {
- const contentPageSpy = jest
- .spyOn(ContentPage, "default")
- .mockImplementationOnce(() => {
- return <>>;
- });
+ const searchPagePageSpy = jest
+ .spyOn(MediaContent, "default")
+ .mockImplementationOnce(() => <>>);
- const memoryRouter = createMemoryRouter(RoutesConfig, {
- initialEntries: ["/"]
- });
+ const component = render(
);
- const component = render(
);
+ expect(
+ RoutesConfig.find((x) => x.path === "/")?.element
+ ).not.toBeUndefined();
- console.log(component.container.innerHTML);
+ expect(searchPagePageSpy).toBeCalled();
- expect(contentPageSpy).toBeCalled();
+ component.unmount();
});
- xit("search", () => {
- const searchPagePageSpy = jest
- .spyOn(SearchPage, "default")
+ it("search", () => {
+ jest.spyOn(SearchPage, "SearchPage").mockImplementationOnce(() => <>>);
+
+ const searchListMock = jest
+ .spyOn(useSearchList, "default")
.mockImplementationOnce(() => {
- return <>>;
+ return [{} as ISearchList, () => {}] as any;
});
- window.location.replace("/search?q=t");
- render(
);
- expect(searchPagePageSpy).toBeCalled();
+
+ Router.navigate("search?q=t");
+
+ const component = render(
);
+
+ expect(searchListMock).toBeCalled();
+ expect(searchListMock).toBeCalledWith(undefined, undefined, true);
+
+ component.unmount();
});
- xit("TrashPage", () => {
- const trashPagePageSpy = jest
- .spyOn(TrashPage, "default")
+ it("TrashPage", () => {
+ const searchListMock = jest
+ .spyOn(useSearchList, "default")
+ .mockReset()
.mockImplementationOnce(() => {
- return <>>;
+ return [{} as ISearchList, () => {}] as any;
});
- window.location.replace("/trash?q=t");
- render(
);
- expect(trashPagePageSpy).toBeCalled();
+
+ jest.spyOn(TrashPage, "TrashPage").mockImplementationOnce(() => {
+ return <>>;
+ });
+
+ Router.navigate("/trash?q=t");
+
+ const component = render(
);
+
+ expect(searchListMock).toBeCalled();
+ expect(searchListMock).toBeCalledWith("!delete!", undefined, true);
+
+ component.unmount();
});
- xit("ImportPage", () => {
+ it("ImportPage", () => {
const importPagePageSpy = jest
- .spyOn(ImportPage, "default")
+ .spyOn(Import, "Import")
.mockImplementationOnce(() => {
return <>>;
});
- window.location.replace("/import?q=t");
- render(
);
+
+ Router.navigate("/import");
+
+ const component = render(
);
+
expect(importPagePageSpy).toBeCalled();
+
+ component.unmount();
});
- xit("LoginPage", () => {
+ it("LoginPage", () => {
const loginPagePageSpy = jest
- .spyOn(LoginPage, "default")
- .mockImplementationOnce(() => {
- return <>>;
- });
- window.location.replace("/account/login");
- render(
);
+ .spyOn(Login, "Login")
+ .mockImplementationOnce(() => <>>);
+
+ Router.navigate("/account/login");
+
+ const component = render(
);
+
+ console.log(component.container.innerHTML);
+
expect(loginPagePageSpy).toBeCalled();
+
+ component.unmount();
});
- xit("NotFoundPage", () => {
- const notFoundPageSpy = jest
- .spyOn(NotFoundPage, "default")
+ it("PreferencesPage", () => {
+ const preferencesPagePageSpy = jest
+ .spyOn(Preferences, "Preferences")
.mockImplementationOnce(() => {
return <>>;
});
- window.location.replace("/not-found");
- render(
);
- expect(notFoundPageSpy).toBeCalled();
+
+ Router.navigate("/preferences");
+
+ const component = render(
);
+
+ expect(preferencesPagePageSpy).toBeCalled();
+
+ component.unmount();
+ });
+
+ it("NotFoundPage", () => {
+ jest
+ .spyOn(NotFoundPage, "NotFoundPage")
+ .mockImplementationOnce(() => <>>);
+
+ Router.navigate("/not-found");
+ const component = render(
);
+
+ expect(component.queryByTestId("not-found-page")).not.toBeNull();
+
+ component.unmount();
});
});
diff --git a/starsky/starsky/clientapp/src/router-app/router-app.tsx b/starsky/starsky/clientapp/src/router-app/router-app.tsx
index 087f25f06f..840c9724e2 100644
--- a/starsky/starsky/clientapp/src/router-app/router-app.tsx
+++ b/starsky/starsky/clientapp/src/router-app/router-app.tsx
@@ -1,13 +1,18 @@
-import { RouterProvider, createBrowserRouter } from "react-router-dom";
-import AccountRegisterPage from "../pages/account-register-page";
-import ContentPage from "../pages/content-page";
-import LoginPage from "../pages/login-page";
-import NotFoundPage from "../pages/not-found-page";
-import PreferencesPage from "../pages/preferences-page";
-import SearchPage from "../pages/search-page";
-import TrashPage from "../pages/trash-page";
+import {
+ RouteObject,
+ RouterProvider,
+ createBrowserRouter
+} from "react-router-dom";
+import { AccountRegisterPage } from "../pages/account-register-page";
+import { ContentPage } from "../pages/content-page";
+import ImportPage from "../pages/import-page";
+import { LoginPage } from "../pages/login-page";
+import { NotFoundPage } from "../pages/not-found-page";
+import { PreferencesPage } from "../pages/preferences-page";
+import { SearchPage } from "../pages/search-page";
+import { TrashPage } from "../pages/trash-page";
-export const RoutesConfig = [
+export const RoutesConfig: RouteObject[] = [
{
path: "/",
element:
,
@@ -18,15 +23,18 @@ export const RoutesConfig = [
{ path: "starsky/search", element:
},
{ path: "trash", element:
},
{ path: "starsky/trash", element:
},
+ { path: "import", element:
},
+ { path: "starsky/import", element:
},
{ path: "login", element:
},
{ path: "starsky/login", element:
},
+ { path: "account/login", element:
},
+ { path: "starsky/account/login", element:
},
{ path: "account/register", element:
},
{ path: "starsky/account/register", element:
},
{ path: "preferences", element:
},
{ path: "starsky/preferences", element:
},
{ path: "*", element:
}
];
-
export const Router = createBrowserRouter(RoutesConfig);
const RouterApp = () =>
;
diff --git a/starsky/starsky/clientapp/src/shared/select.spec.ts b/starsky/starsky/clientapp/src/shared/select.spec.ts
index 1a5ab6957f..52f692e90c 100644
--- a/starsky/starsky/clientapp/src/shared/select.spec.ts
+++ b/starsky/starsky/clientapp/src/shared/select.spec.ts
@@ -33,7 +33,7 @@ describe("select", () => {
});
select.removeSidebarSelection();
- expect(Router.state.location.search).toBe("");
+ expect(Router.state.location.search).toBe("?select=");
expect(setSelectSpy).toBeCalled();
expect(setSelectSpy).toBeCalledWith(["1", "2"]);
});
diff --git a/starsky/starsky/clientapp/src/shared/sidebar.spec.ts b/starsky/starsky/clientapp/src/shared/sidebar.spec.ts
index aa0841b218..76a82c1971 100644
--- a/starsky/starsky/clientapp/src/shared/sidebar.spec.ts
+++ b/starsky/starsky/clientapp/src/shared/sidebar.spec.ts
@@ -30,7 +30,7 @@ describe("sidebar", () => {
href: "",
...Router.state.location
},
- navigate: Router.navigate
+ navigate: navigateSpy
});
sidebar.toggleSidebar();