Skip to content

Commit 3116d3d

Browse files
committed
Ensure offline scenarios tests do not impact later tests
1 parent dbc946d commit 3116d3d

17 files changed

+67
-2
lines changed

packages/ra-core/src/controller/edit/EditBase.spec.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ import {
1111
WithAuthProviderNoAccessControl,
1212
WithRenderProps,
1313
} from './EditBase.stories';
14+
import { onlineManager } from '@tanstack/react-query';
1415

1516
describe('EditBase', () => {
17+
beforeEach(() => {
18+
onlineManager.setOnline(true);
19+
});
1620
it('should give access to the save function', async () => {
1721
const dataProvider = testDataProvider({
1822
getOne: () =>

packages/ra-core/src/controller/field/ReferenceArrayFieldBase.spec.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ import { ReferenceArrayFieldBase } from './ReferenceArrayFieldBase';
1212
import { useResourceContext } from '../../core/useResourceContext';
1313
import { testDataProvider } from '../../dataProvider/testDataProvider';
1414
import { CoreAdminContext } from '../../core/CoreAdminContext';
15+
import { onlineManager } from '@tanstack/react-query';
1516

1617
describe('ReferenceArrayFieldBase', () => {
18+
beforeEach(() => {
19+
onlineManager.setOnline(true);
20+
});
1721
it('should display an error if error is defined', async () => {
1822
jest.spyOn(console, 'error')
1923
.mockImplementationOnce(() => {})

packages/ra-core/src/controller/field/ReferenceFieldBase.spec.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ import {
1414
WithRenderProp,
1515
} from './ReferenceFieldBase.stories';
1616
import { RecordContextProvider } from '../record';
17+
import { onlineManager } from '@tanstack/react-query';
1718

1819
describe('<ReferenceFieldBase />', () => {
1920
beforeAll(() => {
2021
window.scrollTo = jest.fn();
2122
});
23+
beforeEach(() => {
24+
onlineManager.setOnline(true);
25+
});
2226

2327
it('should display an error if error is defined', async () => {
2428
jest.spyOn(console, 'error')

packages/ra-core/src/controller/field/ReferenceManyCountBase.spec.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ import {
66
LoadingState,
77
Offline,
88
} from './ReferenceManyCountBase.stories';
9+
import { onlineManager } from '@tanstack/react-query';
910

1011
describe('ReferenceManyCountBase', () => {
12+
beforeEach(() => {
13+
onlineManager.setOnline(true);
14+
});
1115
it('should display an error if error is defined', async () => {
1216
jest.spyOn(console, 'error')
1317
.mockImplementationOnce(() => {})

packages/ra-core/src/controller/field/ReferenceManyFieldBase.spec.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ import { ReferenceManyFieldBase } from './ReferenceManyFieldBase';
1212
import { useResourceContext } from '../../core/useResourceContext';
1313
import { testDataProvider } from '../../dataProvider/testDataProvider';
1414
import { CoreAdminContext } from '../../core/CoreAdminContext';
15+
import { onlineManager } from '@tanstack/react-query';
1516

1617
describe('ReferenceManyFieldBase', () => {
18+
beforeEach(() => {
19+
onlineManager.setOnline(true);
20+
});
1721
it('should display an error if error is defined', async () => {
1822
jest.spyOn(console, 'error')
1923
.mockImplementationOnce(() => {})

packages/ra-core/src/controller/field/ReferenceOneFieldBase.spec.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ import {
66
Offline,
77
WithRenderProp,
88
} from './ReferenceOneFieldBase.stories';
9+
import { onlineManager } from '@tanstack/react-query';
910

1011
describe('ReferenceOneFieldBase', () => {
12+
beforeEach(() => {
13+
onlineManager.setOnline(true);
14+
});
1115
it('should pass the loading state', async () => {
1216
jest.spyOn(console, 'error')
1317
.mockImplementationOnce(() => {})

packages/ra-core/src/controller/input/ReferenceArrayInputBase.spec.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ import * as React from 'react';
22
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
33
import { testDataProvider } from 'ra-core';
44
import { Basic, Offline, WithError } from './ReferenceArrayInputBase.stories';
5+
import { onlineManager } from '@tanstack/react-query';
56

67
describe('<ReferenceArrayInputBase>', () => {
8+
beforeEach(() => {
9+
onlineManager.setOnline(true);
10+
});
711
afterEach(async () => {
812
// wait for the getManyAggregate batch to resolve
913
await waitFor(() => new Promise(resolve => setTimeout(resolve, 0)));

packages/ra-core/src/controller/input/ReferenceInputBase.spec.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import expect from 'expect';
33
import { render, screen, waitFor, fireEvent } from '@testing-library/react';
4-
import { QueryClient } from '@tanstack/react-query';
4+
import { onlineManager, QueryClient } from '@tanstack/react-query';
55
import { CoreAdminContext } from '../../core';
66
import {
77
ChoicesProps,
@@ -30,6 +30,9 @@ describe('<ReferenceInputBase />', () => {
3030
beforeAll(() => {
3131
window.scrollTo = jest.fn();
3232
});
33+
beforeEach(() => {
34+
onlineManager.setOnline(true);
35+
});
3336

3437
it('should display an error if error is defined', async () => {
3538
jest.spyOn(console, 'error')

packages/ra-core/src/controller/show/ShowBase.spec.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ import {
1111
WithAuthProviderNoAccessControl,
1212
WithRenderProp,
1313
} from './ShowBase.stories';
14+
import { onlineManager } from '@tanstack/react-query';
1415

1516
describe('ShowBase', () => {
17+
beforeEach(() => {
18+
onlineManager.setOnline(true);
19+
});
1620
it('should load data immediately if authProvider is not provided', async () => {
1721
const dataProvider = testDataProvider({
1822
// @ts-ignore

packages/ra-core/src/core/IsOffline.spec.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import * as React from 'react';
22
import { render, screen } from '@testing-library/react';
33
import { Basic } from './IsOffline.stories';
4+
import { onlineManager } from '@tanstack/react-query';
45

56
describe('<IsOffline>', () => {
7+
beforeEach(() => {
8+
onlineManager.setOnline(true);
9+
});
610
it('should render children when offline', async () => {
711
const { rerender } = render(<Basic isOnline={false} />);
812
await screen.findByText('You are offline, the data may be outdated');

0 commit comments

Comments
 (0)