-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathCompanionArea.test.jsx
More file actions
99 lines (78 loc) · 3.16 KB
/
CompanionArea.test.jsx
File metadata and controls
99 lines (78 loc) · 3.16 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
import { render, screen } from '@tests/utils/test-utils';
import userEvent from '@testing-library/user-event';
import { CompanionArea } from '../../../src/components/CompanionArea';
/** */
function createWrapper(props) {
return render(
<CompanionArea
classes={{ horizontal: 'horizontal' }}
direction="ltr"
windowId="abc123"
position="right"
companionAreaOpen
companionWindowIds={['foo', 'baz']}
{...props}
/>,
{ preloadedState: { companionWindows: { baz: { content: 'attribution' }, foo: { content: 'info' } } } },
);
}
describe('CompanionArea', () => {
it('should render all <CompanionWindow>', () => {
createWrapper();
expect(screen.getAllByRole('complementary')).toHaveLength(2);
});
it('should add the appropriate classes when the companion area fills the full width', () => {
const { container } = createWrapper({ position: 'bottom' });
expect(container.querySelector('.mirador-companion-area-bottom')).toBeInTheDocument(); // eslint-disable-line testing-library/no-node-access, testing-library/no-container
});
it('renders the appropriate <CompanionWindow> components', () => {
createWrapper();
expect(screen.getByRole('heading', { name: 'About this item' })).toBeInTheDocument();
expect(screen.getByRole('heading', { name: 'Rights' })).toBeInTheDocument();
});
it('has a toggle to show the companion area window in the left position', async () => {
const setCompanionAreaOpen = vi.fn();
const user = userEvent.setup();
createWrapper({
companionAreaOpen: false,
position: 'left',
setCompanionAreaOpen,
sideBarOpen: true,
});
expect(screen.getByRole('button', { name: 'Expand sidebar' })).toHaveAttribute('aria-expanded', 'false');
expect(screen.queryByRole('complementary')).not.toBeInTheDocument();
await user.click(screen.getByRole('button', { name: 'Expand sidebar' }));
expect(setCompanionAreaOpen).toHaveBeenCalledWith('abc123', true);
});
it('has a toggle to hide the companion area window in the left position', async () => {
const setCompanionAreaOpen = vi.fn();
const user = userEvent.setup();
createWrapper({
companionAreaOpen: true,
position: 'left',
setCompanionAreaOpen,
sideBarOpen: true,
});
expect(screen.getByRole('button', { name: 'Collapse sidebar' })).toHaveAttribute('aria-expanded', 'true');
await user.click(screen.getByRole('button', { name: 'Collapse sidebar' }));
expect(setCompanionAreaOpen).toHaveBeenCalledWith('abc123', false);
});
it('does not show a toggle if the sidebar is collapsed', () => {
createWrapper({
companionAreaOpen: true,
position: 'left',
setCompanionAreaOpen: () => {},
sideBarOpen: false,
});
expect(screen.queryByRole('button', { name: 'Collapse sidebar' })).not.toBeInTheDocument();
});
it('does not show a toggle in other positions', () => {
createWrapper({
companionAreaOpen: true,
position: 'whatever',
setCompanionAreaOpen: () => {},
sideBarOpen: true,
});
expect(screen.queryByRole('button', { name: 'Collapse sidebar' })).not.toBeInTheDocument();
});
});