Skip to content

Commit

Permalink
Tests for download type status caching #1519
Browse files Browse the repository at this point in the history
  • Loading branch information
kaperoo committed Aug 20, 2023
1 parent fa4fcbc commit 8dc8dd0
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions packages/datagateway-download/src/downloadApiHooks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,16 @@ describe('Download Cart API react-query hooks test', () => {
describe('useDownloadTypeStatuses', () => {
const downloadTypes = ['https', 'globus'];

let queryClient: QueryClient;

beforeAll(() => {
queryClient = new QueryClient();
});

afterEach(() => {
queryClient.clear();
});

it('should query statuses of download types', async () => {
axios.get = jest.fn().mockResolvedValue({
data: {
Expand Down Expand Up @@ -1218,6 +1228,43 @@ describe('Download Cart API react-query hooks test', () => {
}
);
});

it('should refetch data on every hook call', async () => {
axios.get = jest.fn().mockResolvedValue({
data: {
disabled: false,
message: '',
},
});

const wrapper = createReactQueryWrapper();

const { result, waitFor } = renderHook(
() =>
useDownloadTypeStatuses({
downloadTypes: ['https'],
}),
{ wrapper }
);

await waitFor(() => result.current.every((query) => query.isSuccess));

expect(result.current[0].isStale).toBe(true);
expect(axios.get).toHaveBeenCalledTimes(1);

const { result: newResult } = renderHook(
() =>
useDownloadTypeStatuses({
downloadTypes: ['https'],
}),
{ wrapper }
);

await waitFor(() => newResult.current.every((query) => query.isSuccess));

expect(newResult.current[0].isStale).toBe(true);
expect(axios.get).toHaveBeenCalledTimes(2);
});
});

describe('useDownloadPercentageComplete', () => {
Expand Down

0 comments on commit 8dc8dd0

Please sign in to comment.