-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathCollectionDialog.test.jsx
More file actions
116 lines (93 loc) · 4.48 KB
/
CollectionDialog.test.jsx
File metadata and controls
116 lines (93 loc) · 4.48 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { render, screen } from '@tests/utils/test-utils';
import userEvent from '@testing-library/user-event';
import { Utils } from 'manifesto.js';
import { CollectionDialog } from '../../../src/components/CollectionDialog';
import collection from '../../fixtures/version-2/collection.json';
import parentCollection from '../../fixtures/version-2/parentCollection.json';
/** */
function createWrapper(props) {
const { collection: propsCollection, manifest, ...otherProps } = props;
const manifestId = (manifest && manifest['@id']) || collection['@id'];
const manifestObject = Utils.parseManifest(manifest || collection);
const collectionObject = propsCollection && Utils.parseManifest(propsCollection);
render(<div id="window" />);
return render(
<CollectionDialog
addWindow={() => {}}
collection={collectionObject}
classes={{}}
ready
manifestId={manifestId}
manifest={manifestObject}
windowId="window"
{...otherProps}
/>,
{ preloadedState: { windows: { window: { id: 'window' } } } },
);
}
describe('CollectionDialog', () => {
it('renders a dialog with collection menu items', () => {
createWrapper({});
expect(screen.getByRole('dialog')).toBeInTheDocument();
expect(screen.getAllByRole('menuitem')).toHaveLength(55);
expect(screen.getByRole('menuitem', { name: 'Test 1 Manifest: Minimum Required Fields' })).toBeInTheDocument();
});
it('when not ready returns placeholder skeleton', () => {
createWrapper({ ready: false });
expect(screen.queryByRole('menuitem')).not.toBeInTheDocument();
expect(screen.getByRole('dialog').querySelectorAll('.MuiSkeleton-root')).toHaveLength(3); // eslint-disable-line testing-library/no-node-access
});
it('clicking the hide button fires hideCollectionDialog', async () => {
const user = userEvent.setup();
const hideCollectionDialog = vi.fn();
createWrapper({ hideCollectionDialog });
await user.click(screen.getByRole('button', { name: 'Close' }));
expect(hideCollectionDialog).toHaveBeenCalled();
});
it('fires correct showCollectionDialog when a child collection is selected', async () => {
const user = userEvent.setup();
const showCollectionDialog = vi.fn();
createWrapper({ manifest: parentCollection, showCollectionDialog });
expect(screen.getByRole('dialog')).toBeInTheDocument();
expect(screen.getAllByRole('menuitem')).toHaveLength(1);
expect(screen.getByRole('menuitem', { name: 'Collection of Test Cases - label for parent' })).toBeInTheDocument();
await user.click(screen.getByRole('menuitem', { name: 'Collection of Test Cases - label for parent' }));
expect(showCollectionDialog).toHaveBeenCalledWith(collection['@id'], [parentCollection['@id']], 'window');
});
it('fires correct showCollectionDialog when the parent collection is clicked', async () => {
const user = userEvent.setup();
const showCollectionDialog = vi.fn();
createWrapper({
collection: parentCollection,
dialogCollectionPath: [parentCollection['@id']],
manifest: collection,
showCollectionDialog,
});
expect(screen.getByRole('dialog')).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Parent Collection of Collection' })).toBeInTheDocument();
await user.click(screen.getByRole('button', { name: 'Parent Collection of Collection' }));
expect(showCollectionDialog).toHaveBeenCalledWith(parentCollection['@id'], [], 'window');
});
it('fires hideCollectionDialog, setWorkspaceAddVisibility, updateWindow when a manifest is selected', async () => {
const user = userEvent.setup();
const hideCollectionDialog = vi.fn();
const setWorkspaceAddVisibility = vi.fn();
const updateWindow = vi.fn();
const manifestId = 'http://iiif.io/api/presentation/2.1/example/fixtures/1/manifest.json';
createWrapper({
collection: parentCollection,
dialogCollectionPath: [parentCollection['@id']],
hideCollectionDialog,
manifest: collection,
setWorkspaceAddVisibility,
updateWindow,
});
expect(screen.getByRole('dialog')).toBeInTheDocument();
await user.click(screen.getByRole('menuitem', { name: 'Test 1 Manifest: Minimum Required Fields' }));
expect(hideCollectionDialog).toHaveBeenCalledWith('window');
expect(setWorkspaceAddVisibility).toHaveBeenCalledWith(false);
expect(updateWindow).toHaveBeenCalledWith('window', {
canvasId: null, collectionPath: [parentCollection['@id'], collection['@id']], manifestId,
});
});
});