-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathSwitchableProcessBar.test.tsx
181 lines (149 loc) · 5.46 KB
/
SwitchableProcessBar.test.tsx
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// SPDX-FileCopyrightText: Meta Platforms, Inc. and its affiliates
// SPDX-FileCopyrightText: TNG Technology Consulting GmbH <https://www.tngtech.com>
//
// SPDX-License-Identifier: Apache-2.0
import { fireEvent, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { text } from '../../../../shared/text';
import { setUserSetting } from '../../../state/actions/user-settings-actions/user-settings-actions';
import { setVariable } from '../../../state/actions/variables-actions/variables-actions';
import { PROGRESS_DATA } from '../../../state/variables/use-progress-data';
import { renderComponent } from '../../../test-helpers/render';
import { ProgressBarData } from '../../../types/types';
import { SwitchableProcessBar } from '../SwitchableProcessBar';
const PROGRESS_BAR_DATA: ProgressBarData = {
fileCount: 6,
filesWithHighlyCriticalExternalAttributionsCount: 1,
filesWithMediumCriticalExternalAttributionsCount: 1,
filesWithManualAttributionCount: 3,
filesWithOnlyExternalAttributionCount: 1,
filesWithOnlyPreSelectedAttributionCount: 1,
resourcesWithMediumCriticalExternalAttributions: [],
resourcesWithNonInheritedExternalAttributionOnly: [],
resourcesWithHighlyCriticalExternalAttributions: [],
classificationStatistics: {},
};
const switchableProgressBarText = text.topBar.switchableProgressBar;
const attributionProgressBarLabel =
switchableProgressBarText.attributionProgressBar.ariaLabel;
function openSelect() {
fireEvent.mouseDown(screen.getByRole('combobox'), {
advanceTimers: jest.runOnlyPendingTimersAsync,
});
}
function expectSelectToBeOpen() {
expect(
screen.getByText(
switchableProgressBarText.attributionProgressBar.selectLabel,
{
selector: 'li',
},
),
).toBeInTheDocument();
}
async function selectEntry(selectLabel: string) {
await userEvent.click(screen.getByText(selectLabel), {
advanceTimers: jest.runOnlyPendingTimersAsync,
});
}
function getCriticalSignalsProgressBar() {
return screen.getByLabelText(
switchableProgressBarText.criticalSignalsBar.ariaLabel,
);
}
function getAttributionProgressBar() {
return screen.getByLabelText(
switchableProgressBarText.attributionProgressBar.ariaLabel,
);
}
describe('SwitchableProcessBar', () => {
beforeEach(() => {
jest.useFakeTimers();
});
afterEach(() => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
});
it('does not display the progress bar when no progress data available', () => {
renderComponent(<SwitchableProcessBar />);
expect(screen.queryByLabelText(/Progress bar .*/)).not.toBeInTheDocument();
});
it('displays the progress bar when progress data available', () => {
renderComponent(<SwitchableProcessBar />, {
actions: [setVariable<ProgressBarData>(PROGRESS_DATA, PROGRESS_BAR_DATA)],
});
expect(
screen.getByLabelText(attributionProgressBarLabel),
).toBeInTheDocument();
});
it('switches the progress bar via the select', async () => {
renderComponent(<SwitchableProcessBar />, {
actions: [setVariable<ProgressBarData>(PROGRESS_DATA, PROGRESS_BAR_DATA)],
});
openSelect();
expectSelectToBeOpen();
await selectEntry(switchableProgressBarText.criticalSignalsBar.selectLabel);
expect(getCriticalSignalsProgressBar()).toBeInTheDocument();
openSelect();
expectSelectToBeOpen();
await selectEntry(
switchableProgressBarText.attributionProgressBar.selectLabel,
);
expect(getAttributionProgressBar()).toBeInTheDocument();
});
it('offers all three possible progress bars if classificaitions configured active', async () => {
renderComponent(<SwitchableProcessBar />, {
actions: [
setVariable<ProgressBarData>(PROGRESS_DATA, PROGRESS_BAR_DATA),
setUserSetting({ showClassifications: true }),
],
});
openSelect();
expectSelectToBeOpen();
const menuEntries = (await screen.findAllByRole('option')).map(
(element) => element.textContent,
);
expect(menuEntries).toEqual([
'Attributions',
'Criticalities',
'Classifications',
]);
});
it('does not offer classifications if disabled', async () => {
renderComponent(<SwitchableProcessBar />, {
actions: [
setVariable<ProgressBarData>(PROGRESS_DATA, PROGRESS_BAR_DATA),
setUserSetting({ showClassifications: false }),
],
});
openSelect();
expectSelectToBeOpen();
const menuEntries = (await screen.findAllByRole('option')).map(
(element) => element.textContent,
);
expect(menuEntries).toEqual(['Attributions', 'Criticalities']);
});
it('does not offer criticality if disabled', async () => {
renderComponent(<SwitchableProcessBar />, {
actions: [
setVariable<ProgressBarData>(PROGRESS_DATA, PROGRESS_BAR_DATA),
setUserSetting({ showCriticality: false }),
],
});
openSelect();
expectSelectToBeOpen();
const menuEntries = (await screen.findAllByRole('option')).map(
(element) => element.textContent,
);
expect(menuEntries).toEqual(['Attributions', 'Classifications']);
});
it('does not show select if only one option to select', () => {
renderComponent(<SwitchableProcessBar />, {
actions: [
setVariable<ProgressBarData>(PROGRESS_DATA, PROGRESS_BAR_DATA),
setUserSetting({ showCriticality: false, showClassifications: false }),
],
});
expect(screen.queryByRole('combobox')).not.toBeInTheDocument();
});
});