-
Notifications
You must be signed in to change notification settings - Fork 263
Expand file tree
/
Copy pathThumbnailCanvasGrouping.test.jsx
More file actions
83 lines (79 loc) · 2.65 KB
/
ThumbnailCanvasGrouping.test.jsx
File metadata and controls
83 lines (79 loc) · 2.65 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
import { render, screen } from '@tests/utils/test-utils';
import userEvent from '@testing-library/user-event';
import { Utils } from 'manifesto.js';
import { ThumbnailCanvasGrouping } from '../../../src/components/ThumbnailCanvasGrouping';
import CanvasGroupings from '../../../src/lib/CanvasGroupings';
import manifestJson from '../../fixtures/version-2/019.json';
/** create wrapper */
function createWrapper(props) {
const canvasGroupings = new CanvasGroupings(
Utils.parseManifest(manifestJson).getSequences()[0].getCanvases(),
).groupings();
return render(
<ThumbnailCanvasGrouping
index={1}
currentCanvasId="https://purl.stanford.edu/fr426cg9537/iiif/canvas/fr426cg9537_1"
classes={{}}
style={{
height: 90,
top: 0,
width: 100,
}}
showThumbnailLabels
canvasGroupings={canvasGroupings}
height={131}
position="far-bottom"
{...props}
/>,
);
}
describe('ThumbnailCanvasGrouping', () => {
let wrapper;
let setCanvas;
beforeEach(() => {
setCanvas = vi.fn();
wrapper = createWrapper({ setCanvas });
});
const spyCurrentCanvasClass = vi.spyOn(ThumbnailCanvasGrouping.prototype, 'currentCanvasClass');
afterEach(() => {
spyCurrentCanvasClass.mockClear();
});
it('renders', () => {
expect(screen.getByRole('gridcell')).toBeInTheDocument();
});
it('renders a CaptionedIIIFThumbnail', () => {
expect(screen.getByText('Image 1')).toBeInTheDocument();
});
it('when clicked, updates the current canvas', async () => {
wrapper.unmount();
const user = userEvent.setup();
wrapper = createWrapper({ index: 0, setCanvas });
await user.click(wrapper.container.querySelector('.mirador-thumbnail-nav-canvas-0')); // eslint-disable-line testing-library/no-node-access
expect(spyCurrentCanvasClass).toHaveBeenCalledWith([0]);
expect(spyCurrentCanvasClass).toHaveReturnedWith('current-canvas-grouping');
expect(setCanvas).toHaveBeenCalledWith('http://iiif.io/api/presentation/2.0/example/fixtures/canvas/24/c1.json');
});
describe('attributes based off far-bottom position', () => {
it('in button div', () => {
expect(screen.getByRole('button', { name: 'Image 1' })).toHaveStyle({
height: '119px',
width: 'auto',
});
});
});
describe('attributes based off far-right position', () => {
beforeEach(() => {
wrapper.unmount();
createWrapper({
position: 'far-right',
setCanvas,
});
});
it('in button div', () => {
expect(screen.getByRole('button', { name: 'Image 1' })).toHaveStyle({
height: 'auto',
width: '100px',
});
});
});
});