-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Expand file tree
/
Copy pathuseBulkExport.spec.tsx
More file actions
54 lines (52 loc) · 2.18 KB
/
useBulkExport.spec.tsx
File metadata and controls
54 lines (52 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import * as React from 'react';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { Basic, HookLevelExporter } from './useBulkExport.stories';
describe('useBulkExport', () => {
it('should export selected records using the exporter from the list context', async () => {
let exportedData: any[];
let exportedResource: string;
const exporter = jest.fn(
(data, fetchRelatedRecords, dataProvider, resource) => {
exportedData = data;
exportedResource = resource;
}
);
render(<Basic exporter={exporter} />);
fireEvent.click(await screen.findByText('War and Peace'));
fireEvent.click(await screen.findByText('The Lord of the Rings'));
fireEvent.click(await screen.findByText('Export'));
await waitFor(() => expect(exporter).toHaveBeenCalled());
expect(exportedData!).toEqual([
{ id: 1, title: 'War and Peace' },
{ id: 5, title: 'The Lord of the Rings' },
]);
expect(exportedResource!).toEqual('books');
});
it('should export selected records using the exporter from the hook options', async () => {
const exporter = jest.fn();
let exportedData: any[];
let exportedResource: string;
const hookExporter = jest.fn(
(data, fetchRelatedRecords, dataProvider, resource) => {
exportedData = data;
exportedResource = resource;
}
);
render(
<HookLevelExporter
exporter={exporter}
hookExporter={hookExporter}
/>
);
fireEvent.click(await screen.findByText('War and Peace'));
fireEvent.click(await screen.findByText('The Lord of the Rings'));
fireEvent.click(await screen.findByText('Export'));
await waitFor(() => expect(hookExporter).toHaveBeenCalled());
expect(exportedData!).toEqual([
{ id: 1, title: 'War and Peace' },
{ id: 5, title: 'The Lord of the Rings' },
]);
expect(exportedResource!).toEqual('books');
expect(exporter).toHaveBeenCalledTimes(0);
});
});