@openshift-migration-advisor/shared-components 0.25.0 → 0.27.0
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 +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/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 +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 +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 +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/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 +384 -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 +474 -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 +132 -0
- package/src/report/__tests__/chartExportPackagers.test.ts +224 -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 +95 -0
- package/src/report/pdfExport.ts +154 -0
- package/src/report/pdfPage.ts +83 -0
- package/src/report/reportExportOptions.ts +53 -0
- package/src/report/zipChartPngs.ts +10 -0
|
@@ -84,28 +84,6 @@ describe("VCenterClusterDetails", () => {
|
|
|
84
84
|
).toHaveAttribute("data-scroll-constrained", "true");
|
|
85
85
|
});
|
|
86
86
|
|
|
87
|
-
it("does not clip the aggregate table in export mode", () => {
|
|
88
|
-
render(
|
|
89
|
-
<VCenterClusterDetails
|
|
90
|
-
isAggregateView
|
|
91
|
-
isExportMode
|
|
92
|
-
rows={Array.from({ length: 12 }, (_, index) => ({
|
|
93
|
-
id: `cluster-${index}`,
|
|
94
|
-
name: `cluster-${index}`,
|
|
95
|
-
hosts: index + 1,
|
|
96
|
-
vms: (index + 1) * 10,
|
|
97
|
-
vmotion: "unknown",
|
|
98
|
-
drs: "unknown",
|
|
99
|
-
vsan: "disabled",
|
|
100
|
-
}))}
|
|
101
|
-
/>,
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
expect(
|
|
105
|
-
screen.getByTestId("vcenter-cluster-details-table").parentElement,
|
|
106
|
-
).not.toHaveAttribute("data-scroll-constrained");
|
|
107
|
-
});
|
|
108
|
-
|
|
109
87
|
it("renders the detailed cluster cards for a single cluster", () => {
|
|
110
88
|
render(
|
|
111
89
|
<VCenterClusterDetails
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import "@testing-library/jest-dom";
|
|
2
|
+
import {
|
|
3
|
+
chart_color_black_500,
|
|
4
|
+
chart_color_blue_300,
|
|
5
|
+
chart_color_green_300,
|
|
6
|
+
chart_color_orange_100,
|
|
7
|
+
chart_color_purple_100,
|
|
8
|
+
chart_color_purple_300,
|
|
9
|
+
chart_color_red_orange_200,
|
|
10
|
+
chart_color_teal_200,
|
|
11
|
+
chart_color_teal_400,
|
|
12
|
+
chart_color_yellow_400,
|
|
13
|
+
} from "@patternfly/react-tokens";
|
|
14
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
15
|
+
import userEvent from "@testing-library/user-event";
|
|
16
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
17
|
+
import type { MigrationDonutChartProps } from "../../charts/MigrationDonutChart.js";
|
|
18
|
+
import { NetworkOverview } from "../NetworkOverview.js";
|
|
19
|
+
|
|
20
|
+
const donutProps = vi.hoisted(() => ({
|
|
21
|
+
current: null as MigrationDonutChartProps | null,
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
vi.mock("../../charts/MigrationDonutChart.js", () => ({
|
|
25
|
+
MigrationDonutChart: (props: MigrationDonutChartProps): JSX.Element => {
|
|
26
|
+
donutProps.current = props;
|
|
27
|
+
return (
|
|
28
|
+
<div data-testid="network-donut">
|
|
29
|
+
{props.title} {props.subTitle}
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
32
|
+
},
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
donutProps.current = null;
|
|
37
|
+
cleanup();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const renderedDonut = (): MigrationDonutChartProps => {
|
|
41
|
+
const props = donutProps.current;
|
|
42
|
+
if (!props) {
|
|
43
|
+
throw new Error("expected a network donut to render");
|
|
44
|
+
}
|
|
45
|
+
return props;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
describe("NetworkOverview", () => {
|
|
49
|
+
it("shows the network empty state when no networks were collected", () => {
|
|
50
|
+
render(<NetworkOverview />);
|
|
51
|
+
|
|
52
|
+
expect(screen.getByText("Networks")).toBeInTheDocument();
|
|
53
|
+
expect(screen.getByText("Top 5 networks")).toBeInTheDocument();
|
|
54
|
+
expect(screen.getByText("Network data not collected")).toBeInTheDocument();
|
|
55
|
+
expect(screen.queryByTestId("network-donut")).not.toBeInTheDocument();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("keeps the top 4 networks and rolls the rest into one slice", () => {
|
|
59
|
+
render(
|
|
60
|
+
<NetworkOverview
|
|
61
|
+
infra={{
|
|
62
|
+
networks: [
|
|
63
|
+
{ vmsCount: 10, vlanId: "100" },
|
|
64
|
+
{ vmsCount: 8, vlanId: 200 },
|
|
65
|
+
{ vmsCount: 6, vlanId: " " },
|
|
66
|
+
{ vmsCount: 4 },
|
|
67
|
+
{ vmsCount: 3, vlanId: "9" },
|
|
68
|
+
{ vmsCount: 1, vlanId: "8" },
|
|
69
|
+
{ vmsCount: Number.NaN },
|
|
70
|
+
],
|
|
71
|
+
}}
|
|
72
|
+
/>,
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const props = renderedDonut();
|
|
76
|
+
expect(props.title).toBe("32");
|
|
77
|
+
expect(props.subTitle).toBe("VMs");
|
|
78
|
+
expect(props.data.map((slice) => [slice.name, slice.count])).toEqual([
|
|
79
|
+
["Network 1", 10],
|
|
80
|
+
["Network 2", 8],
|
|
81
|
+
["Network 3", 6],
|
|
82
|
+
["Network 4", 4],
|
|
83
|
+
["Rest of networks", 4],
|
|
84
|
+
]);
|
|
85
|
+
expect(props.legend).toEqual({
|
|
86
|
+
"Network 1": chart_color_blue_300.value,
|
|
87
|
+
"Network 2": chart_color_purple_300.value,
|
|
88
|
+
"Network 3": chart_color_purple_100.value,
|
|
89
|
+
"Network 4": chart_color_teal_200.value,
|
|
90
|
+
"Rest of networks": chart_color_yellow_400.value,
|
|
91
|
+
});
|
|
92
|
+
expect(props.legendVariant).toBe("html");
|
|
93
|
+
expect(props.height).toBe(300);
|
|
94
|
+
expect(props.width).toBe(420);
|
|
95
|
+
expect(props.donutThickness).toBe(18);
|
|
96
|
+
expect(props.titleFontSize).toBe(34);
|
|
97
|
+
expect(props.labelFontSize).toBe(18);
|
|
98
|
+
expect(props.itemsPerRow).toBe(3);
|
|
99
|
+
expect(props.marginLeft).toBe("0%");
|
|
100
|
+
expect(
|
|
101
|
+
props.tooltipLabelFormatter?.({
|
|
102
|
+
datum: {
|
|
103
|
+
x: "Network 1",
|
|
104
|
+
y: 10,
|
|
105
|
+
countDisplay: "10 VMs",
|
|
106
|
+
legendCategory: "Network 1",
|
|
107
|
+
},
|
|
108
|
+
percent: 31.25,
|
|
109
|
+
total: 32,
|
|
110
|
+
}),
|
|
111
|
+
).toBe("10 VMs\n31.3%\nVLAN: 100");
|
|
112
|
+
expect(
|
|
113
|
+
props.tooltipLabelFormatter?.({
|
|
114
|
+
datum: {
|
|
115
|
+
x: "Network 2",
|
|
116
|
+
y: 8,
|
|
117
|
+
countDisplay: "8 VMs",
|
|
118
|
+
legendCategory: "Network 2",
|
|
119
|
+
},
|
|
120
|
+
percent: 25,
|
|
121
|
+
total: 32,
|
|
122
|
+
}),
|
|
123
|
+
).toBe("8 VMs\n25.0%\nVLAN: 200");
|
|
124
|
+
expect(
|
|
125
|
+
props.tooltipLabelFormatter?.({
|
|
126
|
+
datum: {
|
|
127
|
+
x: "Rest of networks",
|
|
128
|
+
y: 4,
|
|
129
|
+
countDisplay: "4 VMs",
|
|
130
|
+
legendCategory: "Rest of networks",
|
|
131
|
+
},
|
|
132
|
+
percent: 12.5,
|
|
133
|
+
total: 32,
|
|
134
|
+
}),
|
|
135
|
+
).toBe("4 VMs\n12.5%\nVLAN: -");
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("switches to NIC count and falls back to the histogram", async () => {
|
|
139
|
+
const user = userEvent.setup();
|
|
140
|
+
render(
|
|
141
|
+
<NetworkOverview
|
|
142
|
+
legendVariant="chart"
|
|
143
|
+
nicCount={{
|
|
144
|
+
total: 9,
|
|
145
|
+
histogram: { minValue: 1, step: 1, data: [4, 0, 5] },
|
|
146
|
+
}}
|
|
147
|
+
/>,
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
await user.click(
|
|
151
|
+
screen.getByRole("button", { name: "VM distribution by network" }),
|
|
152
|
+
);
|
|
153
|
+
await user.click(
|
|
154
|
+
screen.getByRole("menuitem", { name: "VM distribution by NIC count" }),
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
expect(screen.queryByText("Top 5 networks")).not.toBeInTheDocument();
|
|
158
|
+
expect(
|
|
159
|
+
screen.getByRole("button", { name: "VM distribution by NIC count" }),
|
|
160
|
+
).toBeInTheDocument();
|
|
161
|
+
|
|
162
|
+
const props = renderedDonut();
|
|
163
|
+
expect(props.legendVariant).toBe("chart");
|
|
164
|
+
expect(props.title).toBe("9");
|
|
165
|
+
expect(props.data.map((slice) => [slice.name, slice.count])).toEqual([
|
|
166
|
+
["1 NIC", 4],
|
|
167
|
+
["3 NIC", 5],
|
|
168
|
+
]);
|
|
169
|
+
expect(
|
|
170
|
+
props.tooltipLabelFormatter?.({
|
|
171
|
+
datum: {
|
|
172
|
+
x: "1 NIC",
|
|
173
|
+
y: 4,
|
|
174
|
+
countDisplay: "4 VMs",
|
|
175
|
+
legendCategory: "1 NIC",
|
|
176
|
+
},
|
|
177
|
+
percent: 44.444,
|
|
178
|
+
total: 9,
|
|
179
|
+
}),
|
|
180
|
+
).toBe("4 VMs\n44.4%");
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("plots distributionByNicCount ahead of the deprecated histogram", async () => {
|
|
184
|
+
const user = userEvent.setup();
|
|
185
|
+
render(
|
|
186
|
+
<NetworkOverview
|
|
187
|
+
distributionByNicCount={{ "2": 5, "4+": 2, "1": 3, "0": 1 }}
|
|
188
|
+
nicCount={{
|
|
189
|
+
total: 99,
|
|
190
|
+
histogram: { minValue: 1, step: 1, data: [9] },
|
|
191
|
+
}}
|
|
192
|
+
/>,
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
await user.click(
|
|
196
|
+
screen.getByRole("button", { name: "VM distribution by network" }),
|
|
197
|
+
);
|
|
198
|
+
await user.click(
|
|
199
|
+
screen.getByRole("menuitem", { name: "VM distribution by NIC count" }),
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
const props = renderedDonut();
|
|
203
|
+
expect(props.title).toBe("11");
|
|
204
|
+
expect(props.data.map((slice) => slice.name)).toEqual([
|
|
205
|
+
"0 NIC",
|
|
206
|
+
"1 NIC",
|
|
207
|
+
"2 NIC",
|
|
208
|
+
"4+ NIC",
|
|
209
|
+
]);
|
|
210
|
+
expect(props.legend).toEqual({
|
|
211
|
+
"0 NIC": chart_color_blue_300.value,
|
|
212
|
+
"1 NIC": chart_color_purple_300.value,
|
|
213
|
+
"2 NIC": chart_color_purple_100.value,
|
|
214
|
+
"4+ NIC": chart_color_teal_200.value,
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it("shows the NIC empty state when the selected distribution is empty", async () => {
|
|
219
|
+
const user = userEvent.setup();
|
|
220
|
+
render(<NetworkOverview distributionByNicCount={{}} />);
|
|
221
|
+
|
|
222
|
+
await user.click(
|
|
223
|
+
screen.getByRole("button", { name: "VM distribution by network" }),
|
|
224
|
+
);
|
|
225
|
+
await user.click(
|
|
226
|
+
screen.getByRole("menuitem", { name: "VM distribution by NIC count" }),
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
expect(
|
|
230
|
+
screen.getByText("NIC count data not collected"),
|
|
231
|
+
).toBeInTheDocument();
|
|
232
|
+
expect(screen.queryByTestId("network-donut")).not.toBeInTheDocument();
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it("uses the extended palette when there are more NIC buckets than base colors", async () => {
|
|
236
|
+
const user = userEvent.setup();
|
|
237
|
+
render(
|
|
238
|
+
<NetworkOverview
|
|
239
|
+
distributionByNicCount={{
|
|
240
|
+
"0": 1,
|
|
241
|
+
"1": 1,
|
|
242
|
+
"2": 1,
|
|
243
|
+
"3": 1,
|
|
244
|
+
"4": 1,
|
|
245
|
+
"5": 1,
|
|
246
|
+
"6": 1,
|
|
247
|
+
"7": 1,
|
|
248
|
+
"8": 1,
|
|
249
|
+
"9": 1,
|
|
250
|
+
}}
|
|
251
|
+
/>,
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
await user.click(
|
|
255
|
+
screen.getByRole("button", { name: "VM distribution by network" }),
|
|
256
|
+
);
|
|
257
|
+
await user.click(
|
|
258
|
+
screen.getByRole("menuitem", { name: "VM distribution by NIC count" }),
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
expect(renderedDonut().legend).toMatchObject({
|
|
262
|
+
"5 NIC": chart_color_green_300.value,
|
|
263
|
+
"6 NIC": chart_color_orange_100.value,
|
|
264
|
+
"7 NIC": chart_color_red_orange_200.value,
|
|
265
|
+
"8 NIC": chart_color_teal_400.value,
|
|
266
|
+
"9 NIC": chart_color_black_500.value,
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
});
|
|
@@ -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
|
});
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import html2canvas from "html2canvas-pro";
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { captureChartElement } from "../captureChartElement.js";
|
|
4
|
+
|
|
5
|
+
vi.mock("html2canvas-pro", () => ({
|
|
6
|
+
default: vi.fn(async () => {
|
|
7
|
+
const canvas = document.createElement("canvas");
|
|
8
|
+
canvas.width = 1;
|
|
9
|
+
canvas.height = 1;
|
|
10
|
+
return canvas;
|
|
11
|
+
}),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
const mockedHtml2Canvas = vi.mocked(html2canvas);
|
|
15
|
+
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
mockedHtml2Canvas.mockClear();
|
|
18
|
+
document.body.replaceChildren();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("captureChartElement", () => {
|
|
22
|
+
it("temporarily unhides ancestors so a hidden tab panel can be measured", async () => {
|
|
23
|
+
const panel = document.createElement("div");
|
|
24
|
+
panel.hidden = true;
|
|
25
|
+
const chart = document.createElement("div");
|
|
26
|
+
panel.append(chart);
|
|
27
|
+
document.body.append(panel);
|
|
28
|
+
|
|
29
|
+
mockedHtml2Canvas.mockImplementation(async () => {
|
|
30
|
+
expect(panel.hidden).toBe(false);
|
|
31
|
+
expect(panel.style.display).toBe("block");
|
|
32
|
+
const canvas = document.createElement("canvas");
|
|
33
|
+
canvas.width = 1;
|
|
34
|
+
canvas.height = 1;
|
|
35
|
+
return canvas;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
await captureChartElement(chart);
|
|
39
|
+
|
|
40
|
+
expect(panel.hidden).toBe(true);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("temporarily unhides ancestors hidden with display none", async () => {
|
|
44
|
+
const panel = document.createElement("div");
|
|
45
|
+
panel.style.display = "none";
|
|
46
|
+
const chart = document.createElement("div");
|
|
47
|
+
panel.append(chart);
|
|
48
|
+
document.body.append(panel);
|
|
49
|
+
|
|
50
|
+
mockedHtml2Canvas.mockImplementation(async () => {
|
|
51
|
+
expect(panel.style.display).toBe("block");
|
|
52
|
+
const canvas = document.createElement("canvas");
|
|
53
|
+
canvas.width = 1;
|
|
54
|
+
canvas.height = 1;
|
|
55
|
+
return canvas;
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
await captureChartElement(chart);
|
|
59
|
+
|
|
60
|
+
expect(panel.style.display).toBe("none");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("paints a real card border and hides the PatternFly ::before during capture", async () => {
|
|
64
|
+
const root = document.createElement("div");
|
|
65
|
+
const card = document.createElement("div");
|
|
66
|
+
card.className = "pf-v6-c-card";
|
|
67
|
+
card.style.borderRadius = "16px";
|
|
68
|
+
card.style.backgroundColor = "rgb(255, 255, 255)";
|
|
69
|
+
card.style.border = "1px solid rgb(200, 200, 200)";
|
|
70
|
+
root.append(card);
|
|
71
|
+
document.body.append(root);
|
|
72
|
+
|
|
73
|
+
mockedHtml2Canvas.mockImplementation(async (_element, options) => {
|
|
74
|
+
expect(card.style.borderWidth).toBe("1px");
|
|
75
|
+
expect(card.style.overflow).toBe("hidden");
|
|
76
|
+
expect(
|
|
77
|
+
document.head.querySelector("[data-chart-export-hide-before]"),
|
|
78
|
+
).not.toBeNull();
|
|
79
|
+
|
|
80
|
+
const cloneRoot = document.createElement("div");
|
|
81
|
+
const cloneCard = document.createElement("div");
|
|
82
|
+
cloneCard.className = "pf-v6-c-card";
|
|
83
|
+
cloneRoot.append(cloneCard);
|
|
84
|
+
options?.onclone?.(document, cloneRoot);
|
|
85
|
+
expect(cloneCard.style.borderWidth).toBe("1px");
|
|
86
|
+
expect(cloneCard.style.borderStyle).toBe("solid");
|
|
87
|
+
expect(cloneCard.style.overflow).toBe("hidden");
|
|
88
|
+
|
|
89
|
+
const canvas = document.createElement("canvas");
|
|
90
|
+
canvas.width = 1;
|
|
91
|
+
canvas.height = 1;
|
|
92
|
+
return canvas;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
await captureChartElement(root);
|
|
96
|
+
|
|
97
|
+
expect(card.style.borderWidth).toBe("1px");
|
|
98
|
+
expect(card.style.overflow).toBe("");
|
|
99
|
+
expect(
|
|
100
|
+
document.head.querySelector("[data-chart-export-hide-before]"),
|
|
101
|
+
).toBeNull();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("inlines computed card title padding so content stays inset", async () => {
|
|
105
|
+
const root = document.createElement("div");
|
|
106
|
+
const title = document.createElement("div");
|
|
107
|
+
title.className = "pf-v6-c-card__title";
|
|
108
|
+
title.style.padding = "24px 24px 16px 24px";
|
|
109
|
+
root.append(title);
|
|
110
|
+
document.body.append(root);
|
|
111
|
+
|
|
112
|
+
mockedHtml2Canvas.mockImplementation(async (_element, options) => {
|
|
113
|
+
expect(title.style.paddingTop).not.toBe("");
|
|
114
|
+
expect(title.style.paddingLeft).not.toBe("");
|
|
115
|
+
|
|
116
|
+
const cloneRoot = document.createElement("div");
|
|
117
|
+
const cloneTitle = document.createElement("div");
|
|
118
|
+
cloneTitle.className = "pf-v6-c-card__title";
|
|
119
|
+
cloneRoot.append(cloneTitle);
|
|
120
|
+
options?.onclone?.(document, cloneRoot);
|
|
121
|
+
expect(cloneTitle.style.paddingTop).not.toBe("");
|
|
122
|
+
expect(cloneTitle.style.paddingLeft).not.toBe("");
|
|
123
|
+
|
|
124
|
+
const canvas = document.createElement("canvas");
|
|
125
|
+
canvas.width = 1;
|
|
126
|
+
canvas.height = 1;
|
|
127
|
+
return canvas;
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
await captureChartElement(root);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
chartExportViewsFromLabels,
|
|
4
|
+
restoreChartExportViews,
|
|
5
|
+
sortRegisteredChartsByDocumentOrder,
|
|
6
|
+
toBulkChartCaptureSources,
|
|
7
|
+
} from "../chartExport.js";
|
|
8
|
+
import { getChartExportFilename } from "../chartExportFilenames.js";
|
|
9
|
+
import { buildHtmlReport, escapeHtml } from "../htmlExport.js";
|
|
10
|
+
import {
|
|
11
|
+
fitPdfImageSize,
|
|
12
|
+
placePdfBlock,
|
|
13
|
+
splitSegmentForPageHeight,
|
|
14
|
+
} from "../pdfPage.js";
|
|
15
|
+
|
|
16
|
+
describe("chart export filenames", () => {
|
|
17
|
+
const date = new Date("2026-07-01T15:30:00");
|
|
18
|
+
|
|
19
|
+
it("names pdf, html, and zip downloads with the export date", () => {
|
|
20
|
+
expect(getChartExportFilename("pdf", date)).toBe(
|
|
21
|
+
"migration-export-2026-07-01.pdf",
|
|
22
|
+
);
|
|
23
|
+
expect(getChartExportFilename("html", date)).toBe(
|
|
24
|
+
"migration-export-2026-07-01.html",
|
|
25
|
+
);
|
|
26
|
+
expect(getChartExportFilename("zip", date)).toBe(
|
|
27
|
+
"migration-export-2026-07-01-charts.zip",
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe("dropdown chart export views", () => {
|
|
33
|
+
it("builds a titled view list from card dropdown labels", () => {
|
|
34
|
+
expect(
|
|
35
|
+
chartExportViewsFromLabels("VM migration status", {
|
|
36
|
+
issuesVsNoIssues: "No issues vs with issues",
|
|
37
|
+
issuesBreakdown: "With issues breakdown",
|
|
38
|
+
}),
|
|
39
|
+
).toEqual([
|
|
40
|
+
{
|
|
41
|
+
id: "issuesVsNoIssues",
|
|
42
|
+
title: "VM migration status — No issues vs with issues",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: "issuesBreakdown",
|
|
46
|
+
title: "VM migration status — With issues breakdown",
|
|
47
|
+
},
|
|
48
|
+
]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("captures every dropdown view then restores the visible one", async () => {
|
|
52
|
+
const element = document.createElement("div");
|
|
53
|
+
const activated: string[] = [];
|
|
54
|
+
const charts = [
|
|
55
|
+
{
|
|
56
|
+
id: "vm",
|
|
57
|
+
title: "Visible",
|
|
58
|
+
filename: "visible.png",
|
|
59
|
+
element,
|
|
60
|
+
exportViews: [
|
|
61
|
+
{ id: "a", title: "View A" },
|
|
62
|
+
{ id: "b", title: "View B" },
|
|
63
|
+
],
|
|
64
|
+
activeExportViewId: "a",
|
|
65
|
+
setExportView: async (viewId: string) => {
|
|
66
|
+
activated.push(viewId);
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
const sources = toBulkChartCaptureSources(charts, async () => {
|
|
72
|
+
const canvas = document.createElement("canvas");
|
|
73
|
+
canvas.width = 1;
|
|
74
|
+
canvas.height = 1;
|
|
75
|
+
return canvas;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
expect(sources.map((source) => source.title)).toEqual(["View A", "View B"]);
|
|
79
|
+
await sources[0].capture();
|
|
80
|
+
await sources[1].capture();
|
|
81
|
+
await restoreChartExportViews(charts);
|
|
82
|
+
|
|
83
|
+
expect(activated).toEqual(["a", "b", "a"]);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("lays out hidden cards before switching dropdown views", async () => {
|
|
87
|
+
const element = document.createElement("div");
|
|
88
|
+
const order: string[] = [];
|
|
89
|
+
const charts = [
|
|
90
|
+
{
|
|
91
|
+
id: "vm",
|
|
92
|
+
title: "Visible",
|
|
93
|
+
filename: "visible.png",
|
|
94
|
+
element,
|
|
95
|
+
exportViews: [
|
|
96
|
+
{ id: "a", title: "View A" },
|
|
97
|
+
{ id: "b", title: "View B" },
|
|
98
|
+
],
|
|
99
|
+
activeExportViewId: "a",
|
|
100
|
+
setExportView: async () => {
|
|
101
|
+
order.push("setView");
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
];
|
|
105
|
+
|
|
106
|
+
const [source] = toBulkChartCaptureSources(
|
|
107
|
+
charts,
|
|
108
|
+
async () => {
|
|
109
|
+
order.push("capture");
|
|
110
|
+
const canvas = document.createElement("canvas");
|
|
111
|
+
canvas.width = 1;
|
|
112
|
+
canvas.height = 1;
|
|
113
|
+
return canvas;
|
|
114
|
+
},
|
|
115
|
+
() => {
|
|
116
|
+
order.push("prepare");
|
|
117
|
+
return () => {
|
|
118
|
+
order.push("restore");
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
await source.capture();
|
|
124
|
+
expect(order).toEqual(["prepare", "setView", "capture", "restore"]);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe("sortRegisteredChartsByDocumentOrder", () => {
|
|
129
|
+
it("orders registered nodes by their position in the document", () => {
|
|
130
|
+
const root = document.createElement("div");
|
|
131
|
+
const first = document.createElement("div");
|
|
132
|
+
const second = document.createElement("div");
|
|
133
|
+
root.append(first, second);
|
|
134
|
+
document.body.append(root);
|
|
135
|
+
|
|
136
|
+
const sorted = sortRegisteredChartsByDocumentOrder([
|
|
137
|
+
{
|
|
138
|
+
id: "second",
|
|
139
|
+
title: "Second",
|
|
140
|
+
filename: "second.png",
|
|
141
|
+
element: second,
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
id: "first",
|
|
145
|
+
title: "First",
|
|
146
|
+
filename: "first.png",
|
|
147
|
+
element: first,
|
|
148
|
+
},
|
|
149
|
+
]);
|
|
150
|
+
|
|
151
|
+
expect(sorted.map((chart) => chart.id)).toEqual(["first", "second"]);
|
|
152
|
+
root.remove();
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
describe("splitSegmentForPageHeight", () => {
|
|
157
|
+
it("splits a tall chart across page height", () => {
|
|
158
|
+
expect(
|
|
159
|
+
splitSegmentForPageHeight({ top: 0, height: 250 }, 250, 100),
|
|
160
|
+
).toEqual([
|
|
161
|
+
{ top: 0, height: 100 },
|
|
162
|
+
{ top: 100, height: 100 },
|
|
163
|
+
{ top: 200, height: 50 },
|
|
164
|
+
]);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
describe("fitPdfImageSize", () => {
|
|
169
|
+
it("keeps full content width when the chart fits the page", () => {
|
|
170
|
+
expect(fitPdfImageSize(800, 200, 190, 277)).toEqual({
|
|
171
|
+
widthMm: 190,
|
|
172
|
+
heightMm: 47.5,
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it("scales down a chart taller than the page", () => {
|
|
177
|
+
expect(fitPdfImageSize(1000, 2000, 200, 100)).toEqual({
|
|
178
|
+
widthMm: 50,
|
|
179
|
+
heightMm: 100,
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe("placePdfBlock", () => {
|
|
185
|
+
it("stacks charts on the same page while they fit", () => {
|
|
186
|
+
expect(placePdfBlock(null, 50, 10, 287)).toEqual({
|
|
187
|
+
y: 10,
|
|
188
|
+
needsNewPage: true,
|
|
189
|
+
});
|
|
190
|
+
expect(placePdfBlock(68, 50, 10, 287)).toEqual({
|
|
191
|
+
y: 68,
|
|
192
|
+
needsNewPage: false,
|
|
193
|
+
});
|
|
194
|
+
expect(placePdfBlock(250, 50, 10, 287)).toEqual({
|
|
195
|
+
y: 10,
|
|
196
|
+
needsNewPage: true,
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
describe("buildHtmlReport", () => {
|
|
202
|
+
it("embeds captured chart images and escapes the title", () => {
|
|
203
|
+
const html = buildHtmlReport(
|
|
204
|
+
'Report <script>alert("x")</script>',
|
|
205
|
+
[
|
|
206
|
+
{
|
|
207
|
+
name: "Infrastructure summary",
|
|
208
|
+
dataUrl: "data:image/png;base64,abc",
|
|
209
|
+
},
|
|
210
|
+
],
|
|
211
|
+
new Date("2026-07-01T15:30:00"),
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
expect(html).toContain(
|
|
215
|
+
"Report <script>alert("x")</script>",
|
|
216
|
+
);
|
|
217
|
+
expect(html).toContain('src="data:image/png;base64,abc"');
|
|
218
|
+
expect(html).toContain("Infrastructure summary");
|
|
219
|
+
expect(html).not.toContain("border:");
|
|
220
|
+
expect(html).toContain("width: 100%");
|
|
221
|
+
expect(escapeHtml("<b>")).toBe("<b>");
|
|
222
|
+
expect(escapeHtml("it's")).toBe("it's");
|
|
223
|
+
});
|
|
224
|
+
});
|