mirror of
https://github.com/morpheus65535/bazarr
synced 2025-01-03 13:35:18 +00:00
no log: Refactor app structure
This commit is contained in:
parent
0b7a1a90a1
commit
75a7dc8cdf
4 changed files with 32 additions and 15 deletions
|
@ -1,13 +1,13 @@
|
||||||
import { render } from "@testing-library/react";
|
import { render } from "@/tests";
|
||||||
import { StrictMode } from "react";
|
import { StrictMode } from "react";
|
||||||
import { describe, it } from "vitest";
|
import { describe, it } from "vitest";
|
||||||
import { Main } from "../src/main";
|
import App from ".";
|
||||||
|
|
||||||
describe("App", () => {
|
describe("App", () => {
|
||||||
it("should render without crash", () => {
|
it("should render without crash", () => {
|
||||||
render(
|
render(
|
||||||
<StrictMode>
|
<StrictMode>
|
||||||
<Main />
|
<App />
|
||||||
</StrictMode>
|
</StrictMode>
|
||||||
);
|
);
|
||||||
});
|
});
|
|
@ -1,10 +1,20 @@
|
||||||
import { StrictMode } from "react";
|
import { StrictMode } from "react";
|
||||||
import ReactDOM from "react-dom";
|
import ReactDOM from "react-dom";
|
||||||
import { Main } from "./main";
|
import { useRoutes } from "react-router-dom";
|
||||||
|
import { AllProviders } from "./providers";
|
||||||
|
import { useRouteItems } from "./Router";
|
||||||
|
|
||||||
|
const RouteApp = () => {
|
||||||
|
const items = useRouteItems();
|
||||||
|
|
||||||
|
return useRoutes(items);
|
||||||
|
};
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<StrictMode>
|
<StrictMode>
|
||||||
<Main />
|
<AllProviders>
|
||||||
|
<RouteApp />
|
||||||
|
</AllProviders>
|
||||||
</StrictMode>,
|
</StrictMode>,
|
||||||
document.getElementById("root")
|
document.getElementById("root")
|
||||||
);
|
);
|
||||||
|
|
|
@ -3,19 +3,13 @@ import ThemeProvider from "@/App/theme";
|
||||||
import { ModalsProvider } from "@/modules/modals";
|
import { ModalsProvider } from "@/modules/modals";
|
||||||
import "@fontsource/roboto/300.css";
|
import "@fontsource/roboto/300.css";
|
||||||
import { NotificationsProvider } from "@mantine/notifications";
|
import { NotificationsProvider } from "@mantine/notifications";
|
||||||
|
import { FunctionComponent } from "react";
|
||||||
import { QueryClientProvider } from "react-query";
|
import { QueryClientProvider } from "react-query";
|
||||||
import { ReactQueryDevtools } from "react-query/devtools";
|
import { ReactQueryDevtools } from "react-query/devtools";
|
||||||
import { useRoutes } from "react-router-dom";
|
import { Router } from "./Router";
|
||||||
import { Router, useRouteItems } from "./Router";
|
|
||||||
import { Environment } from "./utilities";
|
import { Environment } from "./utilities";
|
||||||
|
|
||||||
const RouteApp = () => {
|
export const AllProviders: FunctionComponent = ({ children }) => {
|
||||||
const items = useRouteItems();
|
|
||||||
|
|
||||||
return useRoutes(items);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const Main = () => {
|
|
||||||
return (
|
return (
|
||||||
<QueryClientProvider client={queryClient}>
|
<QueryClientProvider client={queryClient}>
|
||||||
<ThemeProvider>
|
<ThemeProvider>
|
||||||
|
@ -25,7 +19,7 @@ export const Main = () => {
|
||||||
{Environment.queryDev && (
|
{Environment.queryDev && (
|
||||||
<ReactQueryDevtools initialIsOpen={false} />
|
<ReactQueryDevtools initialIsOpen={false} />
|
||||||
)}
|
)}
|
||||||
<RouteApp></RouteApp>
|
{children}
|
||||||
</Router>
|
</Router>
|
||||||
</NotificationsProvider>
|
</NotificationsProvider>
|
||||||
</ModalsProvider>
|
</ModalsProvider>
|
13
frontend/src/tests/index.tsx
Normal file
13
frontend/src/tests/index.tsx
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import { AllProviders } from "@/providers";
|
||||||
|
import { render, RenderOptions } from "@testing-library/react";
|
||||||
|
import { ReactElement } from "react";
|
||||||
|
|
||||||
|
const customRender = (
|
||||||
|
ui: ReactElement,
|
||||||
|
options?: Omit<RenderOptions, "wrapper">
|
||||||
|
) => render(ui, { wrapper: AllProviders, ...options });
|
||||||
|
|
||||||
|
// re-export everything
|
||||||
|
export * from "@testing-library/react";
|
||||||
|
// override render method
|
||||||
|
export { customRender as render };
|
Loading…
Reference in a new issue