@openshift-migration-advisor/shared-components 0.25.0-fce5293f01c1 → 0.27.0-5d0cc20d809e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/report/ChartExportProvider.d.ts +3 -2
- package/dist/report/ChartExportProvider.d.ts.map +1 -1
- package/dist/report/ChartExportProvider.js +3 -3
- package/dist/report/CpuAndMemoryOverview.d.ts +19 -0
- package/dist/report/CpuAndMemoryOverview.d.ts.map +1 -0
- package/dist/report/CpuAndMemoryOverview.js +112 -0
- package/dist/report/ErrorTable.d.ts +18 -0
- package/dist/report/ErrorTable.d.ts.map +1 -0
- package/dist/report/ErrorTable.js +20 -0
- 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/ReportTable.d.ts +14 -0
- package/dist/report/ReportTable.d.ts.map +1 -0
- package/dist/report/ReportTable.js +23 -0
- 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.map +1 -1
- package/dist/report/captureChartElement.js +28 -8
- package/dist/report/chartExport.d.ts +23 -0
- package/dist/report/chartExport.d.ts.map +1 -1
- package/dist/report/chartExport.js +20 -0
- package/dist/report/chartExportContext.d.ts +6 -2
- package/dist/report/chartExportContext.d.ts.map +1 -1
- 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/index.d.ts +7 -2
- package/dist/report/index.d.ts.map +1 -1
- package/dist/report/index.js +5 -0
- package/dist/report/pdfExport.d.ts +2 -2
- package/dist/report/pdfExport.d.ts.map +1 -1
- package/dist/report/pdfExport.js +52 -3
- package/package.json +2 -2
- package/src/report/ChartExportProvider.tsx +13 -5
- package/src/report/CpuAndMemoryOverview.tsx +277 -0
- package/src/report/ErrorTable.tsx +85 -0
- package/src/report/HostsOverview.tsx +185 -0
- package/src/report/ReportTable.tsx +81 -0
- package/src/report/WarningsTable.tsx +75 -0
- package/src/report/__tests__/ChartExportProvider.test.tsx +110 -2
- package/src/report/__tests__/CpuAndMemoryOverview.test.tsx +200 -0
- package/src/report/__tests__/HostsOverview.test.tsx +145 -0
- package/src/report/__tests__/captureChartElement.test.ts +73 -0
- package/src/report/__tests__/chartExportPackagers.test.ts +75 -0
- package/src/report/captureChartElement.ts +37 -7
- package/src/report/chartExport.ts +40 -0
- package/src/report/chartExportContext.tsx +9 -1
- package/src/report/constants.ts +2 -0
- package/src/report/index.ts +22 -0
- package/src/report/pdfExport.ts +81 -2
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { css } from "@emotion/css";
|
|
2
|
+
import {
|
|
3
|
+
Card,
|
|
4
|
+
CardBody,
|
|
5
|
+
CardTitle,
|
|
6
|
+
Flex,
|
|
7
|
+
FlexItem,
|
|
8
|
+
} from "@patternfly/react-core";
|
|
9
|
+
import { ServerIcon } from "@patternfly/react-icons";
|
|
10
|
+
import {
|
|
11
|
+
chart_color_blue_300,
|
|
12
|
+
chart_color_green_300,
|
|
13
|
+
chart_color_purple_100,
|
|
14
|
+
chart_color_purple_300,
|
|
15
|
+
chart_color_teal_200,
|
|
16
|
+
chart_color_yellow_400,
|
|
17
|
+
} from "@patternfly/react-tokens";
|
|
18
|
+
import type { FC } from "react";
|
|
19
|
+
import { useMemo } from "react";
|
|
20
|
+
import {
|
|
21
|
+
MigrationDonutChart,
|
|
22
|
+
type MigrationDonutChartDatum,
|
|
23
|
+
type MigrationDonutChartLegendVariant,
|
|
24
|
+
} from "../charts/MigrationDonutChart.js";
|
|
25
|
+
import { CardEmptyState } from "./CardEmptyState.js";
|
|
26
|
+
import { ChartHeaderActions } from "./ChartDownloadButton.js";
|
|
27
|
+
import { ChartExportSurface } from "./ChartExportSurface.js";
|
|
28
|
+
import { REPORT_CARD_EMPTY_STATE_TITLES } from "./constants.js";
|
|
29
|
+
import { dashboardStyles } from "./dashboardStyles.js";
|
|
30
|
+
|
|
31
|
+
/** Smallest host shape this card reads. Apps pass SDK hosts structurally. */
|
|
32
|
+
export interface HostLike {
|
|
33
|
+
model?: string | number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface HostsOverviewProps {
|
|
37
|
+
hosts?: HostLike[];
|
|
38
|
+
/** `"html"` in agent-ui; ui-app passes `"chart"`. */
|
|
39
|
+
legendVariant?: MigrationDonutChartLegendVariant;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const TOP_HOST_MODELS = 5;
|
|
43
|
+
const OTHER_MODELS_LABEL = "Other models";
|
|
44
|
+
const UNKNOWN_MODEL_LABEL = "Unknown model";
|
|
45
|
+
const CHART_ID = "hosts-overview";
|
|
46
|
+
const CHART_TITLE = "Host distribution by model";
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Same categorical order as the ui-app host-model donut, mapped onto
|
|
50
|
+
* PatternFly `chart_color_*` tokens (nearest token where the old hex
|
|
51
|
+
* was not itself a token).
|
|
52
|
+
*/
|
|
53
|
+
const HOST_MODEL_COLORS = [
|
|
54
|
+
chart_color_blue_300.value,
|
|
55
|
+
chart_color_purple_300.value,
|
|
56
|
+
chart_color_purple_100.value,
|
|
57
|
+
chart_color_teal_200.value,
|
|
58
|
+
chart_color_yellow_400.value,
|
|
59
|
+
chart_color_green_300.value,
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
const cardSubtitle = css`
|
|
63
|
+
color: var(--pf-t--global--text--color--subtle);
|
|
64
|
+
font-size: 0.85rem;
|
|
65
|
+
`;
|
|
66
|
+
|
|
67
|
+
const hostModelLabel = (model: HostLike["model"]): string => {
|
|
68
|
+
const raw =
|
|
69
|
+
typeof model === "string"
|
|
70
|
+
? model
|
|
71
|
+
: typeof model === "number"
|
|
72
|
+
? String(model)
|
|
73
|
+
: "";
|
|
74
|
+
const trimmed = raw.trim();
|
|
75
|
+
return trimmed !== "" ? trimmed : UNKNOWN_MODEL_LABEL;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const buildHostModelDonut = (
|
|
79
|
+
hosts: HostLike[],
|
|
80
|
+
): {
|
|
81
|
+
slices: MigrationDonutChartDatum[];
|
|
82
|
+
legend: Record<string, string>;
|
|
83
|
+
totalHosts: number;
|
|
84
|
+
} => {
|
|
85
|
+
const counts = new Map<string, number>();
|
|
86
|
+
for (const host of hosts) {
|
|
87
|
+
const label = hostModelLabel(host?.model);
|
|
88
|
+
counts.set(label, (counts.get(label) ?? 0) + 1);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const entries = [...counts.entries()]
|
|
92
|
+
.map(([model, count]) => ({ model, count }))
|
|
93
|
+
.sort((a, b) => b.count - a.count);
|
|
94
|
+
|
|
95
|
+
const top = entries.slice(0, TOP_HOST_MODELS);
|
|
96
|
+
const restSum = entries
|
|
97
|
+
.slice(TOP_HOST_MODELS)
|
|
98
|
+
.reduce((sum, entry) => sum + entry.count, 0);
|
|
99
|
+
|
|
100
|
+
const slices: MigrationDonutChartDatum[] = top.map((entry) => ({
|
|
101
|
+
name: entry.model,
|
|
102
|
+
count: entry.count,
|
|
103
|
+
countDisplay: `${entry.count} hosts`,
|
|
104
|
+
legendCategory: entry.model,
|
|
105
|
+
}));
|
|
106
|
+
|
|
107
|
+
if (restSum > 0) {
|
|
108
|
+
slices.push({
|
|
109
|
+
name: OTHER_MODELS_LABEL,
|
|
110
|
+
count: restSum,
|
|
111
|
+
countDisplay: `${restSum} hosts`,
|
|
112
|
+
legendCategory: OTHER_MODELS_LABEL,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const legend: Record<string, string> = {};
|
|
117
|
+
slices.forEach((slice, index) => {
|
|
118
|
+
const color = HOST_MODEL_COLORS[index % HOST_MODEL_COLORS.length];
|
|
119
|
+
if (color) {
|
|
120
|
+
legend[slice.legendCategory] = color;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
return { slices, legend, totalHosts: hosts.length };
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export const HostsOverview: FC<HostsOverviewProps> = ({
|
|
128
|
+
hosts,
|
|
129
|
+
legendVariant = "html",
|
|
130
|
+
}) => {
|
|
131
|
+
const { slices, legend, totalHosts } = useMemo(
|
|
132
|
+
() => buildHostModelDonut(Array.isArray(hosts) ? hosts : []),
|
|
133
|
+
[hosts],
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<ChartExportSurface id={CHART_ID} title={CHART_TITLE}>
|
|
138
|
+
<Card className={dashboardStyles.card}>
|
|
139
|
+
<CardTitle>
|
|
140
|
+
<Flex
|
|
141
|
+
justifyContent={{ default: "justifyContentSpaceBetween" }}
|
|
142
|
+
alignItems={{ default: "alignItemsCenter" }}
|
|
143
|
+
>
|
|
144
|
+
<FlexItem>
|
|
145
|
+
<div>
|
|
146
|
+
<div>
|
|
147
|
+
<ServerIcon /> {CHART_TITLE}
|
|
148
|
+
</div>
|
|
149
|
+
<div className={cardSubtitle}>Top 5 models</div>
|
|
150
|
+
</div>
|
|
151
|
+
</FlexItem>
|
|
152
|
+
<ChartHeaderActions chartId={CHART_ID} title={CHART_TITLE} />
|
|
153
|
+
</Flex>
|
|
154
|
+
</CardTitle>
|
|
155
|
+
<CardBody className={dashboardStyles.cardBodyScrollable}>
|
|
156
|
+
{slices.length === 0 ? (
|
|
157
|
+
<CardEmptyState title={REPORT_CARD_EMPTY_STATE_TITLES.hosts} />
|
|
158
|
+
) : (
|
|
159
|
+
<MigrationDonutChart
|
|
160
|
+
legendVariant={legendVariant}
|
|
161
|
+
data={slices}
|
|
162
|
+
height={300}
|
|
163
|
+
width={420}
|
|
164
|
+
donutThickness={18}
|
|
165
|
+
titleFontSize={34}
|
|
166
|
+
legend={legend}
|
|
167
|
+
legendWidth={680}
|
|
168
|
+
title={`${totalHosts}`}
|
|
169
|
+
subTitle="Hosts"
|
|
170
|
+
subTitleColor="var(--pf-t--global--text--color--subtle)"
|
|
171
|
+
itemsPerRow={2}
|
|
172
|
+
labelFontSize={16}
|
|
173
|
+
marginLeft="0%"
|
|
174
|
+
tooltipLabelFormatter={({ datum, percent }) =>
|
|
175
|
+
`${datum.countDisplay}\n${percent.toFixed(1)}%`
|
|
176
|
+
}
|
|
177
|
+
/>
|
|
178
|
+
)}
|
|
179
|
+
</CardBody>
|
|
180
|
+
</Card>
|
|
181
|
+
</ChartExportSurface>
|
|
182
|
+
);
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
HostsOverview.displayName = "HostsOverview";
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Button } from "@patternfly/react-core";
|
|
2
|
+
import { Table, Tbody, Td, Th, Thead, Tr } from "@patternfly/react-table";
|
|
3
|
+
import type React from "react";
|
|
4
|
+
import { tableFullWidthStyle } from "./dashboardStyles.js";
|
|
5
|
+
|
|
6
|
+
export interface ReportTableProps<DataItem> {
|
|
7
|
+
columns: string[];
|
|
8
|
+
data: DataItem[];
|
|
9
|
+
fields: Array<keyof DataItem>;
|
|
10
|
+
caption?: string;
|
|
11
|
+
onRowClick?: (item: DataItem) => void;
|
|
12
|
+
clickableFields?: Array<keyof DataItem>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function ReportTable<DataItem>(
|
|
16
|
+
props: ReportTableProps<DataItem>,
|
|
17
|
+
): React.ReactNode {
|
|
18
|
+
const {
|
|
19
|
+
columns,
|
|
20
|
+
data,
|
|
21
|
+
fields,
|
|
22
|
+
caption,
|
|
23
|
+
onRowClick,
|
|
24
|
+
clickableFields = [],
|
|
25
|
+
} = props;
|
|
26
|
+
|
|
27
|
+
const renderCell = (
|
|
28
|
+
item: DataItem,
|
|
29
|
+
field: keyof DataItem,
|
|
30
|
+
): React.ReactNode => {
|
|
31
|
+
const value = item[field];
|
|
32
|
+
|
|
33
|
+
if (value === "" || value == null) {
|
|
34
|
+
return "-";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (typeof value === "boolean") {
|
|
38
|
+
return value ? "True" : "False";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Make field clickable if specified
|
|
42
|
+
if (clickableFields.includes(field) && onRowClick) {
|
|
43
|
+
return (
|
|
44
|
+
<Button
|
|
45
|
+
variant="link"
|
|
46
|
+
isInline
|
|
47
|
+
onClick={() => onRowClick(item)}
|
|
48
|
+
style={{ padding: 0, fontSize: "inherit" }}
|
|
49
|
+
>
|
|
50
|
+
{value as React.ReactNode}
|
|
51
|
+
</Button>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return value as React.ReactNode;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<Table variant="compact" borders={false} className={tableFullWidthStyle}>
|
|
60
|
+
{caption && <caption>{caption}</caption>}
|
|
61
|
+
<Thead>
|
|
62
|
+
<Tr>
|
|
63
|
+
{columns.map((name) => (
|
|
64
|
+
<Th key={name}>{name}</Th>
|
|
65
|
+
))}
|
|
66
|
+
</Tr>
|
|
67
|
+
</Thead>
|
|
68
|
+
<Tbody>
|
|
69
|
+
{data.map((item) => (
|
|
70
|
+
<Tr key={`row-${String(item[fields[0]])}`}>
|
|
71
|
+
{fields.map((f) => (
|
|
72
|
+
<Td key={String(f)}>{renderCell(item, f)}</Td>
|
|
73
|
+
))}
|
|
74
|
+
</Tr>
|
|
75
|
+
))}
|
|
76
|
+
</Tbody>
|
|
77
|
+
</Table>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
ReportTable.displayName = "ReportTable";
|
|
@@ -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";
|
|
@@ -101,12 +101,18 @@ function DownloadChartButton({ id }: { id: string }): JSX.Element {
|
|
|
101
101
|
);
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
function DownloadPdfButton(
|
|
104
|
+
function DownloadPdfButton({
|
|
105
|
+
extraPages,
|
|
106
|
+
}: {
|
|
107
|
+
extraPages?: Parameters<
|
|
108
|
+
NonNullable<ReturnType<typeof useChartExport>>["downloadPdf"]
|
|
109
|
+
>[1];
|
|
110
|
+
}): JSX.Element {
|
|
105
111
|
const exportApi = useChartExport();
|
|
106
112
|
return (
|
|
107
113
|
<button
|
|
108
114
|
type="button"
|
|
109
|
-
onClick={() => void exportApi?.downloadPdf("Overview")}
|
|
115
|
+
onClick={() => void exportApi?.downloadPdf("Overview", extraPages)}
|
|
110
116
|
>
|
|
111
117
|
Download pdf
|
|
112
118
|
</button>
|
|
@@ -181,6 +187,46 @@ describe("ChartExportProvider", () => {
|
|
|
181
187
|
expect(downloadFile).toHaveBeenCalledWith(expect.any(Blob), "disks.png");
|
|
182
188
|
});
|
|
183
189
|
|
|
190
|
+
it("does not change the live theme while exporting", async () => {
|
|
191
|
+
const user = userEvent.setup();
|
|
192
|
+
document.documentElement.classList.add("pf-v6-theme-dark");
|
|
193
|
+
const capture = vi.fn(async () => {
|
|
194
|
+
expect(
|
|
195
|
+
document.documentElement.classList.contains("pf-v6-theme-dark"),
|
|
196
|
+
).toBe(true);
|
|
197
|
+
return fakeCanvas();
|
|
198
|
+
});
|
|
199
|
+
const downloadFile = vi.fn();
|
|
200
|
+
|
|
201
|
+
render(
|
|
202
|
+
<ChartExportProvider
|
|
203
|
+
capture={capture}
|
|
204
|
+
encodePng={async () => new Blob(["png"])}
|
|
205
|
+
zipFiles={async () => new Blob(["zip"])}
|
|
206
|
+
downloadFile={downloadFile}
|
|
207
|
+
getZipFilename={() => "charts.zip"}
|
|
208
|
+
>
|
|
209
|
+
<RegisteredChart id="storage" title="Disks" />
|
|
210
|
+
<DownloadChartButton id="storage" />
|
|
211
|
+
<DownloadAllButton />
|
|
212
|
+
</ChartExportProvider>,
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
await user.click(screen.getByRole("button", { name: "Download storage" }));
|
|
216
|
+
await waitFor(() =>
|
|
217
|
+
expect(downloadFile).toHaveBeenCalledWith(expect.any(Blob), "disks.png"),
|
|
218
|
+
);
|
|
219
|
+
await user.click(screen.getByRole("button", { name: "Download all" }));
|
|
220
|
+
await waitFor(() =>
|
|
221
|
+
expect(downloadFile).toHaveBeenCalledWith(expect.any(Blob), "charts.zip"),
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
expect(
|
|
225
|
+
document.documentElement.classList.contains("pf-v6-theme-dark"),
|
|
226
|
+
).toBe(true);
|
|
227
|
+
document.documentElement.classList.remove("pf-v6-theme-dark");
|
|
228
|
+
});
|
|
229
|
+
|
|
184
230
|
it("re-registers charts after React Strict Mode's extra effect cycle", async () => {
|
|
185
231
|
const user = userEvent.setup();
|
|
186
232
|
const capture = vi.fn(async () => fakeCanvas());
|
|
@@ -236,6 +282,68 @@ describe("ChartExportProvider", () => {
|
|
|
236
282
|
expect(downloadFile).toHaveBeenCalledWith(expect.any(Blob), "report.pdf");
|
|
237
283
|
});
|
|
238
284
|
|
|
285
|
+
it("forwards extra text pages (e.g. cluster sizing recommendations) to the pdf builder", async () => {
|
|
286
|
+
const user = userEvent.setup();
|
|
287
|
+
const capture = vi.fn(async () => fakeCanvas());
|
|
288
|
+
const buildPdf = vi.fn(async () => new Blob(["pdf"]));
|
|
289
|
+
const downloadFile = vi.fn();
|
|
290
|
+
const extraPages = [
|
|
291
|
+
{
|
|
292
|
+
title: "Cluster sizing recommendations",
|
|
293
|
+
items: [
|
|
294
|
+
{ label: "Cluster name", value: "cluster-1" },
|
|
295
|
+
{ label: "Target platform", value: "Bare metal" },
|
|
296
|
+
],
|
|
297
|
+
footer: "Note: estimates only.",
|
|
298
|
+
},
|
|
299
|
+
];
|
|
300
|
+
|
|
301
|
+
render(
|
|
302
|
+
<ChartExportProvider
|
|
303
|
+
capture={capture}
|
|
304
|
+
zipFiles={vi.fn()}
|
|
305
|
+
buildPdf={buildPdf}
|
|
306
|
+
downloadFile={downloadFile}
|
|
307
|
+
getPdfFilename={() => "report.pdf"}
|
|
308
|
+
>
|
|
309
|
+
<RegisteredChart id="storage" title="Disks" />
|
|
310
|
+
<DownloadPdfButton extraPages={extraPages} />
|
|
311
|
+
</ChartExportProvider>,
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
await user.click(screen.getByRole("button", { name: "Download pdf" }));
|
|
315
|
+
|
|
316
|
+
expect(buildPdf).toHaveBeenCalledTimes(1);
|
|
317
|
+
expect(buildPdf.mock.calls[0]?.[2]).toEqual(extraPages);
|
|
318
|
+
expect(downloadFile).toHaveBeenCalledWith(expect.any(Blob), "report.pdf");
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it("builds a PDF from extra text pages alone when no charts are registered", async () => {
|
|
322
|
+
const user = userEvent.setup();
|
|
323
|
+
const buildPdf = vi.fn(async () => new Blob(["pdf"]));
|
|
324
|
+
const downloadFile = vi.fn();
|
|
325
|
+
const extraPages = [{ title: "Cluster sizing recommendations", items: [] }];
|
|
326
|
+
|
|
327
|
+
render(
|
|
328
|
+
<ChartExportProvider
|
|
329
|
+
capture={vi.fn()}
|
|
330
|
+
zipFiles={vi.fn()}
|
|
331
|
+
buildPdf={buildPdf}
|
|
332
|
+
downloadFile={downloadFile}
|
|
333
|
+
getPdfFilename={() => "report.pdf"}
|
|
334
|
+
>
|
|
335
|
+
<DownloadPdfButton extraPages={extraPages} />
|
|
336
|
+
</ChartExportProvider>,
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
await user.click(screen.getByRole("button", { name: "Download pdf" }));
|
|
340
|
+
|
|
341
|
+
expect(buildPdf).toHaveBeenCalledTimes(1);
|
|
342
|
+
expect(buildPdf.mock.calls[0]?.[0]).toEqual([]);
|
|
343
|
+
expect(buildPdf.mock.calls[0]?.[2]).toEqual(extraPages);
|
|
344
|
+
expect(downloadFile).toHaveBeenCalledWith(expect.any(Blob), "report.pdf");
|
|
345
|
+
});
|
|
346
|
+
|
|
239
347
|
it("builds HTML from the same captured canvases", async () => {
|
|
240
348
|
const user = userEvent.setup();
|
|
241
349
|
const capture = vi.fn(async () => fakeCanvas());
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import "@testing-library/jest-dom";
|
|
2
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
import type { MigrationDonutChartProps } from "../../charts/MigrationDonutChart.js";
|
|
6
|
+
import { CpuAndMemoryOverview } from "../CpuAndMemoryOverview.js";
|
|
7
|
+
|
|
8
|
+
const donutProps = vi.hoisted(() => ({
|
|
9
|
+
current: null as MigrationDonutChartProps | null,
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
vi.mock("../../charts/MigrationDonutChart.js", () => ({
|
|
13
|
+
MigrationDonutChart: (props: MigrationDonutChartProps): JSX.Element => {
|
|
14
|
+
donutProps.current = props;
|
|
15
|
+
return (
|
|
16
|
+
<div data-testid="cpu-memory-donut">
|
|
17
|
+
{props.title} {props.subTitle}
|
|
18
|
+
</div>
|
|
19
|
+
);
|
|
20
|
+
},
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
donutProps.current = null;
|
|
25
|
+
cleanup();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const renderedDonut = (): MigrationDonutChartProps => {
|
|
29
|
+
const props = donutProps.current;
|
|
30
|
+
if (!props) {
|
|
31
|
+
throw new Error("expected a CPU and memory donut to render");
|
|
32
|
+
}
|
|
33
|
+
return props;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
describe("CpuAndMemoryOverview", () => {
|
|
37
|
+
it("shows the memory empty state when no memory tiers were collected", () => {
|
|
38
|
+
render(<CpuAndMemoryOverview />);
|
|
39
|
+
|
|
40
|
+
expect(screen.getByText("CPU & memory")).toBeInTheDocument();
|
|
41
|
+
expect(screen.getByText("Memory size tiers")).toBeInTheDocument();
|
|
42
|
+
expect(screen.getByText("Memory data not collected")).toBeInTheDocument();
|
|
43
|
+
expect(screen.queryByTestId("cpu-memory-donut")).not.toBeInTheDocument();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("plots memory tiers from a plain count map and appends GB", () => {
|
|
47
|
+
render(
|
|
48
|
+
<CpuAndMemoryOverview
|
|
49
|
+
memoryTierDistribution={{
|
|
50
|
+
"129-256": 1,
|
|
51
|
+
"0-4": 2,
|
|
52
|
+
"256+": 3,
|
|
53
|
+
"5-16 GB": 4,
|
|
54
|
+
"17–32": 5,
|
|
55
|
+
unused: 0,
|
|
56
|
+
}}
|
|
57
|
+
memoryTotalGB={1024}
|
|
58
|
+
/>,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const props = renderedDonut();
|
|
62
|
+
expect(props.title).toBe("15 VMs");
|
|
63
|
+
expect(props.subTitle).toBe(`${(1024).toLocaleString()} GB`);
|
|
64
|
+
expect(props.data.map((slice) => [slice.name, slice.count])).toEqual([
|
|
65
|
+
["0-4 GB", 2],
|
|
66
|
+
["5-16 GB", 4],
|
|
67
|
+
["17–32 GB", 5],
|
|
68
|
+
["129-256 GB", 1],
|
|
69
|
+
["256+ GB", 3],
|
|
70
|
+
]);
|
|
71
|
+
expect(props.data.map((slice) => slice.legendCategory)).toEqual([
|
|
72
|
+
"0-4",
|
|
73
|
+
"5-16 GB",
|
|
74
|
+
"17–32",
|
|
75
|
+
"129-256",
|
|
76
|
+
"256+",
|
|
77
|
+
]);
|
|
78
|
+
expect(props.legend).toEqual({
|
|
79
|
+
"0-4": "#0066cc",
|
|
80
|
+
"5-16 GB": "#5e40be",
|
|
81
|
+
"17–32": "#b6a6e9",
|
|
82
|
+
"129-256": "#73c5c5",
|
|
83
|
+
"256+": "#b98412",
|
|
84
|
+
});
|
|
85
|
+
expect(props.legendVariant).toBe("html");
|
|
86
|
+
expect(props.marginLeft).toBeUndefined();
|
|
87
|
+
expect(props.onItemClick).toBeUndefined();
|
|
88
|
+
expect(props.onTitleClick).toBeUndefined();
|
|
89
|
+
expect(
|
|
90
|
+
props.legendLabelFormatter?.({ x: "0-4 GB", countDisplay: "2 VMs" }),
|
|
91
|
+
).toBe("0-4 GB (2 VMs)");
|
|
92
|
+
expect(
|
|
93
|
+
props.tooltipLabelFormatter?.({
|
|
94
|
+
datum: {
|
|
95
|
+
x: "0-4 GB",
|
|
96
|
+
y: 2,
|
|
97
|
+
countDisplay: "2 VMs",
|
|
98
|
+
legendCategory: "0-4",
|
|
99
|
+
},
|
|
100
|
+
percent: 13.333,
|
|
101
|
+
total: 15,
|
|
102
|
+
}),
|
|
103
|
+
).toBe("2 VMs\n13.3%");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("calls onTierSelect with the memory distribution key", () => {
|
|
107
|
+
const onTierSelect = vi.fn();
|
|
108
|
+
const onTitleClick = vi.fn();
|
|
109
|
+
render(
|
|
110
|
+
<CpuAndMemoryOverview
|
|
111
|
+
memoryTierDistribution={{ "0-4": 2 }}
|
|
112
|
+
onTierSelect={onTierSelect}
|
|
113
|
+
onTitleClick={onTitleClick}
|
|
114
|
+
/>,
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
renderedDonut().onItemClick?.({
|
|
118
|
+
name: "0-4 GB",
|
|
119
|
+
count: 2,
|
|
120
|
+
legendCategory: "0-4",
|
|
121
|
+
});
|
|
122
|
+
renderedDonut().onTitleClick?.();
|
|
123
|
+
|
|
124
|
+
expect(onTierSelect).toHaveBeenCalledTimes(1);
|
|
125
|
+
expect(onTierSelect).toHaveBeenCalledWith("0-4");
|
|
126
|
+
expect(onTitleClick).toHaveBeenCalledTimes(1);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("switches to vCPU tiers and omits slice clicks", async () => {
|
|
130
|
+
const user = userEvent.setup();
|
|
131
|
+
const onTierSelect = vi.fn();
|
|
132
|
+
render(
|
|
133
|
+
<CpuAndMemoryOverview
|
|
134
|
+
legendVariant="chart"
|
|
135
|
+
cpuTierDistribution={{
|
|
136
|
+
"8": 1,
|
|
137
|
+
"2 cores": 2,
|
|
138
|
+
"1-2": 4,
|
|
139
|
+
"4+": 1,
|
|
140
|
+
idle: 0,
|
|
141
|
+
}}
|
|
142
|
+
cpuTotalCores={64}
|
|
143
|
+
memoryTierDistribution={{ "0-4": 2 }}
|
|
144
|
+
onTierSelect={onTierSelect}
|
|
145
|
+
/>,
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
await user.click(
|
|
149
|
+
screen.getByRole("button", {
|
|
150
|
+
name: "VM distribution by memory size tier",
|
|
151
|
+
}),
|
|
152
|
+
);
|
|
153
|
+
await user.click(
|
|
154
|
+
screen.getByRole("menuitem", {
|
|
155
|
+
name: "VM distribution by vCPU count tier",
|
|
156
|
+
}),
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
expect(screen.getByText("vCPU count tiers")).toBeInTheDocument();
|
|
160
|
+
expect(
|
|
161
|
+
screen.getByRole("button", {
|
|
162
|
+
name: "VM distribution by vCPU count tier",
|
|
163
|
+
}),
|
|
164
|
+
).toBeInTheDocument();
|
|
165
|
+
|
|
166
|
+
const props = renderedDonut();
|
|
167
|
+
expect(props.title).toBe("8 VMs");
|
|
168
|
+
expect(props.subTitle).toBe(`${(64).toLocaleString()} Cores`);
|
|
169
|
+
expect(props.legendVariant).toBe("chart");
|
|
170
|
+
expect(props.marginLeft).toBe("52%");
|
|
171
|
+
expect(props.labelFontSize).toBe(18);
|
|
172
|
+
expect(props.itemsPerRow).toBe(2);
|
|
173
|
+
expect(props.data.map((slice) => [slice.name, slice.count])).toEqual([
|
|
174
|
+
["1-2 cores", 4],
|
|
175
|
+
["2 cores", 2],
|
|
176
|
+
["4+ cores", 1],
|
|
177
|
+
["8 cores", 1],
|
|
178
|
+
]);
|
|
179
|
+
expect(props.onItemClick).toBeUndefined();
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("shows the CPU empty state when the selected distribution is empty", async () => {
|
|
183
|
+
const user = userEvent.setup();
|
|
184
|
+
render(<CpuAndMemoryOverview cpuTierDistribution={{}} />);
|
|
185
|
+
|
|
186
|
+
await user.click(
|
|
187
|
+
screen.getByRole("button", {
|
|
188
|
+
name: "VM distribution by memory size tier",
|
|
189
|
+
}),
|
|
190
|
+
);
|
|
191
|
+
await user.click(
|
|
192
|
+
screen.getByRole("menuitem", {
|
|
193
|
+
name: "VM distribution by vCPU count tier",
|
|
194
|
+
}),
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
expect(screen.getByText("CPU data not collected")).toBeInTheDocument();
|
|
198
|
+
expect(screen.queryByTestId("cpu-memory-donut")).not.toBeInTheDocument();
|
|
199
|
+
});
|
|
200
|
+
});
|