-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add msw and refactor test for more future proof setup
- Loading branch information
Showing
8 changed files
with
76 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { render } from '@testing-library/react'; | ||
import App from './App.tsx'; | ||
import { beforeAll, describe, expect, it } from "vitest"; | ||
import { customRender } from "../utils/test-utils.tsx"; | ||
import App from "./App.tsx"; | ||
import { server } from "./mocks/node.ts"; | ||
|
||
describe('App Smoke Test', () => { | ||
it('renders without crashing', () => { | ||
const { getByTestId } = render(<App />); | ||
const appElement = getByTestId('app'); | ||
describe("App Smoke Test", async () => { | ||
beforeAll(async () => { | ||
server.listen(); | ||
}); | ||
|
||
it("renders without crashing", () => { | ||
const { getByRole } = customRender(<App />); | ||
const appElement = getByRole("main"); | ||
expect(appElement).toBeTruthy(); | ||
}); | ||
}); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { setupServer } from 'msw/node' | ||
import { handlers } from './handlers' | ||
|
||
export const server = setupServer(...handlers) |
26 changes: 26 additions & 0 deletions
26
packages/frontend-design-poc/src/pages/PageLayout/PageLayout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { HeaderContext } from 'app-shared/navigation/main-header/Header'; | ||
import { Outlet } from 'react-router-dom'; | ||
import { useUserQuery } from 'app-shared/hooks/queries'; | ||
import React, { useMemo } from 'react'; | ||
import type { IHeaderContext } from 'app-shared/navigation/main-header/Header'; | ||
import AppHeader from 'app-shared/navigation/main-header/Header'; | ||
|
||
export const PageLayout = () => { | ||
const { data: user } = useUserQuery(); | ||
|
||
const headerContextValue: IHeaderContext = useMemo( | ||
() => ({ | ||
user, | ||
}), | ||
[user], | ||
); | ||
|
||
return ( | ||
<> | ||
<HeaderContext.Provider value={headerContextValue}> | ||
<AppHeader showMenu={false} /> | ||
</HeaderContext.Provider> | ||
<Outlet /> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { PageLayout } from './PageLayout'; |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { QueryClient, QueryClientProvider } from "react-query"; | ||
import { ReactElement } from "react"; | ||
import { MemoryRouter } from "react-router-dom"; | ||
import { render, RenderOptions } from "@testing-library/react"; | ||
|
||
interface IExtendedRenderOptions extends RenderOptions { | ||
initialEntries?: string[]; | ||
} | ||
|
||
const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
retry: false, | ||
}, | ||
}, | ||
}); | ||
|
||
export const customRender = ( | ||
ui: ReactElement, | ||
options?: Omit<IExtendedRenderOptions, "wrapper">, | ||
) => { | ||
const Wrapper = ({ children }: { children: React.ReactNode }) => { | ||
return ( | ||
<QueryClientProvider client={queryClient}> | ||
<MemoryRouter initialEntries={options?.initialEntries ?? ["/"]}> | ||
{children} | ||
</MemoryRouter> | ||
</QueryClientProvider> | ||
); | ||
}; | ||
|
||
return render(ui, { wrapper: Wrapper, ...options }); | ||
}; |