Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import eslint from '@eslint/js';
import queryPlugin from '@tanstack/eslint-plugin-query';
import prettierPlugin from 'eslint-config-prettier/flat';
import cypressPlugin from 'eslint-plugin-cypress';
import jsxA11yPlugin from 'eslint-plugin-jsx-a11y';
Expand All @@ -17,6 +18,7 @@ export default defineConfig(
reactPlugin.configs.flat['jsx-runtime'],
reactHooksPlugin.configs.flat.recommended,
jsxA11yPlugin.flatConfigs.recommended,
queryPlugin.configs['flat/recommended'],
// See https://github.com/prettier/eslint-config-prettier put last
prettierPlugin,
{
Expand Down
5 changes: 3 additions & 2 deletions packages/datagateway-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"@emotion/styled": "11.14.1",
"@mui/lab": "5.0.0-alpha.177",
"@mui/x-date-pickers": "6.20.2",
"@tanstack/react-query": "4.43.0",
"@tanstack/react-query-devtools": "4.43.0",
"@tanstack/react-query": "5.90.21",
"@tanstack/react-query-devtools": "5.91.3",
"@types/lodash.debounce": "4.0.6",
"@vitejs/plugin-react": "5.2.0",
"axios": "1.13.5",
Expand Down Expand Up @@ -48,6 +48,7 @@
"devDependencies": {
"@mui/icons-material": "5.18.0",
"@mui/material": "5.18.0",
"@tanstack/eslint-plugin-query": "5.91.4",
"@testing-library/dom": "10.4.1",
"@testing-library/jest-dom": "6.9.1",
"@testing-library/react": "16.3.2",
Expand Down
63 changes: 38 additions & 25 deletions packages/datagateway-common/src/api/cart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import {
useSubmitCart,
} from '.';
import { DownloadCart } from '../app.types';
import handleICATError from '../handleICATError';
import * as handleICATError from '../handleICATError';
import { createReactQueryWrapper } from '../setupTests';

vi.mock('../handleICATError');

describe('Cart api functions', () => {
let mockData: DownloadCart;
const getElementByIdSpy = vi.spyOn(document, 'getElementById');
const handleICATErrorSpy = vi
.spyOn(handleICATError, 'default')
.mockImplementation(vi.fn());

beforeEach(() => {
mockData = {
Expand All @@ -47,7 +48,7 @@ describe('Cart api functions', () => {
vi.mocked(axios.get).mockClear();
vi.mocked(axios.post).mockClear();
vi.mocked(axios.delete).mockClear();
vi.mocked(handleICATError).mockClear();
vi.mocked(handleICATErrorSpy).mockClear();
vi.mocked(getElementByIdSpy).mockClear();
});

Expand Down Expand Up @@ -81,7 +82,7 @@ describe('Cart api functions', () => {
wrapper: createReactQueryWrapper(),
});

expect(result.current.status).toBe('loading');
expect(result.current.status).toBe('pending');
expect(result.current.fetchStatus).toBe('idle');

expect(axios.get).not.toHaveBeenCalled();
Expand All @@ -98,9 +99,12 @@ describe('Cart api functions', () => {

await waitFor(() => expect(result.current.isError).toBe(true));

expect(handleICATError).toHaveBeenCalledWith({
message: 'Test error message',
});
expect(handleICATErrorSpy).toHaveBeenCalledWith(
{
message: 'Test error message',
},
undefined
);
});
});

Expand Down Expand Up @@ -158,8 +162,8 @@ describe('Cart api functions', () => {
});

expect(result.current.failureCount).toBe(2);
expect(handleICATError).toHaveBeenCalledTimes(1);
expect(handleICATError).toHaveBeenCalledWith({
expect(handleICATErrorSpy).toHaveBeenCalledTimes(1);
expect(handleICATErrorSpy).toHaveBeenCalledWith({
message: 'Test error message',
});
});
Expand Down Expand Up @@ -221,8 +225,8 @@ describe('Cart api functions', () => {
});

expect(result.current.failureCount).toBe(2);
expect(handleICATError).toHaveBeenCalledTimes(1);
expect(handleICATError).toHaveBeenCalledWith({
expect(handleICATErrorSpy).toHaveBeenCalledTimes(1);
expect(handleICATErrorSpy).toHaveBeenCalledWith({
message: 'Test error message',
});
});
Expand Down Expand Up @@ -295,7 +299,7 @@ describe('Cart api functions', () => {
expect(result.current.useSubmitCart.isError).toBe(true)
);

expect(handleICATError).toHaveBeenCalledWith(
expect(handleICATErrorSpy).toHaveBeenCalledWith(
expect.objectContaining({
message: 'No downloadId returned from submitCart request',
})
Expand Down Expand Up @@ -331,7 +335,7 @@ describe('Cart api functions', () => {
expect(result.current.useSubmitCart.isError).toBe(true)
);

expect(handleICATError).toHaveBeenCalledWith({
expect(handleICATErrorSpy).toHaveBeenCalledWith({
message: 'test error message',
});
});
Expand Down Expand Up @@ -389,9 +393,12 @@ describe('Cart api functions', () => {

await waitFor(() => expect(result.current.isError).toBe(true));

expect(handleICATError).toHaveBeenCalledWith({
message: 'Test error message',
});
expect(handleICATErrorSpy).toHaveBeenCalledWith(
{
message: 'Test error message',
},
undefined
);
});
});

Expand Down Expand Up @@ -466,9 +473,12 @@ describe('Cart api functions', () => {

await waitFor(() => expect(result.current.isError).toBe(true));

expect(handleICATError).toHaveBeenCalledWith({
message: 'Test error message',
});
expect(handleICATErrorSpy).toHaveBeenCalledWith(
{
message: 'Test error message',
},
undefined
);
});
});

Expand Down Expand Up @@ -507,9 +517,12 @@ describe('Cart api functions', () => {

await waitFor(() => expect(result.current.isError).toBe(true));

expect(handleICATError).toHaveBeenCalledWith({
message: 'Test error message',
});
expect(handleICATErrorSpy).toHaveBeenCalledWith(
{
message: 'Test error message',
},
undefined
);
});
});

Expand Down Expand Up @@ -575,7 +588,7 @@ describe('Cart api functions', () => {
});
await waitFor(() => expect(result.current.isError).toBe(true));

expect(handleICATError).toHaveBeenCalledWith({
expect(handleICATErrorSpy).toHaveBeenCalledWith({
message: 'test error message',
});
});
Expand Down Expand Up @@ -646,7 +659,7 @@ describe('Cart api functions', () => {
});
await waitFor(() => expect(result.current.isError).toBe(true));

expect(handleICATError).toHaveBeenCalledWith({
expect(handleICATErrorSpy).toHaveBeenCalledWith({
message: 'test error message',
});
});
Expand Down
Loading
Loading