Skip to content

Commit 431eee0

Browse files
authored
adding mocks for the useVirtualizer hook + changing edit button test (#10204)
1 parent 4337f57 commit 431eee0

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

apps/bulk-edit/test/locations/Page/EntryTable.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ import { Entry, ContentTypeField } from '../../../src/locations/Page/types';
66
import { ContentTypeProps } from 'contentful-management';
77
import { isCheckboxAllowed } from '../../../src/locations/Page/utils/entryUtils';
88

9+
// Mock the virtualizer to render all items in tests
10+
vi.mock('@tanstack/react-virtual', () => ({
11+
useVirtualizer: () => ({
12+
getVirtualItems: () => [
13+
{ index: 0, start: 0, size: 50, end: 50 },
14+
{ index: 1, start: 50, size: 50, end: 100 },
15+
],
16+
getTotalSize: () => 100,
17+
}),
18+
}));
19+
920
const mockFields: ContentTypeField[] = [
1021
{ id: 'displayName', uniqueId: 'displayName', name: 'Display Name', type: 'Symbol' },
1122
{ id: 'description', uniqueId: 'description', name: 'Description', type: 'Text' },

apps/bulk-edit/test/locations/Page/Page.test.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ import { condoAEntry1, condoAEntry2 } from '../../mocks/mockEntries';
99
import { Notification } from '@contentful/f36-components';
1010
import type { ContentTypeProps } from 'contentful-management';
1111

12+
// Mock the virtualizer to render all items in tests
13+
vi.mock('@tanstack/react-virtual', () => ({
14+
useVirtualizer: () => ({
15+
getVirtualItems: () => [
16+
{ index: 0, start: 0, size: 50, end: 50 },
17+
{ index: 1, start: 50, size: 50, end: 100 },
18+
],
19+
getTotalSize: () => 100,
20+
}),
21+
}));
22+
1223
vi.mock('@contentful/react-apps-toolkit', () => ({
1324
useSDK: () => mockSdk,
1425
}));
@@ -48,12 +59,12 @@ describe('Page', () => {
4859
});
4960
});
5061

51-
it('does not show Edit/Bulk edit button when no field is selected', async () => {
62+
it('show Edit/Bulk edit button when no field is selected', async () => {
5263
render(<Page />);
5364
await waitFor(() => {
5465
expect(screen.getByTestId('bulk-edit-table')).toBeInTheDocument();
5566
});
56-
expect(screen.queryByText('Edit')).not.toBeInTheDocument();
67+
expect(screen.queryByText('Edit')).toBeInTheDocument();
5768
expect(screen.queryByText('Bulk edit')).not.toBeInTheDocument();
5869
});
5970
});

0 commit comments

Comments
 (0)