forked from ProjectMirador/mirador
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimaryWindow.test.js
More file actions
80 lines (76 loc) · 3.17 KB
/
PrimaryWindow.test.js
File metadata and controls
80 lines (76 loc) · 3.17 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
import { render, screen, waitFor } from '@tests/utils/test-utils';
import { Resource } from 'manifesto.js';
import textManifest from '../../fixtures/version-3/text-pdf.json';
import { PrimaryWindow } from '../../../src/components/PrimaryWindow';
/** create wrapper */
function createWrapper(props) {
return render(
<PrimaryWindow
classes={{}}
windowId="xyz"
{...props}
/>,
{ preloadedState: { windows: { xyz: { collectionPath: [{}], companionWindowIds: [] } } } },
);
}
describe('PrimaryWindow', () => {
it('should render expected elements', async () => {
createWrapper({ isFetching: false });
await screen.findByTestId('test-window');
expect(document.querySelector('.mirador-primary-window')).toBeInTheDocument(); // eslint-disable-line testing-library/no-node-access
expect(document.querySelector('.mirador-companion-area-left')).toBeInTheDocument(); // eslint-disable-line testing-library/no-node-access
});
it('should render children when available', () => {
createWrapper({ children: <span>hi</span>, isFetching: false });
expect(screen.getByText('hi')).toBeInTheDocument();
});
it('should render nothing if still fetching', () => {
createWrapper({ isFetching: true });
expect(screen.queryByRole('region', { accessibleName: 'item' })).not.toBeInTheDocument();
});
it('should render <GalleryView> if fetching is complete and view is gallery', async () => {
createWrapper({ isFetching: false, view: 'gallery' });
await screen.findByTestId('test-window');
await waitFor(() => {
expect(document.querySelector('#xyz-gallery')).toBeInTheDocument(); // eslint-disable-line testing-library/no-node-access
});
});
it('should render <CollectionDialog> and <SelectCollection> if manifest is collection and isCollectionDialogVisible', async () => {
render(<div id="xyz" />);
render(
<PrimaryWindow
classes={{}}
isCollection
isCollectionDialogVisible
windowId="xyz"
/>,
{ preloadedState: { windows: { xyz: { collectionPath: [{}] } } } },
);
await screen.findByRole('button', { accessibleName: 'show collection' });
});
it('should render a TextViewer when window has textResources but not audio, video or image', async () => {
render(<div id="xyz" />);
const manifests = {};
const manifestId = 'https://iiif.io/api/cookbook/recipe/0001-text-pdf/manifest.json';
manifests[manifestId] = {
id: manifestId,
json: textManifest,
};
const textResources = [true]; // this is a flag; the actual value will be given by a state selector against the preloaded state
const xyz = {
manifestId: 'https://iiif.io/api/cookbook/recipe/0001-text-pdf/manifest.json',
visibleCanvases: ['https://iiif.io/api/cookbook/recipe/0001-text-pdf/canvas'],
};
render(
<PrimaryWindow
classes={{}}
textResources={textResources}
windowId="xyz"
/>,
{ preloadedState: { manifests, windows: { xyz } } },
);
await waitFor(() => {
expect(document.querySelector('source:nth-of-type(1)')).toHaveAttribute('type', 'application/pdf'); // eslint-disable-line testing-library/no-node-access
});
});
});