-
Notifications
You must be signed in to change notification settings - Fork 19
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
ffc6416
commit adbf3c4
Showing
2 changed files
with
208 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,168 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { Provider } from 'react-redux'; | ||
import { store } from '../app/store'; | ||
import { | ||
useGetAggregationsQuery, | ||
useGetDocumentQuery, | ||
useGetListQuery, | ||
useGetMapQuery, | ||
useGetTrendsQuery, | ||
} from './complaints'; | ||
import { aggResponse } from '../components/List/ListPanel/fixture'; | ||
import fetchMock from 'jest-fetch-mock'; | ||
import { waitFor } from '@testing-library/react'; | ||
import { aggResponseTransformed, documentResponse } from './fixture'; | ||
|
||
fetchMock.enableMocks(); | ||
|
||
/** | ||
Check warning on line 18 in src/api/complaints.spec.js GitHub Actions / frontend
|
||
* | ||
* @param root0 | ||
Check warning on line 20 in src/api/complaints.spec.js GitHub Actions / frontend
Check warning on line 20 in src/api/complaints.spec.js GitHub Actions / frontend
|
||
* @param root0.children | ||
Check warning on line 21 in src/api/complaints.spec.js GitHub Actions / frontend
Check warning on line 21 in src/api/complaints.spec.js GitHub Actions / frontend
|
||
*/ | ||
// eslint-disable-next-line react/prop-types | ||
function Wrapper({ children }) { | ||
return <Provider store={store}>{children}</Provider>; | ||
} | ||
|
||
beforeEach(() => { | ||
fetchMock.resetMocks(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
describe('getAggregations', () => { | ||
it('renders hook and transforms data', async () => { | ||
fetchMock.mockResponseOnce(JSON.stringify(aggResponse)); | ||
const { result } = renderHook( | ||
() => useGetAggregationsQuery({ foo: 'bar' }), | ||
{ | ||
wrapper: Wrapper, | ||
}, | ||
); | ||
expect(result.current).toMatchObject({ | ||
status: 'pending', | ||
endpointName: 'getAggregations', | ||
isLoading: true, | ||
isSuccess: false, | ||
isError: false, | ||
isFetching: true, | ||
}); | ||
|
||
await waitFor(() => expect(result.current.isSuccess).toBe(true)); | ||
|
||
expect(fetchMock).toBeCalledTimes(1); | ||
expect(result.current.data).toEqual(aggResponseTransformed); | ||
}); | ||
}); | ||
|
||
describe('getDocument', () => { | ||
it('renders hook transforms data', async () => { | ||
fetchMock.mockResponseOnce(JSON.stringify(documentResponse)); | ||
const { result } = renderHook(() => useGetDocumentQuery(12334), { | ||
wrapper: Wrapper, | ||
}); | ||
expect(result.current).toMatchObject({ | ||
status: 'pending', | ||
endpointName: 'getDocument', | ||
isLoading: true, | ||
isSuccess: false, | ||
isError: false, | ||
isFetching: true, | ||
}); | ||
|
||
await waitFor(() => expect(result.current.isSuccess).toBe(true)); | ||
|
||
expect(fetchMock).toBeCalledTimes(1); | ||
expect(result.current.data).toEqual({ | ||
company: 'JPMORGAN CHASE & CO.', | ||
company_public_response: 'Company acknowledges the complaint', | ||
company_response: 'Closed with explanation', | ||
complaint_id: '2371744', | ||
complaint_what_happened: 'Lorem ipsum dolor sit amet', | ||
consumer_consent_provided: 'Consent provided', | ||
consumer_disputed: 'Yes', | ||
date_received: '2017-03-04T12:00:00', | ||
date_sent_to_company: '2017-03-04T12:00:00', | ||
has_narrative: true, | ||
issue: 'Account opening, closing, or management', | ||
product: 'Bank account or service', | ||
state: 'KY', | ||
sub_issue: 'Closing', | ||
sub_product: 'Checking account', | ||
submitted_via: 'Web', | ||
tags: 'Older American', | ||
timely: 'Yes', | ||
zip_code: '423XX', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('getList', () => { | ||
it('renders hook', async () => { | ||
fetchMock.mockResponseOnce(JSON.stringify(aggResponse)); | ||
const { result } = renderHook(() => useGetListQuery({ foo: 'bar' }), { | ||
wrapper: Wrapper, | ||
}); | ||
expect(result.current).toMatchObject({ | ||
status: 'pending', | ||
endpointName: 'getList', | ||
isLoading: true, | ||
isSuccess: false, | ||
isError: false, | ||
isFetching: true, | ||
}); | ||
|
||
await waitFor(() => expect(result.current.isSuccess).toBe(true)); | ||
|
||
expect(fetchMock).toBeCalledTimes(1); | ||
expect(result.current.data).toEqual('foobar'); | ||
}); | ||
}); | ||
|
||
describe('getMap', () => { | ||
it('renders hook', async () => { | ||
fetchMock.mockResponseOnce(JSON.stringify(aggResponse)); | ||
const { result } = renderHook(() => useGetMapQuery({ foo: 'bar' }), { | ||
wrapper: Wrapper, | ||
}); | ||
|
||
expect(result.current).toMatchObject({ | ||
status: 'pending', | ||
endpointName: 'getMap', | ||
isLoading: true, | ||
isSuccess: false, | ||
isError: false, | ||
isFetching: true, | ||
}); | ||
|
||
await waitFor(() => expect(result.current.isSuccess).toBe(true)); | ||
|
||
expect(fetchMock).toBeCalledTimes(1); | ||
expect(result.current.data).toEqual('foobar'); | ||
}); | ||
}); | ||
|
||
describe('getTrends', () => { | ||
it('renders hook', async () => { | ||
fetchMock.mockResponseOnce(JSON.stringify(aggResponse)); | ||
const { result } = renderHook(() => useGetTrendsQuery({ foo: 'bar' }), { | ||
wrapper: Wrapper, | ||
}); | ||
expect(result.current).toMatchObject({ | ||
status: 'pending', | ||
endpointName: 'getTrends', | ||
isLoading: true, | ||
isSuccess: false, | ||
isError: false, | ||
isFetching: true, | ||
}); | ||
|
||
await waitFor(() => expect(result.current.isSuccess).toBe(true)); | ||
|
||
expect(fetchMock).toBeCalledTimes(1); | ||
expect(result.current.data).toEqual('foobar'); | ||
}); | ||
}); |
Oops, something went wrong.