-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathWindowSideBarButtons.test.jsx
More file actions
152 lines (125 loc) · 4.61 KB
/
WindowSideBarButtons.test.jsx
File metadata and controls
152 lines (125 loc) · 4.61 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
152
import { render, screen } from '@tests/utils/test-utils';
import userEvent from '@testing-library/user-event';
import { WindowSideBarButtons } from '../../../src/components/WindowSideBarButtons';
/** create wrapper */
function createWrapper(props) {
return render(
<WindowSideBarButtons
addCompanionWindow={() => {}}
{...props}
panels={{
annotations: true,
attribution: true,
canvas: true,
info: true,
search: false,
...props.panels,
}}
/>,
);
}
/* eslint-disable testing-library/no-node-access */
describe('WindowSideBarButtons', () => {
const windowId = 'test123';
let user;
let wrapper;
beforeEach(() => {
user = userEvent.setup();
});
it('renders without an error', () => {
wrapper = createWrapper({ windowId });
expect(screen.getByRole('tablist')).toBeInTheDocument();
});
it('triggers the addCompanionWindow prop on click', async () => {
const addCompanionWindow = vi.fn();
wrapper = createWrapper({ addCompanionWindow, windowId });
await user.click(screen.getByRole('tab', { name: 'Information' }));
expect(addCompanionWindow).toHaveBeenCalledTimes(1);
expect(addCompanionWindow).toHaveBeenCalledWith('info');
});
it('has a badge indicating if the annotations panel has annotations', () => {
let tab;
wrapper = createWrapper({ hasAnnotations: true, windowId });
tab = screen.getByRole('tab', { name: 'Annotations' });
expect(tab).toBeInTheDocument();
expect(tab.querySelector('.MuiBadge-dot:not(.MuiBadge-invisible)')).toBeInTheDocument();
wrapper.unmount();
wrapper = createWrapper({ hasAnnotations: false, hasAnyAnnotations: true, windowId });
tab = screen.getByRole('tab', { name: 'Annotations' });
expect(tab.querySelector('.MuiBadge-dot.MuiBadge-invisible')).toBeInTheDocument();
});
it('hides the annotation panel if there are no annotations', () => {
wrapper = createWrapper({ hasAnyAnnotations: false, windowId });
expect(screen.queryByRole('tab', { name: 'Annotations' })).not.toBeInTheDocument();
});
it('can hide annotation panel when configured to do so', () => {
wrapper = createWrapper({ hasAnnotations: true, panels: { annotations: false }, windowId });
expect(screen.queryByRole('tab', { name: 'Annotations' })).not.toBeInTheDocument();
});
describe('search', () => {
it('by default is off', () => {
expect(screen.queryByRole('tab', { name: 'Search' })).not.toBeInTheDocument();
});
it('can be configured to be on', () => {
wrapper = createWrapper({ hasSearchService: true, panels: { search: true }, windowId });
expect(screen.getByRole('tab', { name: 'Search' })).toBeInTheDocument();
});
it('has a badge indicating if the search panel has active annotations', () => {
let tab;
wrapper = createWrapper({
hasSearchResults: true,
hasSearchService: true,
panels: {
search: true,
},
windowId,
});
tab = screen.getByRole('tab', { name: 'Search' });
expect(tab.querySelector('.MuiBadge-dot:not(.MuiBadge-invisible)')).toBeInTheDocument();
wrapper.unmount();
wrapper = createWrapper({
hasSearchResults: false,
hasSearchService: true,
panels: {
search: true,
},
windowId,
});
tab = screen.getByRole('tab', { name: 'Search' });
expect(tab.querySelector('.MuiBadge-dot.MuiBadge-invisible')).toBeInTheDocument();
});
});
describe('layers', () => {
it('by default is off', () => {
expect(screen.queryByRole('tab', { name: 'Layers' })).not.toBeInTheDocument();
});
it('can be configured to be on', () => {
wrapper = createWrapper({ hasAnyLayers: true, panels: { layers: true }, windowId });
expect(screen.getByRole('tab', { name: 'Layers' })).toBeInTheDocument();
});
it('has a badge indicating if there are currently any layers', () => {
let tab;
wrapper = createWrapper({
hasAnyLayers: true,
hasCurrentLayers: true,
panels: {
layers: true,
},
windowId,
});
tab = screen.getByRole('tab', { name: 'Layers' });
expect(tab.querySelector('.MuiBadge-dot:not(.MuiBadge-invisible)')).toBeInTheDocument();
wrapper.unmount();
wrapper = createWrapper({
hasAnyLayers: true,
hasCurrentLayers: false,
panels: {
layers: true,
},
windowId,
});
tab = screen.getByRole('tab', { name: 'Layers' });
expect(tab.querySelector('.MuiBadge-dot.MuiBadge-invisible')).toBeInTheDocument();
});
});
});