-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
28d1361
commit 6342752
Showing
5 changed files
with
185 additions
and
2 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
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,6 +1,48 @@ | ||
import { render } from '@testing-library/react'; | ||
import { cleanup, render, screen } from '@testing-library/react'; | ||
import { MsalReactTester } from 'msal-react-tester'; | ||
import { App } from './App'; | ||
|
||
let msalTester: MsalReactTester; | ||
beforeEach(() => { | ||
// new instance of msal tester for each test | ||
msalTester = new MsalReactTester(); | ||
|
||
// spy all required msal things | ||
msalTester.spyMsal(); | ||
}); | ||
|
||
afterEach(() => { | ||
cleanup(); | ||
msalTester.resetSpyMsal(); | ||
}); | ||
|
||
test('renders without crashing', () => { | ||
render(<App />); | ||
}); | ||
|
||
test('renders what we want', () => { | ||
render(<App />); | ||
|
||
expect(screen.getByText(/You are not authorized/i)).toBeInTheDocument(); | ||
}); | ||
|
||
/** | ||
* | ||
test('renders what we want when logged in', async () => { | ||
msalTester.isLogged(); | ||
render( | ||
<MsalProvider instance={msalTester.client}> | ||
<QueryClientProvider client={queryClient}> | ||
<App /> | ||
</QueryClientProvider> | ||
</MsalProvider>, | ||
); | ||
await msalTester.waitForRedirect(); | ||
expect( | ||
screen.getByRole('h1', { name: /Browse all models/i }), | ||
).toBeInTheDocument(); | ||
}); | ||
*/ |
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
42 changes: 42 additions & 0 deletions
42
src/components/AreaCoordinates/tests/AreaCoordinates.test.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,42 @@ | ||
import { cleanup } from '@testing-library/react'; | ||
|
||
// const mocArea: ListModelAreaTypesQueryResponse = { | ||
// success: true, | ||
// count: 1, | ||
// data: [{ modelAreaTypeId: '111', name: 'mocArea', description: 'Test' }], | ||
// }; | ||
|
||
// jest.mock('model-area', () => ({ | ||
// useQuery: jest | ||
// .fn() | ||
// .mockReturnValue({ data: { ...mocArea }, isLoading: false, error: {} }), | ||
// })); | ||
|
||
afterEach(() => cleanup()); | ||
|
||
// const wrapper = ({ children }: { children: any }) => ( | ||
// <MsalProvider instance={msalInstance}> | ||
// <QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
// </MsalProvider> | ||
// ); | ||
|
||
test('on render, area select is present.', () => { | ||
// render( | ||
// <MsalProvider instance={msalInstance}> | ||
// <QueryClientProvider client={queryClient}> | ||
// <AreaCoordinates setSaveAlert={jest.fn()} /> | ||
// </QueryClientProvider> | ||
// </MsalProvider>, | ||
// ); | ||
// Wait for the authentication redirect to resolve | ||
// const { result } = renderHook(() => useFetchModelAreas(), { | ||
// wrapper, | ||
// }); | ||
// await waitFor(() => expect(result.current.isSuccess).toBe(true)); | ||
// const editButton = screen.getByRole('button', { name: /edit/i }); | ||
// expect(editButton).toBeEnabled(); | ||
}); | ||
|
||
// test('Should render a button', async () => { | ||
// render(<AreaCoordinates setSaveAlert={jest.fn()} />); | ||
// }); |
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,94 @@ | ||
/* | ||
import { MsalProvider } from '@azure/msal-react'; | ||
import { QueryClientProvider } from '@tanstack/react-query'; | ||
import { cleanup, render, screen } from '@testing-library/react'; | ||
import { MsalReactTester } from 'msal-react-tester'; | ||
import { PropsWithChildren } from 'react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { queryClient } from '../../auth/queryClient'; | ||
import { Browse } from './Browse'; | ||
let msalTester: MsalReactTester; | ||
beforeEach(() => { | ||
// new instance of msal tester for each test | ||
msalTester = new MsalReactTester(); | ||
// spy all required msal things | ||
msalTester.spyMsal(); | ||
}); | ||
afterEach(() => { | ||
cleanup(); | ||
msalTester.resetSpyMsal(); | ||
}); | ||
// function setup() { | ||
// const utils = render( | ||
// <MsalProvider instance={msalInstance}> | ||
// <QueryClientProvider client={queryClient}> | ||
// <Browse /> | ||
// </QueryClientProvider> | ||
// </MsalProvider>, | ||
// { wrapper: BrowserRouter }, | ||
// ); | ||
// const add = screen.getByRole('button'); | ||
// const clickAdd = () => fireEvent.click(add); | ||
// return { ...utils, add, clickAdd }; | ||
// } | ||
jest.mock('../../pages/Browse/Browse', () => ({ | ||
__esModule: true, | ||
HomePage: () => <div data-testid="HomePageMock" />, | ||
})); | ||
function wrapper({ children }: PropsWithChildren<unknown>) { | ||
const setRoute = '/'; | ||
return ( | ||
<MsalProvider instance={msalTester.client}> | ||
<QueryClientProvider client={queryClient}> | ||
<MemoryRouter initialEntries={[setRoute]}>{children}</MemoryRouter> | ||
</QueryClientProvider> | ||
</MsalProvider> | ||
); | ||
} | ||
test('should render main page', async () => { | ||
msalTester.isLogged(); | ||
render(<Browse></Browse>, { wrapper }); | ||
await msalTester.waitForRedirect(); | ||
expect( | ||
screen.getByRole('h1', { name: /Browse all models/i }), | ||
).toBeInTheDocument(); | ||
}); | ||
*/ | ||
|
||
// Er her for at fila skal kunne committes, bare fjern sammen med det utkommenterte over | ||
import { cleanup, render, screen } from '@testing-library/react'; | ||
import { MsalReactTester } from 'msal-react-tester'; | ||
import { App } from '../../App'; | ||
|
||
let msalTester: MsalReactTester; | ||
beforeEach(() => { | ||
// new instance of msal tester for each test | ||
msalTester = new MsalReactTester(); | ||
|
||
// spy all required msal things | ||
msalTester.spyMsal(); | ||
}); | ||
|
||
afterEach(() => { | ||
cleanup(); | ||
msalTester.resetSpyMsal(); | ||
}); | ||
|
||
test('renders what we want', () => { | ||
render(<App />); | ||
|
||
expect(screen.getByText(/You are not authorized/i)).toBeInTheDocument(); | ||
}); |