-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathPackageCard.test.tsx
203 lines (172 loc) · 6.4 KB
/
PackageCard.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// 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 { screen } from '@testing-library/react';
import { Criticality, RawCriticality } from '../../../../shared/shared-types';
import { faker } from '../../../../testing/Faker';
import { setConfig } from '../../../state/actions/resource-actions/all-views-simple-actions';
import { setUserSetting } from '../../../state/actions/user-settings-actions/user-settings-actions';
import { renderComponent } from '../../../test-helpers/render';
import { PackageCard } from '../PackageCard';
describe('The PackageCard', () => {
it('renders with preferred icon', () => {
renderComponent(
<PackageCard
packageInfo={faker.opossum.packageInfo({
wasPreferred: true,
preferred: true,
})}
onClick={jest.fn()}
/>,
);
expect(screen.getByTestId('preferred-icon')).toBeInTheDocument();
expect(screen.queryByTestId('was-preferred-icon')).not.toBeInTheDocument();
});
it('renders with was-preferred icon', () => {
renderComponent(
<PackageCard
packageInfo={faker.opossum.packageInfo({ wasPreferred: true })}
onClick={jest.fn()}
/>,
);
expect(screen.queryByTestId('preferred-icon')).not.toBeInTheDocument();
expect(screen.getByTestId('was-preferred-icon')).toBeInTheDocument();
});
it('renders package card with count', () => {
const packageInfo = faker.opossum.packageInfo({ count: 13 });
renderComponent(
<PackageCard packageInfo={packageInfo} onClick={jest.fn()} />,
);
expect(
screen.getByText(
`${packageInfo.packageName!}, ${packageInfo.packageVersion!}`,
),
).toBeInTheDocument();
expect(screen.getByText(packageInfo.licenseName!)).toBeInTheDocument();
expect(screen.getByText('13')).toBeInTheDocument();
});
it('renders package card with checkbox', () => {
const packageInfo = faker.opossum.packageInfo();
renderComponent(
<PackageCard
packageInfo={packageInfo}
onClick={jest.fn()}
checkbox={{ checked: true, onChange: jest.fn() }}
/>,
);
expect(
screen.getByText(
`${packageInfo.packageName!}, ${packageInfo.packageVersion!}`,
),
).toBeInTheDocument();
expect(screen.getByText(packageInfo.licenseName!)).toBeInTheDocument();
expect(screen.getByRole('checkbox')).toBeInTheDocument();
});
describe('classification icon', () => {
it('renders the classification icon for classification > 0', () => {
const packageInfo = faker.opossum.packageInfo({ classification: 1 });
renderComponent(
<PackageCard packageInfo={packageInfo} onClick={jest.fn()} />,
{
actions: [
setConfig({
classifications: {
1: faker.opossum.classificationEntry(),
},
}),
],
},
);
const classificationIcon = screen.getByTestId('classification-tooltip');
expect(classificationIcon).toBeVisible();
});
it('does not render the classification icon for classification 0', () => {
const packageInfo = faker.opossum.packageInfo({ classification: 0 });
renderComponent(
<PackageCard packageInfo={packageInfo} onClick={jest.fn()} />,
{
actions: [
setConfig({
classifications: {
1: faker.opossum.classificationEntry(),
},
}),
],
},
);
const classificationIcon = screen.queryByTestId('classification-tooltip');
expect(classificationIcon).not.toBeInTheDocument();
});
it('does render the classification icon for un-configured classifications', () => {
const packageInfo = faker.opossum.packageInfo({ classification: 3 });
renderComponent(
<PackageCard packageInfo={packageInfo} onClick={jest.fn()} />,
{
actions: [
setConfig({
classifications: {
1: faker.opossum.classificationEntry(),
},
}),
],
},
);
const classificationIcon = screen.getByTestId('classification-tooltip');
expect(classificationIcon).toBeVisible();
});
it('does not render the classification icon if classification display is disabled', () => {
const packageInfo = faker.opossum.packageInfo({ classification: 3 });
renderComponent(
<PackageCard packageInfo={packageInfo} onClick={jest.fn()} />,
{
actions: [
setConfig({
classifications: {
1: faker.opossum.classificationEntry(),
},
}),
setUserSetting({ showClassifications: false }),
],
},
);
const classificationIcon = screen.queryByTestId('classification-tooltip');
expect(classificationIcon).not.toBeInTheDocument();
});
});
describe('criticality icon', () => {
[Criticality.Medium, Criticality.High].forEach((criticality) => {
it(`renders the criticality icon for criticality ${RawCriticality[criticality]}`, () => {
const packageInfo = faker.opossum.packageInfo({
criticality,
});
renderComponent(
<PackageCard packageInfo={packageInfo} onClick={jest.fn()} />,
);
const criticalityIcon = screen.getByLabelText('Criticality icon');
expect(criticalityIcon).toBeVisible();
});
});
it('does not render the criticality icon for criticality none', () => {
const packageInfo = faker.opossum.packageInfo({
criticality: Criticality.None,
});
renderComponent(
<PackageCard packageInfo={packageInfo} onClick={jest.fn()} />,
);
const criticalityIcon = screen.queryByLabelText('Criticality icon');
expect(criticalityIcon).not.toBeInTheDocument();
});
it('does not render the criticality icon if disabled', () => {
const packageInfo = faker.opossum.packageInfo({
criticality: Criticality.High,
});
renderComponent(
<PackageCard packageInfo={packageInfo} onClick={jest.fn()} />,
{ actions: [setUserSetting({ showCriticality: false })] },
);
const criticalityIcon = screen.queryByLabelText('Criticality icon');
expect(criticalityIcon).not.toBeInTheDocument();
});
});
});