Skip to content

Commit

Permalink
chore: temp
Browse files Browse the repository at this point in the history
  • Loading branch information
mheggelund committed Mar 6, 2024
1 parent 28d1361 commit 6342752
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"axios": "^1.6.0",
"env-cmd": "^10.1.0",
"lodash": "^4.17.21",
"msal-react-tester": "^0.3.1",
"openapi-fetch": "^0.7.2",
"openapi-typescript-codegen": "^0.25.0",
"react": "^18.2.0",
Expand Down
44 changes: 43 additions & 1 deletion src/App.test.tsx
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();
});
*/
6 changes: 5 additions & 1 deletion src/components/AreaCoordinates/AreaCoordinates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,11 @@ export const AreaCoordinates = ({
</Button>
</>
) : (
<Button variant="outlined" onClick={handleEditChange}>
<Button
name="edit"
variant="outlined"
onClick={handleEditChange}
>
Edit coordinates
</Button>
)}
Expand Down
42 changes: 42 additions & 0 deletions src/components/AreaCoordinates/tests/AreaCoordinates.test.tsx
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()} />);
// });
94 changes: 94 additions & 0 deletions src/pages/Browse/Browse.test.tsx
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();
});

0 comments on commit 6342752

Please sign in to comment.