@openshift-migration-advisor/shared-components 0.25.0 → 0.27.0-5d313f88dc52
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 +25 -0
- 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 +23 -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/ErrorTable.d.ts +18 -0
- package/dist/report/ErrorTable.d.ts.map +1 -0
- package/dist/report/ErrorTable.js +20 -0
- package/dist/report/HostPowerStates.d.ts +0 -1
- package/dist/report/HostPowerStates.d.ts.map +1 -1
- package/dist/report/HostPowerStates.js +2 -2
- package/dist/report/HostsOverview.d.ts +13 -0
- package/dist/report/HostsOverview.d.ts.map +1 -0
- package/dist/report/HostsOverview.js +84 -0
- package/dist/report/InfrastructureSummary.d.ts.map +1 -1
- package/dist/report/InfrastructureSummary.js +6 -2
- package/dist/report/NetworkOverview.d.ts +31 -0
- package/dist/report/NetworkOverview.d.ts.map +1 -0
- package/dist/report/NetworkOverview.js +201 -0
- package/dist/report/OSDistribution.d.ts +0 -2
- package/dist/report/OSDistribution.d.ts.map +1 -1
- package/dist/report/OSDistribution.js +8 -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 +0 -1
- package/dist/report/PowerStateCard.d.ts.map +1 -1
- package/dist/report/PowerStateCard.js +4 -2
- 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/ReportTable.d.ts +14 -0
- package/dist/report/ReportTable.d.ts.map +1 -0
- package/dist/report/ReportTable.js +23 -0
- package/dist/report/SupportTierBadge.d.ts +0 -1
- package/dist/report/SupportTierBadge.d.ts.map +1 -1
- package/dist/report/SupportTierBadge.js +1 -21
- package/dist/report/VCenterClusterDetails.d.ts +0 -1
- package/dist/report/VCenterClusterDetails.d.ts.map +1 -1
- package/dist/report/VCenterClusterDetails.js +9 -4
- package/dist/report/VmPowerStates.d.ts +0 -1
- package/dist/report/VmPowerStates.d.ts.map +1 -1
- package/dist/report/VmPowerStates.js +2 -2
- package/dist/report/WarningsTable.d.ts +9 -0
- package/dist/report/WarningsTable.d.ts.map +1 -0
- package/dist/report/WarningsTable.js +20 -0
- package/dist/report/captureChartElement.d.ts +8 -0
- package/dist/report/captureChartElement.d.ts.map +1 -0
- package/dist/report/captureChartElement.js +304 -0
- package/dist/report/chartExport.d.ts +80 -0
- package/dist/report/chartExport.d.ts.map +1 -0
- package/dist/report/chartExport.js +182 -0
- package/dist/report/chartExportContext.d.ts +32 -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 +18 -0
- package/dist/report/index.d.ts.map +1 -1
- package/dist/report/index.js +18 -0
- package/dist/report/pdfExport.d.ts +3 -0
- package/dist/report/pdfExport.d.ts.map +1 -0
- package/dist/report/pdfExport.js +131 -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/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/report/ChartDownloadButton.tsx +59 -0
- package/src/report/ChartExportProvider.tsx +392 -0
- package/src/report/ChartExportSurface.tsx +60 -0
- package/src/report/ErrorTable.tsx +85 -0
- package/src/report/HostPowerStates.tsx +0 -3
- package/src/report/HostsOverview.tsx +185 -0
- package/src/report/InfrastructureSummary.tsx +48 -31
- package/src/report/NetworkOverview.tsx +405 -0
- package/src/report/OSDistribution.tsx +46 -42
- package/src/report/OsUpgradeRecommendationPopover.tsx +3 -4
- package/src/report/PowerStateCard.tsx +49 -36
- package/src/report/ReportExportMenu.tsx +119 -0
- package/src/report/ReportTable.tsx +81 -0
- package/src/report/SupportTierBadge.tsx +12 -40
- package/src/report/VCenterClusterDetails.tsx +38 -16
- package/src/report/VmPowerStates.tsx +0 -3
- package/src/report/WarningsTable.tsx +75 -0
- package/src/report/__tests__/ChartExportProvider.test.tsx +582 -0
- package/src/report/__tests__/HostsOverview.test.tsx +145 -0
- package/src/report/__tests__/InfrastructureSummary.test.tsx +0 -22
- package/src/report/__tests__/NetworkOverview.test.tsx +269 -0
- package/src/report/__tests__/OSDistribution.test.tsx +10 -11
- package/src/report/__tests__/captureChartElement.test.ts +205 -0
- package/src/report/__tests__/chartExportPackagers.test.ts +299 -0
- package/src/report/captureChartElement.ts +398 -0
- package/src/report/chartExport.ts +277 -0
- package/src/report/chartExportContext.tsx +92 -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 +98 -0
- package/src/report/pdfExport.ts +233 -0
- package/src/report/pdfPage.ts +83 -0
- package/src/report/reportExportOptions.ts +53 -0
- package/src/report/zipChartPngs.ts +10 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Card,
|
|
3
|
+
CardBody,
|
|
4
|
+
CardTitle,
|
|
5
|
+
Flex,
|
|
6
|
+
FlexItem,
|
|
7
|
+
Icon,
|
|
8
|
+
} from "@patternfly/react-core";
|
|
9
|
+
import { ExclamationTriangleIcon } from "@patternfly/react-icons";
|
|
10
|
+
import type React from "react";
|
|
11
|
+
import { CardEmptyState } from "./CardEmptyState.js";
|
|
12
|
+
import { ChartHeaderActions } from "./ChartDownloadButton.js";
|
|
13
|
+
import { ChartExportSurface } from "./ChartExportSurface.js";
|
|
14
|
+
import { REPORT_CARD_EMPTY_STATE_TITLES } from "./constants.js";
|
|
15
|
+
import { dashboardStyles } from "./dashboardStyles.js";
|
|
16
|
+
import type { MigrationIssueLike } from "./ErrorTable.js";
|
|
17
|
+
import { ReportTable } from "./ReportTable.js";
|
|
18
|
+
|
|
19
|
+
export interface WarningsTableProps {
|
|
20
|
+
warnings: MigrationIssueLike[];
|
|
21
|
+
/** Optional drill-down callback invoked with an issue's `label`. */
|
|
22
|
+
onConcernClick?: (concernLabel: string) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const WarningsTable: React.FC<WarningsTableProps> = ({
|
|
26
|
+
warnings,
|
|
27
|
+
onConcernClick,
|
|
28
|
+
}) => {
|
|
29
|
+
const handleRowClick = (issue: MigrationIssueLike) => {
|
|
30
|
+
if (issue.label && onConcernClick) {
|
|
31
|
+
onConcernClick(issue.label);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const chartId = "warnings-table";
|
|
36
|
+
const chartTitle = "Warnings";
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<ChartExportSurface id={chartId} title={chartTitle}>
|
|
40
|
+
<Card className={dashboardStyles.card}>
|
|
41
|
+
<CardTitle>
|
|
42
|
+
<Flex
|
|
43
|
+
justifyContent={{ default: "justifyContentSpaceBetween" }}
|
|
44
|
+
alignItems={{ default: "alignItemsCenter" }}
|
|
45
|
+
>
|
|
46
|
+
<FlexItem>
|
|
47
|
+
<Icon status="warning">
|
|
48
|
+
<ExclamationTriangleIcon />
|
|
49
|
+
</Icon>{" "}
|
|
50
|
+
Warnings
|
|
51
|
+
</FlexItem>
|
|
52
|
+
<ChartHeaderActions chartId={chartId} title={chartTitle} />
|
|
53
|
+
</Flex>
|
|
54
|
+
</CardTitle>
|
|
55
|
+
<CardBody className={dashboardStyles.cardBodyScrollable}>
|
|
56
|
+
{warnings.length === 0 ? (
|
|
57
|
+
<CardEmptyState title={REPORT_CARD_EMPTY_STATE_TITLES.warnings} />
|
|
58
|
+
) : (
|
|
59
|
+
<div>
|
|
60
|
+
<ReportTable<MigrationIssueLike>
|
|
61
|
+
data={warnings}
|
|
62
|
+
columns={["Description", "Total VMs"]}
|
|
63
|
+
fields={["assessment", "count"]}
|
|
64
|
+
onRowClick={onConcernClick ? handleRowClick : undefined}
|
|
65
|
+
clickableFields={onConcernClick ? ["assessment"] : []}
|
|
66
|
+
/>
|
|
67
|
+
</div>
|
|
68
|
+
)}
|
|
69
|
+
</CardBody>
|
|
70
|
+
</Card>
|
|
71
|
+
</ChartExportSurface>
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
WarningsTable.displayName = "WarningsTable";
|
|
@@ -0,0 +1,582 @@
|
|
|
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({
|
|
105
|
+
extraPages,
|
|
106
|
+
}: {
|
|
107
|
+
extraPages?: Parameters<
|
|
108
|
+
NonNullable<ReturnType<typeof useChartExport>>["downloadPdf"]
|
|
109
|
+
>[1];
|
|
110
|
+
}): JSX.Element {
|
|
111
|
+
const exportApi = useChartExport();
|
|
112
|
+
return (
|
|
113
|
+
<button
|
|
114
|
+
type="button"
|
|
115
|
+
onClick={() => void exportApi?.downloadPdf("Overview", extraPages)}
|
|
116
|
+
>
|
|
117
|
+
Download pdf
|
|
118
|
+
</button>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function DownloadHtmlButton(): JSX.Element {
|
|
123
|
+
const exportApi = useChartExport();
|
|
124
|
+
return (
|
|
125
|
+
<button
|
|
126
|
+
type="button"
|
|
127
|
+
onClick={() => void exportApi?.downloadHtml("Overview")}
|
|
128
|
+
>
|
|
129
|
+
Download html
|
|
130
|
+
</button>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
describe("ChartExportProvider", () => {
|
|
135
|
+
it("snapshots registered live nodes instead of a second chart tree", async () => {
|
|
136
|
+
const user = userEvent.setup();
|
|
137
|
+
const capture = vi.fn(async () => fakeCanvas());
|
|
138
|
+
const encodePng = vi.fn(async () => new Blob(["png"]));
|
|
139
|
+
const zipFiles = vi.fn(
|
|
140
|
+
async (files: { filename: string; blob: Blob }[]) => {
|
|
141
|
+
return new Blob([files.map((file) => file.filename).join(",")]);
|
|
142
|
+
},
|
|
143
|
+
);
|
|
144
|
+
const downloadFile = vi.fn();
|
|
145
|
+
|
|
146
|
+
render(
|
|
147
|
+
<ChartExportProvider
|
|
148
|
+
capture={capture}
|
|
149
|
+
encodePng={encodePng}
|
|
150
|
+
zipFiles={zipFiles}
|
|
151
|
+
downloadFile={downloadFile}
|
|
152
|
+
getZipFilename={() => "charts.zip"}
|
|
153
|
+
>
|
|
154
|
+
<RegisteredChart id="cpu-memory" title="CPU and memory" />
|
|
155
|
+
<RegisteredChart id="storage" title="Disks" />
|
|
156
|
+
<DownloadAllButton />
|
|
157
|
+
</ChartExportProvider>,
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
await user.click(screen.getByRole("button", { name: "Download all" }));
|
|
161
|
+
|
|
162
|
+
expect(zipFiles).toHaveBeenCalledTimes(1);
|
|
163
|
+
expect(downloadFile).toHaveBeenCalledWith(expect.any(Blob), "charts.zip");
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("downloads one registered node as a PNG", async () => {
|
|
167
|
+
const user = userEvent.setup();
|
|
168
|
+
const capture = vi.fn(async () => fakeCanvas());
|
|
169
|
+
const encodePng = vi.fn(async () => new Blob(["png"]));
|
|
170
|
+
const downloadFile = vi.fn();
|
|
171
|
+
|
|
172
|
+
render(
|
|
173
|
+
<ChartExportProvider
|
|
174
|
+
capture={capture}
|
|
175
|
+
encodePng={encodePng}
|
|
176
|
+
zipFiles={vi.fn()}
|
|
177
|
+
downloadFile={downloadFile}
|
|
178
|
+
>
|
|
179
|
+
<RegisteredChart id="storage" title="Disks" />
|
|
180
|
+
<DownloadChartButton id="storage" />
|
|
181
|
+
</ChartExportProvider>,
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
await user.click(screen.getByRole("button", { name: "Download storage" }));
|
|
185
|
+
|
|
186
|
+
expect(capture).toHaveBeenCalledTimes(1);
|
|
187
|
+
expect(downloadFile).toHaveBeenCalledWith(expect.any(Blob), "disks.png");
|
|
188
|
+
});
|
|
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
|
+
|
|
230
|
+
it("re-registers charts after React Strict Mode's extra effect cycle", async () => {
|
|
231
|
+
const user = userEvent.setup();
|
|
232
|
+
const capture = vi.fn(async () => fakeCanvas());
|
|
233
|
+
const encodePng = vi.fn(async () => new Blob(["png"]));
|
|
234
|
+
const downloadFile = vi.fn();
|
|
235
|
+
|
|
236
|
+
render(
|
|
237
|
+
<ChartExportProvider
|
|
238
|
+
capture={capture}
|
|
239
|
+
encodePng={encodePng}
|
|
240
|
+
zipFiles={vi.fn()}
|
|
241
|
+
downloadFile={downloadFile}
|
|
242
|
+
>
|
|
243
|
+
<RegisteredChart id="storage" title="Disks" />
|
|
244
|
+
<DownloadChartButton id="storage" />
|
|
245
|
+
</ChartExportProvider>,
|
|
246
|
+
{ reactStrictMode: true },
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
await user.click(screen.getByRole("button", { name: "Download storage" }));
|
|
250
|
+
|
|
251
|
+
expect(capture).toHaveBeenCalledTimes(1);
|
|
252
|
+
expect(downloadFile).toHaveBeenCalledWith(expect.any(Blob), "disks.png");
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it("builds a PDF from the same captured canvases", async () => {
|
|
256
|
+
const user = userEvent.setup();
|
|
257
|
+
const capture = vi.fn(async () => fakeCanvas());
|
|
258
|
+
const buildPdf = vi.fn(async () => new Blob(["pdf"]));
|
|
259
|
+
const downloadFile = vi.fn();
|
|
260
|
+
|
|
261
|
+
render(
|
|
262
|
+
<ChartExportProvider
|
|
263
|
+
capture={capture}
|
|
264
|
+
zipFiles={vi.fn()}
|
|
265
|
+
buildPdf={buildPdf}
|
|
266
|
+
downloadFile={downloadFile}
|
|
267
|
+
getPdfFilename={() => "report.pdf"}
|
|
268
|
+
>
|
|
269
|
+
<RegisteredChart id="storage" title="Disks" />
|
|
270
|
+
<DownloadPdfButton />
|
|
271
|
+
</ChartExportProvider>,
|
|
272
|
+
);
|
|
273
|
+
|
|
274
|
+
await user.click(screen.getByRole("button", { name: "Download pdf" }));
|
|
275
|
+
|
|
276
|
+
expect(buildPdf).toHaveBeenCalledTimes(1);
|
|
277
|
+
expect(buildPdf.mock.calls[0]?.[1]).toBe("Overview");
|
|
278
|
+
expect(buildPdf.mock.calls[0]?.[0][0]).toMatchObject({
|
|
279
|
+
id: "storage",
|
|
280
|
+
title: "Disks",
|
|
281
|
+
});
|
|
282
|
+
expect(downloadFile).toHaveBeenCalledWith(expect.any(Blob), "report.pdf");
|
|
283
|
+
});
|
|
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
|
+
|
|
347
|
+
it("builds HTML from the same captured canvases", async () => {
|
|
348
|
+
const user = userEvent.setup();
|
|
349
|
+
const capture = vi.fn(async () => fakeCanvas());
|
|
350
|
+
const buildHtml = vi.fn(async () => new Blob(["html"]));
|
|
351
|
+
const downloadFile = vi.fn();
|
|
352
|
+
|
|
353
|
+
render(
|
|
354
|
+
<ChartExportProvider
|
|
355
|
+
capture={capture}
|
|
356
|
+
zipFiles={vi.fn()}
|
|
357
|
+
buildHtml={buildHtml}
|
|
358
|
+
downloadFile={downloadFile}
|
|
359
|
+
getHtmlFilename={() => "report.html"}
|
|
360
|
+
>
|
|
361
|
+
<RegisteredChart id="storage" title="Disks" />
|
|
362
|
+
<DownloadHtmlButton />
|
|
363
|
+
</ChartExportProvider>,
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
await user.click(screen.getByRole("button", { name: "Download html" }));
|
|
367
|
+
|
|
368
|
+
expect(buildHtml).toHaveBeenCalledTimes(1);
|
|
369
|
+
expect(buildHtml.mock.calls[0]?.[1]).toBe("Overview");
|
|
370
|
+
expect(downloadFile).toHaveBeenCalledWith(expect.any(Blob), "report.html");
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
it("captures every dropdown view for PDF, HTML, and zip exports", async () => {
|
|
374
|
+
const user = userEvent.setup();
|
|
375
|
+
const seenViews: string[] = [];
|
|
376
|
+
const capture = vi.fn(async (element: HTMLElement) => {
|
|
377
|
+
seenViews.push(
|
|
378
|
+
element.querySelector("[data-testid='active-view']")?.textContent ?? "",
|
|
379
|
+
);
|
|
380
|
+
return fakeCanvas();
|
|
381
|
+
});
|
|
382
|
+
const encodePng = vi.fn(async () => new Blob(["png"]));
|
|
383
|
+
const zipFiles = vi.fn(
|
|
384
|
+
async (files: { filename: string; blob: Blob }[]) => {
|
|
385
|
+
return new Blob([files.map((file) => file.filename).join(",")]);
|
|
386
|
+
},
|
|
387
|
+
);
|
|
388
|
+
const buildPdf = vi.fn(
|
|
389
|
+
async (
|
|
390
|
+
sources: { title: string; capture: () => Promise<HTMLCanvasElement> }[],
|
|
391
|
+
) => {
|
|
392
|
+
for (const source of sources) {
|
|
393
|
+
await source.capture();
|
|
394
|
+
}
|
|
395
|
+
return new Blob(["pdf"]);
|
|
396
|
+
},
|
|
397
|
+
);
|
|
398
|
+
const downloadFile = vi.fn();
|
|
399
|
+
|
|
400
|
+
function DropdownChart(): JSX.Element {
|
|
401
|
+
const [view, setView] = useState("a");
|
|
402
|
+
return (
|
|
403
|
+
<ChartExportSurface
|
|
404
|
+
id="vm"
|
|
405
|
+
title={view === "a" ? "View A" : "View B"}
|
|
406
|
+
exportViews={[
|
|
407
|
+
{ id: "a", title: "View A" },
|
|
408
|
+
{ id: "b", title: "View B" },
|
|
409
|
+
]}
|
|
410
|
+
activeExportViewId={view}
|
|
411
|
+
onExportViewChange={setView}
|
|
412
|
+
>
|
|
413
|
+
<div data-testid="active-view">{view}</div>
|
|
414
|
+
</ChartExportSurface>
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
render(
|
|
419
|
+
<ChartExportProvider
|
|
420
|
+
capture={capture}
|
|
421
|
+
encodePng={encodePng}
|
|
422
|
+
zipFiles={zipFiles}
|
|
423
|
+
buildPdf={buildPdf}
|
|
424
|
+
downloadFile={downloadFile}
|
|
425
|
+
getZipFilename={() => "charts.zip"}
|
|
426
|
+
getPdfFilename={() => "report.pdf"}
|
|
427
|
+
>
|
|
428
|
+
<DropdownChart />
|
|
429
|
+
<DownloadAllButton />
|
|
430
|
+
<DownloadPdfButton />
|
|
431
|
+
</ChartExportProvider>,
|
|
432
|
+
);
|
|
433
|
+
|
|
434
|
+
await user.click(screen.getByRole("button", { name: "Download all" }));
|
|
435
|
+
await waitFor(() => expect(zipFiles).toHaveBeenCalledTimes(1));
|
|
436
|
+
expect(seenViews).toEqual(["a", "b"]);
|
|
437
|
+
expect(zipFiles.mock.calls[0]?.[0].map((file) => file.filename)).toEqual([
|
|
438
|
+
"01-view-a.png",
|
|
439
|
+
"02-view-b.png",
|
|
440
|
+
]);
|
|
441
|
+
expect(screen.getByTestId("active-view")).toHaveTextContent("a");
|
|
442
|
+
|
|
443
|
+
seenViews.length = 0;
|
|
444
|
+
await user.click(screen.getByRole("button", { name: "Download pdf" }));
|
|
445
|
+
await waitFor(() =>
|
|
446
|
+
expect(downloadFile).toHaveBeenCalledWith(expect.any(Blob), "report.pdf"),
|
|
447
|
+
);
|
|
448
|
+
expect(buildPdf.mock.calls[0]?.[0].map((source) => source.title)).toEqual([
|
|
449
|
+
"View A",
|
|
450
|
+
"View B",
|
|
451
|
+
]);
|
|
452
|
+
expect(seenViews).toEqual(["a", "b"]);
|
|
453
|
+
expect(screen.getByTestId("active-view")).toHaveTextContent("a");
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
it("warns when two live charts share an id", () => {
|
|
457
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => undefined);
|
|
458
|
+
|
|
459
|
+
render(
|
|
460
|
+
<ChartExportProvider capture={vi.fn()} zipFiles={vi.fn()}>
|
|
461
|
+
<RegisteredChart id="storage" title="Disks" />
|
|
462
|
+
<RegisteredChart id="storage" title="Disks copy" />
|
|
463
|
+
</ChartExportProvider>,
|
|
464
|
+
);
|
|
465
|
+
|
|
466
|
+
expect(warn).toHaveBeenCalledWith(
|
|
467
|
+
expect.stringContaining('Duplicate chart export id "storage"'),
|
|
468
|
+
);
|
|
469
|
+
warn.mockRestore();
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
it("shows a generic error when capture fails", async () => {
|
|
473
|
+
const user = userEvent.setup();
|
|
474
|
+
vi.spyOn(console, "error").mockImplementation(() => undefined);
|
|
475
|
+
|
|
476
|
+
function ErrorText(): JSX.Element {
|
|
477
|
+
const exportApi = useChartExport();
|
|
478
|
+
return <div>{exportApi?.exportError}</div>;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
render(
|
|
482
|
+
<ChartExportProvider
|
|
483
|
+
capture={vi.fn(async () => {
|
|
484
|
+
throw new Error("canvas tainted");
|
|
485
|
+
})}
|
|
486
|
+
zipFiles={vi.fn()}
|
|
487
|
+
>
|
|
488
|
+
<RegisteredChart id="storage" title="Disks" />
|
|
489
|
+
<DownloadChartButton id="storage" />
|
|
490
|
+
<ErrorText />
|
|
491
|
+
</ChartExportProvider>,
|
|
492
|
+
);
|
|
493
|
+
|
|
494
|
+
await user.click(screen.getByRole("button", { name: "Download storage" }));
|
|
495
|
+
|
|
496
|
+
expect(
|
|
497
|
+
await screen.findByText("Failed to export PNG. Please try again."),
|
|
498
|
+
).toBeInTheDocument();
|
|
499
|
+
expect(screen.queryByText("canvas tainted")).not.toBeInTheDocument();
|
|
500
|
+
vi.mocked(console.error).mockRestore();
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
it("hides per-chart download when no provider is present", () => {
|
|
504
|
+
render(<HostPowerStates hostPowerStates={{ green: 3 }} />);
|
|
505
|
+
|
|
506
|
+
expect(
|
|
507
|
+
screen.queryByRole("button", { name: /download/i }),
|
|
508
|
+
).not.toBeInTheDocument();
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
it("shows a per-chart download button when the provider is present", () => {
|
|
512
|
+
render(
|
|
513
|
+
<ChartExportProvider capture={vi.fn()} zipFiles={vi.fn()}>
|
|
514
|
+
<HostPowerStates hostPowerStates={{ green: 3 }} />
|
|
515
|
+
</ChartExportProvider>,
|
|
516
|
+
);
|
|
517
|
+
|
|
518
|
+
expect(
|
|
519
|
+
screen.getByRole("button", {
|
|
520
|
+
name: "Download ESXi host power states as PNG",
|
|
521
|
+
}),
|
|
522
|
+
).toBeInTheDocument();
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
describe("standardReportExportOptions", () => {
|
|
527
|
+
it("omits formats whose handlers are missing", () => {
|
|
528
|
+
const onExportPng = vi.fn();
|
|
529
|
+
expect(
|
|
530
|
+
standardReportExportOptions({ onExportPng }).map((option) => option.key),
|
|
531
|
+
).toEqual(["png"]);
|
|
532
|
+
});
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
describe("ReportExportMenu", () => {
|
|
536
|
+
it("renders nothing without options", () => {
|
|
537
|
+
const { container } = render(<ReportExportMenu options={[]} />);
|
|
538
|
+
expect(container).toBeEmptyDOMElement();
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
it("invokes the PNG handler from the menu", async () => {
|
|
542
|
+
const user = userEvent.setup();
|
|
543
|
+
const onExportPng = vi.fn();
|
|
544
|
+
|
|
545
|
+
render(<ExportReportButton onExportPng={onExportPng} />);
|
|
546
|
+
|
|
547
|
+
await user.click(
|
|
548
|
+
screen.getByRole("button", { name: "Export report options" }),
|
|
549
|
+
);
|
|
550
|
+
await user.click(screen.getByRole("menuitem", { name: /png/i }));
|
|
551
|
+
|
|
552
|
+
expect(onExportPng).toHaveBeenCalledTimes(1);
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
it("places the loading spinner in the toggle icon slot", () => {
|
|
556
|
+
render(
|
|
557
|
+
<ReportExportMenu
|
|
558
|
+
isLoading
|
|
559
|
+
loadingLabel="Generating PNG..."
|
|
560
|
+
options={[
|
|
561
|
+
{
|
|
562
|
+
key: "png",
|
|
563
|
+
label: "PNG",
|
|
564
|
+
description: "Download all charts as PNG files",
|
|
565
|
+
onSelect: vi.fn(),
|
|
566
|
+
},
|
|
567
|
+
]}
|
|
568
|
+
/>,
|
|
569
|
+
);
|
|
570
|
+
|
|
571
|
+
const toggle = screen.getByRole("button", {
|
|
572
|
+
name: "Export report options",
|
|
573
|
+
});
|
|
574
|
+
expect(toggle).toHaveTextContent("Generating PNG...");
|
|
575
|
+
const iconSlot = toggle.querySelector(".pf-v6-c-menu-toggle__icon");
|
|
576
|
+
expect(iconSlot).not.toBeNull();
|
|
577
|
+
expect(iconSlot?.querySelector('[role="progressbar"]')).not.toBeNull();
|
|
578
|
+
expect(
|
|
579
|
+
toggle.querySelector(".pf-v6-c-menu-toggle__text")?.textContent,
|
|
580
|
+
).toBe("Generating PNG...");
|
|
581
|
+
});
|
|
582
|
+
});
|