Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
updated MainPage and useInstitution tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-hellen committed May 1, 2024
1 parent da4d10a commit 5726993
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/hooks/useInstitutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ export const useInstitutions = () => {

return useQuery<Institution[]>(
["ui-training", "institutions"],
async () => ((await ky("location-units/institutions").json<InstitutionsResponse>())).locinsts,
async () => ((await ky.get("location-units/institutions").json<InstitutionsResponse>())).locinsts,
);
};
15 changes: 12 additions & 3 deletions src/views/MainPage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import { getByText, render, screen } from '@folio/jest-config-stripes/testing-library/react';
import { render, screen } from '@folio/jest-config-stripes/testing-library/react';
import { QueryClient, QueryClientProvider } from 'react-query';
import React from 'react';
import MainPage from './MainPage';
import userEvent from '@testing-library/user-event'
import withIntlConfiguration from '../test/util/withIntlConfiguration';

const queryClient = new QueryClient();

// Mock the QueryClientProvider to provide the QueryClient
jest.mock('react-query', () => ({
...jest.requireActual('react-query'),
useQueryClient: () => queryClient,
}));

describe('Main page', () => {
it('shows correct text', async () => {
render(withIntlConfiguration(<MainPage />));
render(withIntlConfiguration(<QueryClientProvider client={queryClient}> <MainPage /></QueryClientProvider>));

expect(screen.getByRole('heading', { name: 'Headline Open side panel' })).toBeVisible();

await userEvent.click(await screen.findByRole('button'));
await userEvent.click(await screen.findByText('Open side panel'));
expect(screen.getByText('Side panel')).toBeVisible();
});
});

0 comments on commit 5726993

Please sign in to comment.