@openshift-migration-advisor/shared-components 0.27.0 → 0.28.0-09381b4d22e5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/charts/MigrationDonutChart.d.ts.map +1 -1
- package/dist/charts/MigrationDonutChart.js +7 -0
- package/dist/report/ChartExportProvider.d.ts +4 -3
- package/dist/report/ChartExportProvider.d.ts.map +1 -1
- package/dist/report/ChartExportProvider.js +7 -4
- package/dist/report/ClustersOverview.d.ts +24 -0
- package/dist/report/ClustersOverview.d.ts.map +1 -0
- package/dist/report/ClustersOverview.js +228 -0
- package/dist/report/ClustersOverviewStyles.d.ts +12 -0
- package/dist/report/ClustersOverviewStyles.d.ts.map +1 -0
- package/dist/report/ClustersOverviewStyles.js +101 -0
- package/dist/report/CpuAndMemoryOverview.d.ts +19 -0
- package/dist/report/CpuAndMemoryOverview.d.ts.map +1 -0
- package/dist/report/CpuAndMemoryOverview.js +112 -0
- package/dist/report/FeatureStatusBadge.js +1 -1
- package/dist/report/ReportExportMenu.d.ts +1 -0
- package/dist/report/ReportExportMenu.d.ts.map +1 -1
- package/dist/report/ReportExportMenu.js +38 -4
- package/dist/report/StorageOverview.d.ts +27 -0
- package/dist/report/StorageOverview.d.ts.map +1 -0
- package/dist/report/StorageOverview.js +319 -0
- package/dist/report/VMMigrationStatus.d.ts +33 -0
- package/dist/report/VMMigrationStatus.d.ts.map +1 -0
- package/dist/report/VMMigrationStatus.js +129 -0
- package/dist/report/captureChartElement.d.ts +6 -1
- package/dist/report/captureChartElement.d.ts.map +1 -1
- package/dist/report/captureChartElement.js +41 -12
- package/dist/report/chartExport.d.ts +23 -0
- package/dist/report/chartExport.d.ts.map +1 -1
- package/dist/report/chartExport.js +21 -1
- package/dist/report/chartExportContext.d.ts +6 -2
- package/dist/report/chartExportContext.d.ts.map +1 -1
- package/dist/report/dashboardStyles.d.ts +6 -0
- package/dist/report/dashboardStyles.d.ts.map +1 -1
- package/dist/report/dashboardStyles.js +7 -4
- package/dist/report/index.d.ts +7 -3
- package/dist/report/index.d.ts.map +1 -1
- package/dist/report/index.js +4 -0
- package/dist/report/pdfExport.d.ts +2 -2
- package/dist/report/pdfExport.d.ts.map +1 -1
- package/dist/report/pdfExport.js +52 -3
- package/dist/report/reportExportOptions.d.ts +13 -2
- package/dist/report/reportExportOptions.d.ts.map +1 -1
- package/dist/report/reportExportOptions.js +13 -5
- package/package.json +2 -2
- package/src/charts/MigrationDonutChart.tsx +9 -0
- package/src/report/ChartExportProvider.tsx +18 -6
- package/src/report/ClustersOverview.tsx +451 -0
- package/src/report/ClustersOverviewStyles.ts +110 -0
- package/src/report/CpuAndMemoryOverview.tsx +277 -0
- package/src/report/FeatureStatusBadge.tsx +1 -1
- package/src/report/ReportExportMenu.tsx +69 -13
- package/src/report/StorageOverview.tsx +629 -0
- package/src/report/VMMigrationStatus.tsx +358 -0
- package/src/report/__tests__/ChartExportProvider.test.tsx +110 -2
- package/src/report/__tests__/ClustersOverview.test.tsx +241 -0
- package/src/report/__tests__/CpuAndMemoryOverview.test.tsx +200 -0
- package/src/report/__tests__/StorageOverview.test.tsx +223 -0
- package/src/report/__tests__/VMMigrationStatus.test.tsx +178 -0
- package/src/report/__tests__/captureChartElement.test.ts +120 -0
- package/src/report/__tests__/chartExportPackagers.test.ts +75 -0
- package/src/report/captureChartElement.ts +55 -10
- package/src/report/chartExport.ts +41 -1
- package/src/report/chartExportContext.tsx +9 -1
- package/src/report/dashboardStyles.ts +7 -4
- package/src/report/index.ts +24 -0
- package/src/report/pdfExport.ts +81 -2
- package/src/report/reportExportOptions.ts +28 -5
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { css } from "@emotion/css";
|
|
2
|
+
import {
|
|
3
|
+
Card,
|
|
4
|
+
CardBody,
|
|
5
|
+
CardTitle,
|
|
6
|
+
Content,
|
|
7
|
+
Dropdown,
|
|
8
|
+
DropdownItem,
|
|
9
|
+
DropdownList,
|
|
10
|
+
Flex,
|
|
11
|
+
FlexItem,
|
|
12
|
+
MenuToggle,
|
|
13
|
+
type MenuToggleElement,
|
|
14
|
+
} from "@patternfly/react-core";
|
|
15
|
+
import { VirtualMachineIcon } from "@patternfly/react-icons";
|
|
16
|
+
import {
|
|
17
|
+
chart_color_blue_300,
|
|
18
|
+
chart_color_purple_100,
|
|
19
|
+
chart_color_purple_300,
|
|
20
|
+
chart_color_teal_200,
|
|
21
|
+
chart_color_yellow_400,
|
|
22
|
+
} from "@patternfly/react-tokens";
|
|
23
|
+
import type { FC, Ref } from "react";
|
|
24
|
+
import { useMemo, useState } from "react";
|
|
25
|
+
import {
|
|
26
|
+
MigrationDonutChart,
|
|
27
|
+
type MigrationDonutChartLegendVariant,
|
|
28
|
+
} from "../charts/MigrationDonutChart.js";
|
|
29
|
+
import { CardEmptyState } from "./CardEmptyState.js";
|
|
30
|
+
import { ChartHeaderActions } from "./ChartDownloadButton.js";
|
|
31
|
+
import { ChartExportSurface } from "./ChartExportSurface.js";
|
|
32
|
+
import { chartExportViewsFromLabels } from "./chartExport.js";
|
|
33
|
+
import {
|
|
34
|
+
chartColorFailure,
|
|
35
|
+
chartColorSuccess,
|
|
36
|
+
REPORT_CARD_EMPTY_STATE_TITLES,
|
|
37
|
+
} from "./constants.js";
|
|
38
|
+
import { dashboardStyles } from "./dashboardStyles.js";
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* VM-issue counts this card reads. agent-sdk's `IssuesBreakdown` satisfies it;
|
|
42
|
+
* each field stays optional so older or partial payloads do not throw.
|
|
43
|
+
*/
|
|
44
|
+
export interface IssuesBreakdownLike {
|
|
45
|
+
critical?: number;
|
|
46
|
+
error?: number;
|
|
47
|
+
warning?: number;
|
|
48
|
+
information?: number;
|
|
49
|
+
advisory?: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface VMMigrationStatusProps {
|
|
53
|
+
data: {
|
|
54
|
+
migratable: number;
|
|
55
|
+
nonMigratable: number;
|
|
56
|
+
};
|
|
57
|
+
issuesBreakdown?: IssuesBreakdownLike;
|
|
58
|
+
/**
|
|
59
|
+
* Donut-slice click. `true` for the migratable slice, `false` otherwise.
|
|
60
|
+
* Agent-ui maps it to a VM migration-readiness filter; ui-app omits it.
|
|
61
|
+
*/
|
|
62
|
+
onReadinessSelect?: (isMigratable: boolean) => void;
|
|
63
|
+
/** Breakdown-bar click. The argument is the concern category label. */
|
|
64
|
+
onCategorySelect?: (category: string) => void;
|
|
65
|
+
/** Center-title click. Agent-ui opens the VM list with no extra filters. */
|
|
66
|
+
onTitleClick?: () => void;
|
|
67
|
+
/** `"html"` in agent-ui; ui-app passes `"chart"`. */
|
|
68
|
+
legendVariant?: MigrationDonutChartLegendVariant;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
type ViewMode = "issuesVsNoIssues" | "issuesBreakdown";
|
|
72
|
+
|
|
73
|
+
const VIEW_MODE_LABELS: Record<ViewMode, string> = {
|
|
74
|
+
issuesVsNoIssues: "No issues vs with issues",
|
|
75
|
+
issuesBreakdown: "With issues breakdown",
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const CHART_ID = "vm-migration-status";
|
|
79
|
+
const CHART_TITLE = "VM migration status";
|
|
80
|
+
|
|
81
|
+
const MIGRATABLE_LABEL = "Migratable";
|
|
82
|
+
const NOT_MIGRATABLE_LABEL = "Not ready for migration";
|
|
83
|
+
|
|
84
|
+
const CATEGORY_ORDER: Array<{ label: string; key: keyof IssuesBreakdownLike }> =
|
|
85
|
+
[
|
|
86
|
+
{ label: "Critical", key: "critical" },
|
|
87
|
+
{ label: "Error", key: "error" },
|
|
88
|
+
{ label: "Warning", key: "warning" },
|
|
89
|
+
{ label: "Information", key: "information" },
|
|
90
|
+
{ label: "Advisory", key: "advisory" },
|
|
91
|
+
];
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Same categorical order as the previous breakdown hex palette, mapped onto
|
|
95
|
+
* PatternFly `chart_color_*` tokens (nearest token where the old hex was not
|
|
96
|
+
* itself a token).
|
|
97
|
+
*/
|
|
98
|
+
const CATEGORY_COLORS: Record<string, string> = {
|
|
99
|
+
Critical: chart_color_blue_300.value,
|
|
100
|
+
Error: chart_color_purple_300.value,
|
|
101
|
+
Warning: chart_color_purple_100.value,
|
|
102
|
+
Information: chart_color_teal_200.value,
|
|
103
|
+
Advisory: chart_color_yellow_400.value,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const menuToggleMinWidth = css`
|
|
107
|
+
min-width: 250px;
|
|
108
|
+
`;
|
|
109
|
+
|
|
110
|
+
const isViewMode = (value: string | number | undefined): value is ViewMode =>
|
|
111
|
+
value === "issuesVsNoIssues" || value === "issuesBreakdown";
|
|
112
|
+
|
|
113
|
+
const toCount = (value: number | undefined): number =>
|
|
114
|
+
typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
115
|
+
|
|
116
|
+
export const VMMigrationStatus: FC<VMMigrationStatusProps> = ({
|
|
117
|
+
data,
|
|
118
|
+
issuesBreakdown,
|
|
119
|
+
onReadinessSelect,
|
|
120
|
+
onCategorySelect,
|
|
121
|
+
onTitleClick,
|
|
122
|
+
legendVariant = "html",
|
|
123
|
+
}) => {
|
|
124
|
+
const [viewMode, setViewMode] = useState<ViewMode>("issuesVsNoIssues");
|
|
125
|
+
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
|
|
126
|
+
|
|
127
|
+
const totalVMs = data.migratable + data.nonMigratable;
|
|
128
|
+
|
|
129
|
+
const donutData = [
|
|
130
|
+
{
|
|
131
|
+
name: MIGRATABLE_LABEL,
|
|
132
|
+
count: data.migratable,
|
|
133
|
+
countDisplay: `${data.migratable} VMs`,
|
|
134
|
+
legendCategory: MIGRATABLE_LABEL,
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: NOT_MIGRATABLE_LABEL,
|
|
138
|
+
count: data.nonMigratable,
|
|
139
|
+
countDisplay: `${data.nonMigratable} VMs`,
|
|
140
|
+
legendCategory: NOT_MIGRATABLE_LABEL,
|
|
141
|
+
},
|
|
142
|
+
];
|
|
143
|
+
|
|
144
|
+
const legend = {
|
|
145
|
+
[MIGRATABLE_LABEL]: chartColorSuccess,
|
|
146
|
+
[NOT_MIGRATABLE_LABEL]: chartColorFailure,
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const breakdownData = useMemo(() => {
|
|
150
|
+
if (!issuesBreakdown) {
|
|
151
|
+
return [];
|
|
152
|
+
}
|
|
153
|
+
return CATEGORY_ORDER.map(({ label, key }) => ({
|
|
154
|
+
name: label,
|
|
155
|
+
count: toCount(issuesBreakdown[key]),
|
|
156
|
+
}));
|
|
157
|
+
}, [issuesBreakdown]);
|
|
158
|
+
|
|
159
|
+
const maxCount = useMemo(
|
|
160
|
+
() =>
|
|
161
|
+
breakdownData.length > 0
|
|
162
|
+
? Math.max(...breakdownData.map((d) => d.count))
|
|
163
|
+
: 0,
|
|
164
|
+
[breakdownData],
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
const chartTitle = `${CHART_TITLE} — ${VIEW_MODE_LABELS[viewMode]}`;
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<ChartExportSurface
|
|
171
|
+
id={CHART_ID}
|
|
172
|
+
title={chartTitle}
|
|
173
|
+
exportViews={chartExportViewsFromLabels(CHART_TITLE, VIEW_MODE_LABELS)}
|
|
174
|
+
activeExportViewId={viewMode}
|
|
175
|
+
onExportViewChange={(viewId) => {
|
|
176
|
+
if (isViewMode(viewId)) {
|
|
177
|
+
setViewMode(viewId);
|
|
178
|
+
}
|
|
179
|
+
}}
|
|
180
|
+
>
|
|
181
|
+
<Card className={dashboardStyles.card}>
|
|
182
|
+
<CardTitle>
|
|
183
|
+
<Flex
|
|
184
|
+
alignItems={{ default: "alignItemsCenter" }}
|
|
185
|
+
justifyContent={{ default: "justifyContentSpaceBetween" }}
|
|
186
|
+
>
|
|
187
|
+
<FlexItem>
|
|
188
|
+
<VirtualMachineIcon /> VM Migration Status
|
|
189
|
+
</FlexItem>
|
|
190
|
+
<ChartHeaderActions chartId={CHART_ID} title={chartTitle}>
|
|
191
|
+
<Dropdown
|
|
192
|
+
isOpen={isDropdownOpen}
|
|
193
|
+
onSelect={(_event, value) => {
|
|
194
|
+
if (isViewMode(value)) {
|
|
195
|
+
setViewMode(value);
|
|
196
|
+
}
|
|
197
|
+
setIsDropdownOpen(false);
|
|
198
|
+
}}
|
|
199
|
+
onOpenChange={setIsDropdownOpen}
|
|
200
|
+
toggle={(toggleRef: Ref<MenuToggleElement>) => (
|
|
201
|
+
<MenuToggle
|
|
202
|
+
ref={toggleRef}
|
|
203
|
+
onClick={() => setIsDropdownOpen((open) => !open)}
|
|
204
|
+
isExpanded={isDropdownOpen}
|
|
205
|
+
className={menuToggleMinWidth}
|
|
206
|
+
>
|
|
207
|
+
{VIEW_MODE_LABELS[viewMode]}
|
|
208
|
+
</MenuToggle>
|
|
209
|
+
)}
|
|
210
|
+
>
|
|
211
|
+
<DropdownList>
|
|
212
|
+
<DropdownItem value="issuesVsNoIssues" key="issuesVsNoIssues">
|
|
213
|
+
{VIEW_MODE_LABELS.issuesVsNoIssues}
|
|
214
|
+
</DropdownItem>
|
|
215
|
+
<DropdownItem value="issuesBreakdown" key="issuesBreakdown">
|
|
216
|
+
{VIEW_MODE_LABELS.issuesBreakdown}
|
|
217
|
+
</DropdownItem>
|
|
218
|
+
</DropdownList>
|
|
219
|
+
</Dropdown>
|
|
220
|
+
</ChartHeaderActions>
|
|
221
|
+
</Flex>
|
|
222
|
+
</CardTitle>
|
|
223
|
+
<CardBody className={dashboardStyles.cardBodyScrollable}>
|
|
224
|
+
{viewMode === "issuesVsNoIssues" ? (
|
|
225
|
+
totalVMs === 0 ? (
|
|
226
|
+
<CardEmptyState
|
|
227
|
+
title={REPORT_CARD_EMPTY_STATE_TITLES.migrationStatus}
|
|
228
|
+
/>
|
|
229
|
+
) : (
|
|
230
|
+
<MigrationDonutChart
|
|
231
|
+
legendVariant={legendVariant}
|
|
232
|
+
data={donutData}
|
|
233
|
+
legend={legend}
|
|
234
|
+
height={300}
|
|
235
|
+
width={420}
|
|
236
|
+
donutThickness={18}
|
|
237
|
+
padAngle={1}
|
|
238
|
+
title={`${totalVMs}`}
|
|
239
|
+
subTitle="VMs"
|
|
240
|
+
subTitleColor="var(--pf-t--global--text--color--subtle)"
|
|
241
|
+
titleFontSize={34}
|
|
242
|
+
legendLabelFormatter={({ x, countDisplay }) =>
|
|
243
|
+
`${x} (${countDisplay})`
|
|
244
|
+
}
|
|
245
|
+
onItemClick={
|
|
246
|
+
onReadinessSelect
|
|
247
|
+
? (item) =>
|
|
248
|
+
onReadinessSelect(item.name === MIGRATABLE_LABEL)
|
|
249
|
+
: undefined
|
|
250
|
+
}
|
|
251
|
+
onTitleClick={onTitleClick}
|
|
252
|
+
/>
|
|
253
|
+
)
|
|
254
|
+
) : breakdownData.length === 0 ? (
|
|
255
|
+
<CardEmptyState
|
|
256
|
+
title={REPORT_CARD_EMPTY_STATE_TITLES.issuesBreakdown}
|
|
257
|
+
/>
|
|
258
|
+
) : (
|
|
259
|
+
<div>
|
|
260
|
+
<div className={dashboardStyles.storageChartWrapper}>
|
|
261
|
+
<Flex
|
|
262
|
+
direction={{ default: "row" }}
|
|
263
|
+
alignItems={{ default: "alignItemsFlexEnd" }}
|
|
264
|
+
justifyContent={{ default: "justifyContentCenter" }}
|
|
265
|
+
spaceItems={{ default: "spaceItemsMd" }}
|
|
266
|
+
style={{
|
|
267
|
+
height: "250px",
|
|
268
|
+
width: "100%",
|
|
269
|
+
}}
|
|
270
|
+
>
|
|
271
|
+
{breakdownData.map((item) => {
|
|
272
|
+
const heightPercentage =
|
|
273
|
+
maxCount > 0 ? (item.count / maxCount) * 100 : 0;
|
|
274
|
+
const minHeightPercentage = item.count > 0 ? 20 : 0;
|
|
275
|
+
const finalHeightPercentage = Math.max(
|
|
276
|
+
heightPercentage,
|
|
277
|
+
minHeightPercentage,
|
|
278
|
+
);
|
|
279
|
+
const barColor =
|
|
280
|
+
CATEGORY_COLORS[item.name] || CATEGORY_COLORS.Critical;
|
|
281
|
+
|
|
282
|
+
return (
|
|
283
|
+
<Flex
|
|
284
|
+
key={item.name}
|
|
285
|
+
direction={{ default: "column" }}
|
|
286
|
+
alignItems={{ default: "alignItemsCenter" }}
|
|
287
|
+
spaceItems={{ default: "spaceItemsSm" }}
|
|
288
|
+
style={{ flex: "1", maxWidth: "120px" }}
|
|
289
|
+
>
|
|
290
|
+
<FlexItem
|
|
291
|
+
style={{
|
|
292
|
+
height: "200px",
|
|
293
|
+
display: "flex",
|
|
294
|
+
alignItems: "flex-end",
|
|
295
|
+
width: "100%",
|
|
296
|
+
justifyContent: "center",
|
|
297
|
+
}}
|
|
298
|
+
>
|
|
299
|
+
<button
|
|
300
|
+
type="button"
|
|
301
|
+
onClick={() => onCategorySelect?.(item.name)}
|
|
302
|
+
title={`${item.name}: ${item.count} VMs`}
|
|
303
|
+
style={{
|
|
304
|
+
width: "60px",
|
|
305
|
+
height: `${finalHeightPercentage}%`,
|
|
306
|
+
backgroundColor: barColor,
|
|
307
|
+
transition: "height 0.3s ease",
|
|
308
|
+
borderRadius: "4px 4px 0 0",
|
|
309
|
+
cursor: "pointer",
|
|
310
|
+
border: "none",
|
|
311
|
+
padding: 0,
|
|
312
|
+
}}
|
|
313
|
+
/>
|
|
314
|
+
</FlexItem>
|
|
315
|
+
<FlexItem>
|
|
316
|
+
<Content
|
|
317
|
+
component="small"
|
|
318
|
+
style={{
|
|
319
|
+
fontSize: "12px",
|
|
320
|
+
textAlign: "center",
|
|
321
|
+
wordBreak: "break-word",
|
|
322
|
+
color:
|
|
323
|
+
"var(--pf-t--global--text--color--regular)",
|
|
324
|
+
}}
|
|
325
|
+
>
|
|
326
|
+
{item.name}
|
|
327
|
+
<br />({item.count} VMs)
|
|
328
|
+
</Content>
|
|
329
|
+
</FlexItem>
|
|
330
|
+
</Flex>
|
|
331
|
+
);
|
|
332
|
+
})}
|
|
333
|
+
</Flex>
|
|
334
|
+
</div>
|
|
335
|
+
<div>
|
|
336
|
+
<Content
|
|
337
|
+
component="small"
|
|
338
|
+
style={{
|
|
339
|
+
fontSize: "12px",
|
|
340
|
+
color: "var(--pf-t--global--text--color--subtle)",
|
|
341
|
+
marginTop: "16px",
|
|
342
|
+
textAlign: "center",
|
|
343
|
+
display: "block",
|
|
344
|
+
}}
|
|
345
|
+
>
|
|
346
|
+
Totals may exceed the unique VM count because a VM can appear
|
|
347
|
+
in multiple categories
|
|
348
|
+
</Content>
|
|
349
|
+
</div>
|
|
350
|
+
</div>
|
|
351
|
+
)}
|
|
352
|
+
</CardBody>
|
|
353
|
+
</Card>
|
|
354
|
+
</ChartExportSurface>
|
|
355
|
+
);
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
VMMigrationStatus.displayName = "VMMigrationStatus";
|
|
@@ -101,12 +101,18 @@ function DownloadChartButton({ id }: { id: string }): JSX.Element {
|
|
|
101
101
|
);
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
function DownloadPdfButton(
|
|
104
|
+
function DownloadPdfButton({
|
|
105
|
+
extraPages,
|
|
106
|
+
}: {
|
|
107
|
+
extraPages?: Parameters<
|
|
108
|
+
NonNullable<ReturnType<typeof useChartExport>>["downloadPdf"]
|
|
109
|
+
>[1];
|
|
110
|
+
}): JSX.Element {
|
|
105
111
|
const exportApi = useChartExport();
|
|
106
112
|
return (
|
|
107
113
|
<button
|
|
108
114
|
type="button"
|
|
109
|
-
onClick={() => void exportApi?.downloadPdf("Overview")}
|
|
115
|
+
onClick={() => void exportApi?.downloadPdf("Overview", extraPages)}
|
|
110
116
|
>
|
|
111
117
|
Download pdf
|
|
112
118
|
</button>
|
|
@@ -181,6 +187,46 @@ describe("ChartExportProvider", () => {
|
|
|
181
187
|
expect(downloadFile).toHaveBeenCalledWith(expect.any(Blob), "disks.png");
|
|
182
188
|
});
|
|
183
189
|
|
|
190
|
+
it("does not change the live theme while exporting", async () => {
|
|
191
|
+
const user = userEvent.setup();
|
|
192
|
+
document.documentElement.classList.add("pf-v6-theme-dark");
|
|
193
|
+
const capture = vi.fn(async () => {
|
|
194
|
+
expect(
|
|
195
|
+
document.documentElement.classList.contains("pf-v6-theme-dark"),
|
|
196
|
+
).toBe(true);
|
|
197
|
+
return fakeCanvas();
|
|
198
|
+
});
|
|
199
|
+
const downloadFile = vi.fn();
|
|
200
|
+
|
|
201
|
+
render(
|
|
202
|
+
<ChartExportProvider
|
|
203
|
+
capture={capture}
|
|
204
|
+
encodePng={async () => new Blob(["png"])}
|
|
205
|
+
zipFiles={async () => new Blob(["zip"])}
|
|
206
|
+
downloadFile={downloadFile}
|
|
207
|
+
getZipFilename={() => "charts.zip"}
|
|
208
|
+
>
|
|
209
|
+
<RegisteredChart id="storage" title="Disks" />
|
|
210
|
+
<DownloadChartButton id="storage" />
|
|
211
|
+
<DownloadAllButton />
|
|
212
|
+
</ChartExportProvider>,
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
await user.click(screen.getByRole("button", { name: "Download storage" }));
|
|
216
|
+
await waitFor(() =>
|
|
217
|
+
expect(downloadFile).toHaveBeenCalledWith(expect.any(Blob), "disks.png"),
|
|
218
|
+
);
|
|
219
|
+
await user.click(screen.getByRole("button", { name: "Download all" }));
|
|
220
|
+
await waitFor(() =>
|
|
221
|
+
expect(downloadFile).toHaveBeenCalledWith(expect.any(Blob), "charts.zip"),
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
expect(
|
|
225
|
+
document.documentElement.classList.contains("pf-v6-theme-dark"),
|
|
226
|
+
).toBe(true);
|
|
227
|
+
document.documentElement.classList.remove("pf-v6-theme-dark");
|
|
228
|
+
});
|
|
229
|
+
|
|
184
230
|
it("re-registers charts after React Strict Mode's extra effect cycle", async () => {
|
|
185
231
|
const user = userEvent.setup();
|
|
186
232
|
const capture = vi.fn(async () => fakeCanvas());
|
|
@@ -236,6 +282,68 @@ describe("ChartExportProvider", () => {
|
|
|
236
282
|
expect(downloadFile).toHaveBeenCalledWith(expect.any(Blob), "report.pdf");
|
|
237
283
|
});
|
|
238
284
|
|
|
285
|
+
it("forwards extra text pages (e.g. cluster sizing recommendations) to the pdf builder", async () => {
|
|
286
|
+
const user = userEvent.setup();
|
|
287
|
+
const capture = vi.fn(async () => fakeCanvas());
|
|
288
|
+
const buildPdf = vi.fn(async () => new Blob(["pdf"]));
|
|
289
|
+
const downloadFile = vi.fn();
|
|
290
|
+
const extraPages = [
|
|
291
|
+
{
|
|
292
|
+
title: "Cluster sizing recommendations",
|
|
293
|
+
items: [
|
|
294
|
+
{ label: "Cluster name", value: "cluster-1" },
|
|
295
|
+
{ label: "Target platform", value: "Bare metal" },
|
|
296
|
+
],
|
|
297
|
+
footer: "Note: estimates only.",
|
|
298
|
+
},
|
|
299
|
+
];
|
|
300
|
+
|
|
301
|
+
render(
|
|
302
|
+
<ChartExportProvider
|
|
303
|
+
capture={capture}
|
|
304
|
+
zipFiles={vi.fn()}
|
|
305
|
+
buildPdf={buildPdf}
|
|
306
|
+
downloadFile={downloadFile}
|
|
307
|
+
getPdfFilename={() => "report.pdf"}
|
|
308
|
+
>
|
|
309
|
+
<RegisteredChart id="storage" title="Disks" />
|
|
310
|
+
<DownloadPdfButton extraPages={extraPages} />
|
|
311
|
+
</ChartExportProvider>,
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
await user.click(screen.getByRole("button", { name: "Download pdf" }));
|
|
315
|
+
|
|
316
|
+
expect(buildPdf).toHaveBeenCalledTimes(1);
|
|
317
|
+
expect(buildPdf.mock.calls[0]?.[2]).toEqual(extraPages);
|
|
318
|
+
expect(downloadFile).toHaveBeenCalledWith(expect.any(Blob), "report.pdf");
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it("builds a PDF from extra text pages alone when no charts are registered", async () => {
|
|
322
|
+
const user = userEvent.setup();
|
|
323
|
+
const buildPdf = vi.fn(async () => new Blob(["pdf"]));
|
|
324
|
+
const downloadFile = vi.fn();
|
|
325
|
+
const extraPages = [{ title: "Cluster sizing recommendations", items: [] }];
|
|
326
|
+
|
|
327
|
+
render(
|
|
328
|
+
<ChartExportProvider
|
|
329
|
+
capture={vi.fn()}
|
|
330
|
+
zipFiles={vi.fn()}
|
|
331
|
+
buildPdf={buildPdf}
|
|
332
|
+
downloadFile={downloadFile}
|
|
333
|
+
getPdfFilename={() => "report.pdf"}
|
|
334
|
+
>
|
|
335
|
+
<DownloadPdfButton extraPages={extraPages} />
|
|
336
|
+
</ChartExportProvider>,
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
await user.click(screen.getByRole("button", { name: "Download pdf" }));
|
|
340
|
+
|
|
341
|
+
expect(buildPdf).toHaveBeenCalledTimes(1);
|
|
342
|
+
expect(buildPdf.mock.calls[0]?.[0]).toEqual([]);
|
|
343
|
+
expect(buildPdf.mock.calls[0]?.[2]).toEqual(extraPages);
|
|
344
|
+
expect(downloadFile).toHaveBeenCalledWith(expect.any(Blob), "report.pdf");
|
|
345
|
+
});
|
|
346
|
+
|
|
239
347
|
it("builds HTML from the same captured canvases", async () => {
|
|
240
348
|
const user = userEvent.setup();
|
|
241
349
|
const capture = vi.fn(async () => fakeCanvas());
|