@openshift-migration-advisor/shared-components 0.24.0 → 0.25.0-6fd4e1ee8e11
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/README.md +31 -0
- package/dist/charts/index.d.ts +1 -1
- package/dist/charts/index.d.ts.map +1 -1
- package/dist/forms/RadioButtonFormGroup.d.ts.map +1 -1
- package/dist/forms/RadioButtonFormGroup.js +2 -2
- package/dist/report/ChartDownloadButton.d.ts +11 -0
- package/dist/report/ChartDownloadButton.d.ts.map +1 -0
- package/dist/report/ChartDownloadButton.js +24 -0
- package/dist/report/ChartExportProvider.d.ts +22 -0
- package/dist/report/ChartExportProvider.d.ts.map +1 -0
- package/dist/report/ChartExportProvider.js +222 -0
- package/dist/report/ChartExportSurface.d.ts +12 -0
- package/dist/report/ChartExportSurface.d.ts.map +1 -0
- package/dist/report/ChartExportSurface.js +32 -0
- package/dist/report/FeatureStatusBadge.d.ts +7 -0
- package/dist/report/FeatureStatusBadge.d.ts.map +1 -0
- package/dist/report/FeatureStatusBadge.js +13 -0
- package/dist/report/HostPowerStates.d.ts +8 -0
- package/dist/report/HostPowerStates.d.ts.map +1 -0
- package/dist/report/HostPowerStates.js +11 -0
- package/dist/report/InfrastructureSummary.d.ts +7 -0
- package/dist/report/InfrastructureSummary.d.ts.map +1 -0
- package/dist/report/InfrastructureSummary.js +9 -0
- package/dist/report/OSDistribution.d.ts +0 -2
- package/dist/report/OSDistribution.d.ts.map +1 -1
- package/dist/report/OSDistribution.js +10 -15
- package/dist/report/OsSupportTiersHelpPopover.d.ts.map +1 -1
- package/dist/report/OsSupportTiersHelpPopover.js +2 -31
- package/dist/report/OsUpgradeNotice.d.ts.map +1 -1
- package/dist/report/OsUpgradeNotice.js +1 -5
- package/dist/report/OsUpgradeRecommendationPopover.d.ts +0 -1
- package/dist/report/OsUpgradeRecommendationPopover.d.ts.map +1 -1
- package/dist/report/OsUpgradeRecommendationPopover.js +4 -3
- package/dist/report/PowerStateCard.d.ts +16 -0
- package/dist/report/PowerStateCard.d.ts.map +1 -0
- package/dist/report/PowerStateCard.js +9 -0
- package/dist/report/ReportExportMenu.d.ts +19 -0
- package/dist/report/ReportExportMenu.d.ts.map +1 -0
- package/dist/report/ReportExportMenu.js +31 -0
- package/dist/report/SupportTierBadge.d.ts +0 -1
- package/dist/report/SupportTierBadge.d.ts.map +1 -1
- package/dist/report/SupportTierBadge.js +1 -19
- package/dist/report/VCenterClusterDetails.d.ts +9 -0
- package/dist/report/VCenterClusterDetails.d.ts.map +1 -0
- package/dist/report/VCenterClusterDetails.js +31 -0
- package/dist/report/VmPowerStates.d.ts +8 -0
- package/dist/report/VmPowerStates.d.ts.map +1 -0
- package/dist/report/VmPowerStates.js +11 -0
- package/dist/report/captureChartElement.d.ts +8 -0
- package/dist/report/captureChartElement.d.ts.map +1 -0
- package/dist/report/captureChartElement.js +284 -0
- package/dist/report/chartExport.d.ts +57 -0
- package/dist/report/chartExport.d.ts.map +1 -0
- package/dist/report/chartExport.js +162 -0
- package/dist/report/chartExportContext.d.ts +28 -0
- package/dist/report/chartExportContext.d.ts.map +1 -0
- package/dist/report/chartExportContext.js +36 -0
- package/dist/report/chartExportFilenames.d.ts +4 -0
- package/dist/report/chartExportFilenames.d.ts.map +1 -0
- package/dist/report/chartExportFilenames.js +16 -0
- package/dist/report/constants.d.ts +2 -0
- package/dist/report/constants.d.ts.map +1 -1
- package/dist/report/constants.js +2 -0
- package/dist/report/dashboardStyles.d.ts +0 -4
- package/dist/report/dashboardStyles.d.ts.map +1 -1
- package/dist/report/dashboardStyles.js +0 -19
- package/dist/report/htmlExport.d.ts +9 -0
- package/dist/report/htmlExport.d.ts.map +1 -0
- package/dist/report/htmlExport.js +65 -0
- package/dist/report/index.d.ts +23 -0
- package/dist/report/index.d.ts.map +1 -1
- package/dist/report/index.js +21 -0
- package/dist/report/infrastructureSummaryModel.d.ts +82 -0
- package/dist/report/infrastructureSummaryModel.d.ts.map +1 -0
- package/dist/report/infrastructureSummaryModel.js +139 -0
- package/dist/report/pdfExport.d.ts +3 -0
- package/dist/report/pdfExport.d.ts.map +1 -0
- package/dist/report/pdfExport.js +82 -0
- package/dist/report/pdfPage.d.ts +15 -0
- package/dist/report/pdfPage.d.ts.map +1 -0
- package/dist/report/pdfPage.js +44 -0
- package/dist/report/powerStates.d.ts +11 -0
- package/dist/report/powerStates.d.ts.map +1 -0
- package/dist/report/powerStates.js +113 -0
- package/dist/report/reportExportOptions.d.ts +17 -0
- package/dist/report/reportExportOptions.d.ts.map +1 -0
- package/dist/report/reportExportOptions.js +31 -0
- package/dist/report/zipChartPngs.d.ts +3 -0
- package/dist/report/zipChartPngs.d.ts.map +1 -0
- package/dist/report/zipChartPngs.js +8 -0
- package/package.json +7 -2
- package/src/charts/index.ts +1 -0
- package/src/forms/RadioButtonFormGroup.tsx +10 -3
- package/src/report/ChartDownloadButton.tsx +59 -0
- package/src/report/ChartExportProvider.tsx +384 -0
- package/src/report/ChartExportSurface.tsx +60 -0
- package/src/report/FeatureStatusBadge.tsx +30 -0
- package/src/report/HostPowerStates.tsx +38 -0
- package/src/report/InfrastructureSummary.tsx +73 -0
- package/src/report/OSDistribution.tsx +96 -99
- package/src/report/OsSupportTiersHelpPopover.tsx +32 -62
- package/src/report/OsUpgradeNotice.tsx +1 -7
- package/src/report/OsUpgradeRecommendationPopover.tsx +3 -4
- package/src/report/PowerStateCard.tsx +86 -0
- package/src/report/ReportExportMenu.tsx +119 -0
- package/src/report/SupportTierBadge.tsx +12 -38
- package/src/report/VCenterClusterDetails.tsx +233 -0
- package/src/report/VmPowerStates.tsx +38 -0
- package/src/report/__tests__/ChartExportProvider.test.tsx +474 -0
- package/src/report/__tests__/HostPowerStates.test.tsx +47 -0
- package/src/report/__tests__/InfrastructureSummary.test.tsx +126 -0
- package/src/report/__tests__/OSDistribution.test.tsx +10 -11
- package/src/report/__tests__/captureChartElement.test.ts +132 -0
- package/src/report/__tests__/chartExportPackagers.test.ts +224 -0
- package/src/report/__tests__/infrastructureSummaryModel.test.ts +224 -0
- package/src/report/__tests__/powerStates.test.ts +70 -0
- package/src/report/captureChartElement.ts +368 -0
- package/src/report/chartExport.ts +237 -0
- package/src/report/chartExportContext.tsx +84 -0
- package/src/report/chartExportFilenames.ts +21 -0
- package/src/report/constants.ts +2 -0
- package/src/report/dashboardStyles.ts +0 -23
- package/src/report/htmlExport.ts +83 -0
- package/src/report/index.ts +128 -0
- package/src/report/infrastructureSummaryModel.ts +281 -0
- package/src/report/pdfExport.ts +154 -0
- package/src/report/pdfPage.ts +83 -0
- package/src/report/powerStates.ts +169 -0
- package/src/report/reportExportOptions.ts +53 -0
- package/src/report/zipChartPngs.ts +10 -0
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
import "@testing-library/jest-dom";
|
|
2
|
+
import { cleanup, render, screen, waitFor } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { ChartExportProvider, useChartExport } from "../ChartExportProvider.js";
|
|
7
|
+
import { ChartExportSurface } from "../ChartExportSurface.js";
|
|
8
|
+
import {
|
|
9
|
+
CHART_EXPORT_HIDE_ATTR,
|
|
10
|
+
chartPngFilename,
|
|
11
|
+
shouldIgnoreChartExportElement,
|
|
12
|
+
slugifyExportName,
|
|
13
|
+
} from "../chartExport.js";
|
|
14
|
+
import { useRegisterChart } from "../chartExportContext.js";
|
|
15
|
+
import { HostPowerStates } from "../HostPowerStates.js";
|
|
16
|
+
import { ExportReportButton, ReportExportMenu } from "../ReportExportMenu.js";
|
|
17
|
+
import { standardReportExportOptions } from "../reportExportOptions.js";
|
|
18
|
+
|
|
19
|
+
vi.mock("../../charts/MigrationDonutChart.js", () => ({
|
|
20
|
+
MigrationDonutChart: ({
|
|
21
|
+
title,
|
|
22
|
+
subTitle,
|
|
23
|
+
}: {
|
|
24
|
+
title?: string;
|
|
25
|
+
subTitle?: string;
|
|
26
|
+
}): JSX.Element => (
|
|
27
|
+
<div data-testid="power-donut">
|
|
28
|
+
{title} {subTitle}
|
|
29
|
+
</div>
|
|
30
|
+
),
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
afterEach(() => cleanup());
|
|
34
|
+
|
|
35
|
+
function RegisteredChart({
|
|
36
|
+
id,
|
|
37
|
+
title,
|
|
38
|
+
}: {
|
|
39
|
+
id: string;
|
|
40
|
+
title: string;
|
|
41
|
+
}): JSX.Element {
|
|
42
|
+
const ref = useRegisterChart({ id, title });
|
|
43
|
+
return (
|
|
44
|
+
<div ref={ref} data-testid={`chart-${id}`}>
|
|
45
|
+
{title}
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function DownloadAllButton(): JSX.Element {
|
|
51
|
+
const exportApi = useChartExport();
|
|
52
|
+
return (
|
|
53
|
+
<button type="button" onClick={() => void exportApi?.downloadAll()}>
|
|
54
|
+
Download all
|
|
55
|
+
</button>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
describe("chart export names", () => {
|
|
60
|
+
it("slugifies titles for PNG filenames", () => {
|
|
61
|
+
expect(slugifyExportName("CPU & memory")).toBe("cpu-memory");
|
|
62
|
+
expect(chartPngFilename("CPU & memory", "cpu")).toBe("cpu-memory.png");
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe("shouldIgnoreChartExportElement", () => {
|
|
67
|
+
it("keeps the capture root and skips sibling cards", () => {
|
|
68
|
+
const page = document.createElement("div");
|
|
69
|
+
const card = document.createElement("div");
|
|
70
|
+
const sibling = document.createElement("div");
|
|
71
|
+
page.append(card, sibling);
|
|
72
|
+
|
|
73
|
+
expect(shouldIgnoreChartExportElement(card, card)).toBe(false);
|
|
74
|
+
expect(shouldIgnoreChartExportElement(sibling, card)).toBe(true);
|
|
75
|
+
expect(shouldIgnoreChartExportElement(page, card)).toBe(false);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("skips chrome marked for export hide inside the card", () => {
|
|
79
|
+
const card = document.createElement("div");
|
|
80
|
+
const hide = document.createElement("button");
|
|
81
|
+
hide.setAttribute(CHART_EXPORT_HIDE_ATTR, "");
|
|
82
|
+
card.append(hide);
|
|
83
|
+
|
|
84
|
+
expect(shouldIgnoreChartExportElement(hide, card)).toBe(true);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
function fakeCanvas(): HTMLCanvasElement {
|
|
89
|
+
const canvas = document.createElement("canvas");
|
|
90
|
+
canvas.width = 10;
|
|
91
|
+
canvas.height = 10;
|
|
92
|
+
return canvas;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function DownloadChartButton({ id }: { id: string }): JSX.Element {
|
|
96
|
+
const exportApi = useChartExport();
|
|
97
|
+
return (
|
|
98
|
+
<button type="button" onClick={() => void exportApi?.downloadChart(id)}>
|
|
99
|
+
Download {id}
|
|
100
|
+
</button>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function DownloadPdfButton(): JSX.Element {
|
|
105
|
+
const exportApi = useChartExport();
|
|
106
|
+
return (
|
|
107
|
+
<button
|
|
108
|
+
type="button"
|
|
109
|
+
onClick={() => void exportApi?.downloadPdf("Overview")}
|
|
110
|
+
>
|
|
111
|
+
Download pdf
|
|
112
|
+
</button>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function DownloadHtmlButton(): JSX.Element {
|
|
117
|
+
const exportApi = useChartExport();
|
|
118
|
+
return (
|
|
119
|
+
<button
|
|
120
|
+
type="button"
|
|
121
|
+
onClick={() => void exportApi?.downloadHtml("Overview")}
|
|
122
|
+
>
|
|
123
|
+
Download html
|
|
124
|
+
</button>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
describe("ChartExportProvider", () => {
|
|
129
|
+
it("snapshots registered live nodes instead of a second chart tree", async () => {
|
|
130
|
+
const user = userEvent.setup();
|
|
131
|
+
const capture = vi.fn(async () => fakeCanvas());
|
|
132
|
+
const encodePng = vi.fn(async () => new Blob(["png"]));
|
|
133
|
+
const zipFiles = vi.fn(
|
|
134
|
+
async (files: { filename: string; blob: Blob }[]) => {
|
|
135
|
+
return new Blob([files.map((file) => file.filename).join(",")]);
|
|
136
|
+
},
|
|
137
|
+
);
|
|
138
|
+
const downloadFile = vi.fn();
|
|
139
|
+
|
|
140
|
+
render(
|
|
141
|
+
<ChartExportProvider
|
|
142
|
+
capture={capture}
|
|
143
|
+
encodePng={encodePng}
|
|
144
|
+
zipFiles={zipFiles}
|
|
145
|
+
downloadFile={downloadFile}
|
|
146
|
+
getZipFilename={() => "charts.zip"}
|
|
147
|
+
>
|
|
148
|
+
<RegisteredChart id="cpu-memory" title="CPU and memory" />
|
|
149
|
+
<RegisteredChart id="storage" title="Disks" />
|
|
150
|
+
<DownloadAllButton />
|
|
151
|
+
</ChartExportProvider>,
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
await user.click(screen.getByRole("button", { name: "Download all" }));
|
|
155
|
+
|
|
156
|
+
expect(zipFiles).toHaveBeenCalledTimes(1);
|
|
157
|
+
expect(downloadFile).toHaveBeenCalledWith(expect.any(Blob), "charts.zip");
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("downloads one registered node as a PNG", async () => {
|
|
161
|
+
const user = userEvent.setup();
|
|
162
|
+
const capture = vi.fn(async () => fakeCanvas());
|
|
163
|
+
const encodePng = vi.fn(async () => new Blob(["png"]));
|
|
164
|
+
const downloadFile = vi.fn();
|
|
165
|
+
|
|
166
|
+
render(
|
|
167
|
+
<ChartExportProvider
|
|
168
|
+
capture={capture}
|
|
169
|
+
encodePng={encodePng}
|
|
170
|
+
zipFiles={vi.fn()}
|
|
171
|
+
downloadFile={downloadFile}
|
|
172
|
+
>
|
|
173
|
+
<RegisteredChart id="storage" title="Disks" />
|
|
174
|
+
<DownloadChartButton id="storage" />
|
|
175
|
+
</ChartExportProvider>,
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
await user.click(screen.getByRole("button", { name: "Download storage" }));
|
|
179
|
+
|
|
180
|
+
expect(capture).toHaveBeenCalledTimes(1);
|
|
181
|
+
expect(downloadFile).toHaveBeenCalledWith(expect.any(Blob), "disks.png");
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("re-registers charts after React Strict Mode's extra effect cycle", async () => {
|
|
185
|
+
const user = userEvent.setup();
|
|
186
|
+
const capture = vi.fn(async () => fakeCanvas());
|
|
187
|
+
const encodePng = vi.fn(async () => new Blob(["png"]));
|
|
188
|
+
const downloadFile = vi.fn();
|
|
189
|
+
|
|
190
|
+
render(
|
|
191
|
+
<ChartExportProvider
|
|
192
|
+
capture={capture}
|
|
193
|
+
encodePng={encodePng}
|
|
194
|
+
zipFiles={vi.fn()}
|
|
195
|
+
downloadFile={downloadFile}
|
|
196
|
+
>
|
|
197
|
+
<RegisteredChart id="storage" title="Disks" />
|
|
198
|
+
<DownloadChartButton id="storage" />
|
|
199
|
+
</ChartExportProvider>,
|
|
200
|
+
{ reactStrictMode: true },
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
await user.click(screen.getByRole("button", { name: "Download storage" }));
|
|
204
|
+
|
|
205
|
+
expect(capture).toHaveBeenCalledTimes(1);
|
|
206
|
+
expect(downloadFile).toHaveBeenCalledWith(expect.any(Blob), "disks.png");
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("builds a PDF from the same captured canvases", async () => {
|
|
210
|
+
const user = userEvent.setup();
|
|
211
|
+
const capture = vi.fn(async () => fakeCanvas());
|
|
212
|
+
const buildPdf = vi.fn(async () => new Blob(["pdf"]));
|
|
213
|
+
const downloadFile = vi.fn();
|
|
214
|
+
|
|
215
|
+
render(
|
|
216
|
+
<ChartExportProvider
|
|
217
|
+
capture={capture}
|
|
218
|
+
zipFiles={vi.fn()}
|
|
219
|
+
buildPdf={buildPdf}
|
|
220
|
+
downloadFile={downloadFile}
|
|
221
|
+
getPdfFilename={() => "report.pdf"}
|
|
222
|
+
>
|
|
223
|
+
<RegisteredChart id="storage" title="Disks" />
|
|
224
|
+
<DownloadPdfButton />
|
|
225
|
+
</ChartExportProvider>,
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
await user.click(screen.getByRole("button", { name: "Download pdf" }));
|
|
229
|
+
|
|
230
|
+
expect(buildPdf).toHaveBeenCalledTimes(1);
|
|
231
|
+
expect(buildPdf.mock.calls[0]?.[1]).toBe("Overview");
|
|
232
|
+
expect(buildPdf.mock.calls[0]?.[0][0]).toMatchObject({
|
|
233
|
+
id: "storage",
|
|
234
|
+
title: "Disks",
|
|
235
|
+
});
|
|
236
|
+
expect(downloadFile).toHaveBeenCalledWith(expect.any(Blob), "report.pdf");
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it("builds HTML from the same captured canvases", async () => {
|
|
240
|
+
const user = userEvent.setup();
|
|
241
|
+
const capture = vi.fn(async () => fakeCanvas());
|
|
242
|
+
const buildHtml = vi.fn(async () => new Blob(["html"]));
|
|
243
|
+
const downloadFile = vi.fn();
|
|
244
|
+
|
|
245
|
+
render(
|
|
246
|
+
<ChartExportProvider
|
|
247
|
+
capture={capture}
|
|
248
|
+
zipFiles={vi.fn()}
|
|
249
|
+
buildHtml={buildHtml}
|
|
250
|
+
downloadFile={downloadFile}
|
|
251
|
+
getHtmlFilename={() => "report.html"}
|
|
252
|
+
>
|
|
253
|
+
<RegisteredChart id="storage" title="Disks" />
|
|
254
|
+
<DownloadHtmlButton />
|
|
255
|
+
</ChartExportProvider>,
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
await user.click(screen.getByRole("button", { name: "Download html" }));
|
|
259
|
+
|
|
260
|
+
expect(buildHtml).toHaveBeenCalledTimes(1);
|
|
261
|
+
expect(buildHtml.mock.calls[0]?.[1]).toBe("Overview");
|
|
262
|
+
expect(downloadFile).toHaveBeenCalledWith(expect.any(Blob), "report.html");
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it("captures every dropdown view for PDF, HTML, and zip exports", async () => {
|
|
266
|
+
const user = userEvent.setup();
|
|
267
|
+
const seenViews: string[] = [];
|
|
268
|
+
const capture = vi.fn(async (element: HTMLElement) => {
|
|
269
|
+
seenViews.push(
|
|
270
|
+
element.querySelector("[data-testid='active-view']")?.textContent ?? "",
|
|
271
|
+
);
|
|
272
|
+
return fakeCanvas();
|
|
273
|
+
});
|
|
274
|
+
const encodePng = vi.fn(async () => new Blob(["png"]));
|
|
275
|
+
const zipFiles = vi.fn(
|
|
276
|
+
async (files: { filename: string; blob: Blob }[]) => {
|
|
277
|
+
return new Blob([files.map((file) => file.filename).join(",")]);
|
|
278
|
+
},
|
|
279
|
+
);
|
|
280
|
+
const buildPdf = vi.fn(
|
|
281
|
+
async (
|
|
282
|
+
sources: { title: string; capture: () => Promise<HTMLCanvasElement> }[],
|
|
283
|
+
) => {
|
|
284
|
+
for (const source of sources) {
|
|
285
|
+
await source.capture();
|
|
286
|
+
}
|
|
287
|
+
return new Blob(["pdf"]);
|
|
288
|
+
},
|
|
289
|
+
);
|
|
290
|
+
const downloadFile = vi.fn();
|
|
291
|
+
|
|
292
|
+
function DropdownChart(): JSX.Element {
|
|
293
|
+
const [view, setView] = useState("a");
|
|
294
|
+
return (
|
|
295
|
+
<ChartExportSurface
|
|
296
|
+
id="vm"
|
|
297
|
+
title={view === "a" ? "View A" : "View B"}
|
|
298
|
+
exportViews={[
|
|
299
|
+
{ id: "a", title: "View A" },
|
|
300
|
+
{ id: "b", title: "View B" },
|
|
301
|
+
]}
|
|
302
|
+
activeExportViewId={view}
|
|
303
|
+
onExportViewChange={setView}
|
|
304
|
+
>
|
|
305
|
+
<div data-testid="active-view">{view}</div>
|
|
306
|
+
</ChartExportSurface>
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
render(
|
|
311
|
+
<ChartExportProvider
|
|
312
|
+
capture={capture}
|
|
313
|
+
encodePng={encodePng}
|
|
314
|
+
zipFiles={zipFiles}
|
|
315
|
+
buildPdf={buildPdf}
|
|
316
|
+
downloadFile={downloadFile}
|
|
317
|
+
getZipFilename={() => "charts.zip"}
|
|
318
|
+
getPdfFilename={() => "report.pdf"}
|
|
319
|
+
>
|
|
320
|
+
<DropdownChart />
|
|
321
|
+
<DownloadAllButton />
|
|
322
|
+
<DownloadPdfButton />
|
|
323
|
+
</ChartExportProvider>,
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
await user.click(screen.getByRole("button", { name: "Download all" }));
|
|
327
|
+
await waitFor(() => expect(zipFiles).toHaveBeenCalledTimes(1));
|
|
328
|
+
expect(seenViews).toEqual(["a", "b"]);
|
|
329
|
+
expect(zipFiles.mock.calls[0]?.[0].map((file) => file.filename)).toEqual([
|
|
330
|
+
"01-view-a.png",
|
|
331
|
+
"02-view-b.png",
|
|
332
|
+
]);
|
|
333
|
+
expect(screen.getByTestId("active-view")).toHaveTextContent("a");
|
|
334
|
+
|
|
335
|
+
seenViews.length = 0;
|
|
336
|
+
await user.click(screen.getByRole("button", { name: "Download pdf" }));
|
|
337
|
+
await waitFor(() =>
|
|
338
|
+
expect(downloadFile).toHaveBeenCalledWith(expect.any(Blob), "report.pdf"),
|
|
339
|
+
);
|
|
340
|
+
expect(buildPdf.mock.calls[0]?.[0].map((source) => source.title)).toEqual([
|
|
341
|
+
"View A",
|
|
342
|
+
"View B",
|
|
343
|
+
]);
|
|
344
|
+
expect(seenViews).toEqual(["a", "b"]);
|
|
345
|
+
expect(screen.getByTestId("active-view")).toHaveTextContent("a");
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it("warns when two live charts share an id", () => {
|
|
349
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
350
|
+
|
|
351
|
+
render(
|
|
352
|
+
<ChartExportProvider capture={vi.fn()} zipFiles={vi.fn()}>
|
|
353
|
+
<RegisteredChart id="storage" title="Disks" />
|
|
354
|
+
<RegisteredChart id="storage" title="Disks copy" />
|
|
355
|
+
</ChartExportProvider>,
|
|
356
|
+
);
|
|
357
|
+
|
|
358
|
+
expect(warn).toHaveBeenCalledWith(
|
|
359
|
+
expect.stringContaining('Duplicate chart export id "storage"'),
|
|
360
|
+
);
|
|
361
|
+
warn.mockRestore();
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
it("shows a generic error when capture fails", async () => {
|
|
365
|
+
const user = userEvent.setup();
|
|
366
|
+
vi.spyOn(console, "error").mockImplementation(() => undefined);
|
|
367
|
+
|
|
368
|
+
function ErrorText(): JSX.Element {
|
|
369
|
+
const exportApi = useChartExport();
|
|
370
|
+
return <div>{exportApi?.exportError}</div>;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
render(
|
|
374
|
+
<ChartExportProvider
|
|
375
|
+
capture={vi.fn(async () => {
|
|
376
|
+
throw new Error("canvas tainted");
|
|
377
|
+
})}
|
|
378
|
+
zipFiles={vi.fn()}
|
|
379
|
+
>
|
|
380
|
+
<RegisteredChart id="storage" title="Disks" />
|
|
381
|
+
<DownloadChartButton id="storage" />
|
|
382
|
+
<ErrorText />
|
|
383
|
+
</ChartExportProvider>,
|
|
384
|
+
);
|
|
385
|
+
|
|
386
|
+
await user.click(screen.getByRole("button", { name: "Download storage" }));
|
|
387
|
+
|
|
388
|
+
expect(
|
|
389
|
+
await screen.findByText("Failed to export PNG. Please try again."),
|
|
390
|
+
).toBeInTheDocument();
|
|
391
|
+
expect(screen.queryByText("canvas tainted")).not.toBeInTheDocument();
|
|
392
|
+
vi.mocked(console.error).mockRestore();
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
it("hides per-chart download when no provider is present", () => {
|
|
396
|
+
render(<HostPowerStates hostPowerStates={{ green: 3 }} />);
|
|
397
|
+
|
|
398
|
+
expect(
|
|
399
|
+
screen.queryByRole("button", { name: /download/i }),
|
|
400
|
+
).not.toBeInTheDocument();
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
it("shows a per-chart download button when the provider is present", () => {
|
|
404
|
+
render(
|
|
405
|
+
<ChartExportProvider capture={vi.fn()} zipFiles={vi.fn()}>
|
|
406
|
+
<HostPowerStates hostPowerStates={{ green: 3 }} />
|
|
407
|
+
</ChartExportProvider>,
|
|
408
|
+
);
|
|
409
|
+
|
|
410
|
+
expect(
|
|
411
|
+
screen.getByRole("button", {
|
|
412
|
+
name: "Download ESXi host power states as PNG",
|
|
413
|
+
}),
|
|
414
|
+
).toBeInTheDocument();
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
describe("standardReportExportOptions", () => {
|
|
419
|
+
it("omits formats whose handlers are missing", () => {
|
|
420
|
+
const onExportPng = vi.fn();
|
|
421
|
+
expect(
|
|
422
|
+
standardReportExportOptions({ onExportPng }).map((option) => option.key),
|
|
423
|
+
).toEqual(["png"]);
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
describe("ReportExportMenu", () => {
|
|
428
|
+
it("renders nothing without options", () => {
|
|
429
|
+
const { container } = render(<ReportExportMenu options={[]} />);
|
|
430
|
+
expect(container).toBeEmptyDOMElement();
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
it("invokes the PNG handler from the menu", async () => {
|
|
434
|
+
const user = userEvent.setup();
|
|
435
|
+
const onExportPng = vi.fn();
|
|
436
|
+
|
|
437
|
+
render(<ExportReportButton onExportPng={onExportPng} />);
|
|
438
|
+
|
|
439
|
+
await user.click(
|
|
440
|
+
screen.getByRole("button", { name: "Export report options" }),
|
|
441
|
+
);
|
|
442
|
+
await user.click(screen.getByRole("menuitem", { name: /png/i }));
|
|
443
|
+
|
|
444
|
+
expect(onExportPng).toHaveBeenCalledTimes(1);
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it("places the loading spinner in the toggle icon slot", () => {
|
|
448
|
+
render(
|
|
449
|
+
<ReportExportMenu
|
|
450
|
+
isLoading
|
|
451
|
+
loadingLabel="Generating PNG..."
|
|
452
|
+
options={[
|
|
453
|
+
{
|
|
454
|
+
key: "png",
|
|
455
|
+
label: "PNG",
|
|
456
|
+
description: "Download all charts as PNG files",
|
|
457
|
+
onSelect: vi.fn(),
|
|
458
|
+
},
|
|
459
|
+
]}
|
|
460
|
+
/>,
|
|
461
|
+
);
|
|
462
|
+
|
|
463
|
+
const toggle = screen.getByRole("button", {
|
|
464
|
+
name: "Export report options",
|
|
465
|
+
});
|
|
466
|
+
expect(toggle).toHaveTextContent("Generating PNG...");
|
|
467
|
+
const iconSlot = toggle.querySelector(".pf-v6-c-menu-toggle__icon");
|
|
468
|
+
expect(iconSlot).not.toBeNull();
|
|
469
|
+
expect(iconSlot?.querySelector('[role="progressbar"]')).not.toBeNull();
|
|
470
|
+
expect(
|
|
471
|
+
toggle.querySelector(".pf-v6-c-menu-toggle__text")?.textContent,
|
|
472
|
+
).toBe("Generating PNG...");
|
|
473
|
+
});
|
|
474
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import "@testing-library/jest-dom";
|
|
2
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { HostPowerStates } from "../HostPowerStates.js";
|
|
5
|
+
import { VmPowerStates } from "../VmPowerStates.js";
|
|
6
|
+
|
|
7
|
+
vi.mock("../../charts/MigrationDonutChart.js", () => ({
|
|
8
|
+
MigrationDonutChart: ({
|
|
9
|
+
title,
|
|
10
|
+
subTitle,
|
|
11
|
+
}: {
|
|
12
|
+
title?: string;
|
|
13
|
+
subTitle?: string;
|
|
14
|
+
}): JSX.Element => (
|
|
15
|
+
<div data-testid="power-donut">
|
|
16
|
+
{title} {subTitle}
|
|
17
|
+
</div>
|
|
18
|
+
),
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
afterEach(() => cleanup());
|
|
22
|
+
|
|
23
|
+
describe("HostPowerStates", () => {
|
|
24
|
+
it("renders the host power donut from inventory data", () => {
|
|
25
|
+
render(<HostPowerStates hostPowerStates={{ green: 7 }} />);
|
|
26
|
+
|
|
27
|
+
expect(screen.getByText("ESXi host power states")).toBeInTheDocument();
|
|
28
|
+
expect(screen.getByTestId("power-donut")).toHaveTextContent("7 Hosts");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("shows an empty state when host power data is missing", () => {
|
|
32
|
+
render(<HostPowerStates hostPowerStates={{}} />);
|
|
33
|
+
|
|
34
|
+
expect(
|
|
35
|
+
screen.getByText("Host power state data not collected"),
|
|
36
|
+
).toBeInTheDocument();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe("VmPowerStates", () => {
|
|
41
|
+
it("renders the VM power donut from inventory data", () => {
|
|
42
|
+
render(<VmPowerStates powerStates={{ poweredOff: 297, poweredOn: 53 }} />);
|
|
43
|
+
|
|
44
|
+
expect(screen.getByText("VM power states")).toBeInTheDocument();
|
|
45
|
+
expect(screen.getByTestId("power-donut")).toHaveTextContent("350 VMs");
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import "@testing-library/jest-dom";
|
|
2
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
3
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
4
|
+
import { InfrastructureSummary } from "../InfrastructureSummary.js";
|
|
5
|
+
import { VCenterClusterDetails } from "../VCenterClusterDetails.js";
|
|
6
|
+
|
|
7
|
+
afterEach(() => cleanup());
|
|
8
|
+
|
|
9
|
+
describe("InfrastructureSummary", () => {
|
|
10
|
+
it("renders inventory summary fields from the mapped model", () => {
|
|
11
|
+
render(
|
|
12
|
+
<InfrastructureSummary
|
|
13
|
+
summary={{
|
|
14
|
+
vmwareVersion: "vSphere 7.0.3",
|
|
15
|
+
datacenters: 1,
|
|
16
|
+
vCenters: 1,
|
|
17
|
+
esxiHosts: 12,
|
|
18
|
+
}}
|
|
19
|
+
/>,
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
expect(screen.getByText("Infrastructure summary")).toBeInTheDocument();
|
|
23
|
+
expect(screen.getByText("vSphere 7.0.3")).toBeInTheDocument();
|
|
24
|
+
expect(screen.getByText("Datacenters")).toBeInTheDocument();
|
|
25
|
+
expect(screen.getByText("vCenters")).toBeInTheDocument();
|
|
26
|
+
expect(screen.getByText("ESXi hosts")).toBeInTheDocument();
|
|
27
|
+
expect(screen.getByText("12")).toBeInTheDocument();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe("VCenterClusterDetails", () => {
|
|
32
|
+
it("renders the aggregate cluster table with feature statuses", () => {
|
|
33
|
+
render(
|
|
34
|
+
<VCenterClusterDetails
|
|
35
|
+
isAggregateView
|
|
36
|
+
rows={[
|
|
37
|
+
{
|
|
38
|
+
id: "Cluster-Prod-01",
|
|
39
|
+
name: "Cluster-Prod-01",
|
|
40
|
+
hosts: 5,
|
|
41
|
+
vms: 280,
|
|
42
|
+
vmotion: "enabled",
|
|
43
|
+
drs: "enabled",
|
|
44
|
+
vsan: "enabled",
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: "Cluster-Dev-02",
|
|
48
|
+
name: "Cluster-Dev-02",
|
|
49
|
+
hosts: 7,
|
|
50
|
+
vms: 350,
|
|
51
|
+
vmotion: "enabled",
|
|
52
|
+
drs: "disabled",
|
|
53
|
+
vsan: "enabled",
|
|
54
|
+
},
|
|
55
|
+
]}
|
|
56
|
+
/>,
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
expect(screen.getByText("vCenter cluster details")).toBeInTheDocument();
|
|
60
|
+
expect(screen.getByText("Cluster-Prod-01")).toBeInTheDocument();
|
|
61
|
+
expect(screen.getByText("Cluster-Dev-02")).toBeInTheDocument();
|
|
62
|
+
expect(screen.getAllByText("Enabled").length).toBeGreaterThan(0);
|
|
63
|
+
expect(screen.getByText("Disabled")).toBeInTheDocument();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("limits the aggregate table height so long cluster lists can scroll", () => {
|
|
67
|
+
render(
|
|
68
|
+
<VCenterClusterDetails
|
|
69
|
+
isAggregateView
|
|
70
|
+
rows={Array.from({ length: 12 }, (_, index) => ({
|
|
71
|
+
id: `cluster-${index}`,
|
|
72
|
+
name: `cluster-${index}`,
|
|
73
|
+
hosts: index + 1,
|
|
74
|
+
vms: (index + 1) * 10,
|
|
75
|
+
vmotion: "unknown",
|
|
76
|
+
drs: "unknown",
|
|
77
|
+
vsan: "disabled",
|
|
78
|
+
}))}
|
|
79
|
+
/>,
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
expect(
|
|
83
|
+
screen.getByTestId("vcenter-cluster-details-table").parentElement,
|
|
84
|
+
).toHaveAttribute("data-scroll-constrained", "true");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("renders the detailed cluster cards for a single cluster", () => {
|
|
88
|
+
render(
|
|
89
|
+
<VCenterClusterDetails
|
|
90
|
+
isAggregateView={false}
|
|
91
|
+
rows={[]}
|
|
92
|
+
details={{
|
|
93
|
+
hosts: 7,
|
|
94
|
+
vms: 350,
|
|
95
|
+
networksDetected: 2,
|
|
96
|
+
vmotion: "enabled",
|
|
97
|
+
drs: "disabled",
|
|
98
|
+
ha: "enabled",
|
|
99
|
+
vsan: "disabled",
|
|
100
|
+
networks: [
|
|
101
|
+
{
|
|
102
|
+
name: "VDS-Dev",
|
|
103
|
+
vlanId: "10",
|
|
104
|
+
displayName: "VDS-Dev (VLAN 10)",
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: "VDS-Dev",
|
|
108
|
+
vlanId: "11",
|
|
109
|
+
displayName: "VDS-Dev (VLAN 11)",
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
}}
|
|
113
|
+
/>,
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
expect(screen.getByText("Core infrastructure")).toBeInTheDocument();
|
|
117
|
+
expect(screen.getByText("vSAN capabilities")).toBeInTheDocument();
|
|
118
|
+
expect(screen.getByText("Network topology")).toBeInTheDocument();
|
|
119
|
+
expect(screen.getByText("vMotion")).toBeInTheDocument();
|
|
120
|
+
expect(screen.getByText("DRS")).toBeInTheDocument();
|
|
121
|
+
expect(screen.getByText("HA")).toBeInTheDocument();
|
|
122
|
+
expect(screen.getByText("VDS-Dev (VLAN 10)")).toBeInTheDocument();
|
|
123
|
+
expect(screen.getByText("VDS-Dev (VLAN 11)")).toBeInTheDocument();
|
|
124
|
+
expect(screen.queryByText("VM encryption")).toBeNull();
|
|
125
|
+
});
|
|
126
|
+
});
|
|
@@ -82,14 +82,13 @@ describe("OSBarChart", () => {
|
|
|
82
82
|
expect(within(popover).getByText("Upgrade to RHEL 7")).toBeInTheDocument();
|
|
83
83
|
});
|
|
84
84
|
|
|
85
|
-
it("
|
|
86
|
-
render(<OSBarChart osData={sampleOsData}
|
|
85
|
+
it("marks the upgrade recommendation icon as capture chrome", () => {
|
|
86
|
+
render(<OSBarChart osData={sampleOsData} />);
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
).not.toBeInTheDocument();
|
|
88
|
+
const upgradeButton = screen.getByRole("button", {
|
|
89
|
+
name: "Open operating system upgrade information",
|
|
90
|
+
});
|
|
91
|
+
expect(upgradeButton.closest("[data-chart-export-hide]")).not.toBeNull();
|
|
93
92
|
});
|
|
94
93
|
|
|
95
94
|
it("shows official Red Hat definitions in tier badge tooltips", async () => {
|
|
@@ -149,12 +148,12 @@ describe("OSBarChart", () => {
|
|
|
149
148
|
).toBeInTheDocument();
|
|
150
149
|
});
|
|
151
150
|
|
|
152
|
-
it("
|
|
153
|
-
render(<OSBarChart osData={sampleOsData}
|
|
151
|
+
it("uses explicit badge colors so html2canvas can capture them", () => {
|
|
152
|
+
render(<OSBarChart osData={sampleOsData} />);
|
|
154
153
|
|
|
155
154
|
const certifiedBadge = screen.getByText("Certified");
|
|
156
|
-
|
|
157
|
-
expect(
|
|
155
|
+
const styledBadge = certifiedBadge.closest("[style]") ?? certifiedBadge;
|
|
156
|
+
expect(styledBadge).toHaveStyle({
|
|
158
157
|
backgroundColor: "rgb(185, 218, 252)",
|
|
159
158
|
color: "rgb(0, 77, 153)",
|
|
160
159
|
});
|