-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UISACQCOMP-171 Add unit test for hooks
- Loading branch information
1 parent
8cf9d92
commit e6563a8
Showing
6 changed files
with
168 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { QueryClient, QueryClientProvider } from 'react-query'; | ||
|
||
import { useOkapiKy } from '@folio/stripes/core'; | ||
|
||
import { campus } from '../../../test/jest/fixtures'; | ||
import { useCampuses } from './useCampuses'; | ||
|
||
const queryClient = new QueryClient(); | ||
const wrapper = ({ children }) => ( | ||
<QueryClientProvider client={queryClient}> | ||
{children} | ||
</QueryClientProvider> | ||
); | ||
|
||
describe('useCampuses', () => { | ||
beforeEach(() => { | ||
useOkapiKy.mockClear().mockReturnValue({ | ||
get: () => ({ | ||
json: () => Promise.resolve({ loccamps: [campus] }), | ||
}), | ||
}); | ||
}); | ||
|
||
it('should return list of campuses', async () => { | ||
const { result, waitFor } = renderHook(() => useCampuses(), { wrapper }); | ||
|
||
await waitFor(() => expect(result.current.isLoading).toBeFalsy()); | ||
|
||
expect(result.current.campuses).toEqual([campus]); | ||
}); | ||
}); |
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,32 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { QueryClient, QueryClientProvider } from 'react-query'; | ||
|
||
import { useOkapiKy } from '@folio/stripes/core'; | ||
|
||
import { institution } from '../../../test/jest/fixtures'; | ||
import { useInstitutions } from './useInstitutions'; | ||
|
||
const queryClient = new QueryClient(); | ||
const wrapper = ({ children }) => ( | ||
<QueryClientProvider client={queryClient}> | ||
{children} | ||
</QueryClientProvider> | ||
); | ||
|
||
describe('useInstitutions', () => { | ||
beforeEach(() => { | ||
useOkapiKy.mockClear().mockReturnValue({ | ||
get: () => ({ | ||
json: () => Promise.resolve({ locinsts: [institution] }), | ||
}), | ||
}); | ||
}); | ||
|
||
it('should return list of institutions', async () => { | ||
const { result, waitFor } = renderHook(() => useInstitutions(), { wrapper }); | ||
|
||
await waitFor(() => expect(result.current.isLoading).toBeFalsy()); | ||
|
||
expect(result.current.institutions).toEqual([institution]); | ||
}); | ||
}); |
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,32 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { QueryClient, QueryClientProvider } from 'react-query'; | ||
|
||
import { useOkapiKy } from '@folio/stripes/core'; | ||
|
||
import { library } from '../../../test/jest/fixtures'; | ||
import { useLibraries } from './useLibraries'; | ||
|
||
const queryClient = new QueryClient(); | ||
const wrapper = ({ children }) => ( | ||
<QueryClientProvider client={queryClient}> | ||
{children} | ||
</QueryClientProvider> | ||
); | ||
|
||
describe('useLibraries', () => { | ||
beforeEach(() => { | ||
useOkapiKy.mockClear().mockReturnValue({ | ||
get: () => ({ | ||
json: () => Promise.resolve({ loclibs: [library] }), | ||
}), | ||
}); | ||
}); | ||
|
||
it('should return list of libraries', async () => { | ||
const { result, waitFor } = renderHook(() => useLibraries(), { wrapper }); | ||
|
||
await waitFor(() => expect(result.current.isLoading).toBeFalsy()); | ||
|
||
expect(result.current.libraries).toEqual([library]); | ||
}); | ||
}); |
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,32 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { QueryClient, QueryClientProvider } from 'react-query'; | ||
|
||
import { useOkapiKy } from '@folio/stripes/core'; | ||
|
||
import { location } from '../../../test/jest/fixtures'; | ||
import { useLocations } from './useLocations'; | ||
|
||
const queryClient = new QueryClient(); | ||
const wrapper = ({ children }) => ( | ||
<QueryClientProvider client={queryClient}> | ||
{children} | ||
</QueryClientProvider> | ||
); | ||
|
||
describe('useLocations', () => { | ||
beforeEach(() => { | ||
useOkapiKy.mockClear().mockReturnValue({ | ||
get: () => ({ | ||
json: () => Promise.resolve({ locations: [location] }), | ||
}), | ||
}); | ||
}); | ||
|
||
it('should return list of locations', async () => { | ||
const { result, waitFor } = renderHook(() => useLocations(), { wrapper }); | ||
|
||
await waitFor(() => expect(result.current.isLoading).toBeFalsy()); | ||
|
||
expect(result.current.locations).toEqual([location]); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
export const institution = { | ||
id: '28a372df-a8c9-439e-91fd-6d606b52e1f4', | ||
name: 'Test institution', | ||
code: 'TS' | ||
}; | ||
|
||
export const campus = { | ||
id: '34790631-dd30-4ed0-b895-39125d866e44', | ||
name: 'Riverside Campus', | ||
code: 'RS', | ||
institutionId: [institution.id], | ||
}; | ||
|
||
export const library = { | ||
id: 'e81d1fc0-6801-4dec-b9b9-e105fa575cf0', | ||
name: 'Main Library', | ||
code: 'ML', | ||
campusId: [campus.id], | ||
}; | ||
|
||
export const location = { | ||
id: 'd9cd0bed-1b49-4b5e-a7bd-064b8d177231', | ||
name: 'Miller General Stacks', | ||
code: 'TS/RS/ML/GS', | ||
isActive: true, | ||
description: 'The very general stacks of Miller', | ||
discoveryDisplayName: 'Miller General', | ||
institutionId: [institution.id], | ||
campusId: [campus.id], | ||
libraryId: [library.id], | ||
details: { | ||
a: 'b', | ||
foo: 'bar' | ||
}, | ||
primaryServicePoint: '79faacf1-4ba4-42c7-8b2a-566b259e4641', | ||
servicePointIds: [ | ||
'79faacf1-4ba4-42c7-8b2a-566b259e4641', | ||
], | ||
}; |