-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathMiradorViewer.test.jsx
More file actions
151 lines (134 loc) · 4.89 KB
/
MiradorViewer.test.jsx
File metadata and controls
151 lines (134 loc) · 4.89 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import { act, render, screen } from '@tests/utils/test-utils';
import MiradorViewer from '../../../src/lib/MiradorViewer';
/** */
const DummyPlugin = () => <div data-testid="plugin">Plugin</div>;
describe('MiradorViewer', () => {
let container;
beforeEach(async () => {
render(<div id="mirador" data-testid="container" />);
container = await screen.findByTestId('container');
});
describe('constructor', () => {
it('returns viewer store', () => {
const instance = new MiradorViewer({});
// eslint-disable-next-line testing-library/no-unnecessary-act
act(() => { instance.renderInto(container); });
expect(instance.store.dispatch).toBeDefined();
});
it('renders via ReactDOM', () => {
const instance = new MiradorViewer({});
// eslint-disable-next-line testing-library/no-unnecessary-act
act(() => { instance.renderInto(container); });
expect(screen.getByTestId('container')).not.toBeEmptyDOMElement();
});
});
describe('processConfig', () => {
it('transforms config values to actions to dispatch to store', () => {
const instance = new MiradorViewer(
{
catalog: [
{ manifestId: 'http://media.nga.gov/public/manifests/nga_highlights.json', provider: 'National Gallery of Art' },
],
windows: [
{
canvasId: 'https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-47174892',
loadedManifest: 'https://iiif.harvardartmuseums.org/manifests/object/299843',
thumbnailNavigationPosition: 'far-bottom',
},
{
loadedManifest: 'https://iiif.harvardartmuseums.org/manifests/object/299843',
view: 'book',
},
],
},
{
plugins: [{
component: DummyPlugin,
config: {
foo: 'bar',
},
mode: 'add',
target: 'WindowTopBarPluginArea',
}],
},
);
// eslint-disable-next-line testing-library/no-unnecessary-act
act(() => { instance.renderInto(container); });
const { windows, catalog, config } = instance.store.getState();
const windowIds = Object.keys(windows);
expect(Object.keys(windowIds).length).toBe(2);
expect(windows[windowIds[0]].canvasId).toBe('https://iiif.harvardartmuseums.org/manifests/object/299843/canvas/canvas-47174892');
expect(windows[windowIds[1]].canvasId).toBe(undefined);
expect(windows[windowIds[0]].thumbnailNavigationPosition).toBe('far-bottom');
expect(windows[windowIds[1]].thumbnailNavigationPosition).toBe(undefined);
expect(windows[windowIds[0]].view).toBe(undefined);
expect(windows[windowIds[1]].view).toBe('book');
expect(catalog.length).toBe(2);
expect(catalog[0].manifestId).toBe('https://iiif.harvardartmuseums.org/manifests/object/299843');
expect(catalog[1].manifestId).toBe('http://media.nga.gov/public/manifests/nga_highlights.json');
expect(catalog[1].provider).toBe('National Gallery of Art');
expect(config.foo).toBe('bar');
});
it('merges translation configs from multiple plugins', () => {
const instance = new MiradorViewer(
{},
{
plugins: [
{
component: DummyPlugin,
config: {
translations: {
en: {
foo: 'bar',
},
},
},
mode: 'add',
target: 'WindowTopBarPluginArea',
},
{
component: DummyPlugin,
config: {
translations: {
en: {
bat: 'bar',
},
},
},
mode: 'wrap',
target: 'Window',
},
],
},
);
const { config } = instance.store.getState();
expect(config.translations.en).toEqual(expect.objectContaining({
bat: 'bar',
foo: 'bar',
}));
});
});
describe('render', () => {
it('passes props through to the App component', async () => {
const instance = new MiradorViewer({});
const plugins = [{
component: DummyPlugin,
mode: 'wrap',
target: 'AppProviders',
}];
render(instance.render({ plugins }));
expect(await screen.findByTestId('plugin')).toBeInTheDocument();
});
});
describe('unmount', () => {
it('unmounts via ReactDOM', () => {
const instance = new MiradorViewer({});
// eslint-disable-next-line testing-library/no-unnecessary-act
act(() => { instance.renderInto(container); });
expect(container).not.toBeEmptyDOMElement();
// eslint-disable-next-line testing-library/no-unnecessary-act
act(() => { instance.unmount(); });
expect(container).toBeEmptyDOMElement();
});
});
});