@openshift-migration-advisor/shared-components 0.27.0 → 0.28.0-09381b4d22e5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/charts/MigrationDonutChart.d.ts.map +1 -1
- package/dist/charts/MigrationDonutChart.js +7 -0
- package/dist/report/ChartExportProvider.d.ts +4 -3
- package/dist/report/ChartExportProvider.d.ts.map +1 -1
- package/dist/report/ChartExportProvider.js +7 -4
- package/dist/report/ClustersOverview.d.ts +24 -0
- package/dist/report/ClustersOverview.d.ts.map +1 -0
- package/dist/report/ClustersOverview.js +228 -0
- package/dist/report/ClustersOverviewStyles.d.ts +12 -0
- package/dist/report/ClustersOverviewStyles.d.ts.map +1 -0
- package/dist/report/ClustersOverviewStyles.js +101 -0
- package/dist/report/CpuAndMemoryOverview.d.ts +19 -0
- package/dist/report/CpuAndMemoryOverview.d.ts.map +1 -0
- package/dist/report/CpuAndMemoryOverview.js +112 -0
- package/dist/report/FeatureStatusBadge.js +1 -1
- package/dist/report/ReportExportMenu.d.ts +1 -0
- package/dist/report/ReportExportMenu.d.ts.map +1 -1
- package/dist/report/ReportExportMenu.js +38 -4
- package/dist/report/StorageOverview.d.ts +27 -0
- package/dist/report/StorageOverview.d.ts.map +1 -0
- package/dist/report/StorageOverview.js +319 -0
- package/dist/report/VMMigrationStatus.d.ts +33 -0
- package/dist/report/VMMigrationStatus.d.ts.map +1 -0
- package/dist/report/VMMigrationStatus.js +129 -0
- package/dist/report/captureChartElement.d.ts +6 -1
- package/dist/report/captureChartElement.d.ts.map +1 -1
- package/dist/report/captureChartElement.js +41 -12
- package/dist/report/chartExport.d.ts +23 -0
- package/dist/report/chartExport.d.ts.map +1 -1
- package/dist/report/chartExport.js +21 -1
- package/dist/report/chartExportContext.d.ts +6 -2
- package/dist/report/chartExportContext.d.ts.map +1 -1
- package/dist/report/dashboardStyles.d.ts +6 -0
- package/dist/report/dashboardStyles.d.ts.map +1 -1
- package/dist/report/dashboardStyles.js +7 -4
- package/dist/report/index.d.ts +7 -3
- package/dist/report/index.d.ts.map +1 -1
- package/dist/report/index.js +4 -0
- package/dist/report/pdfExport.d.ts +2 -2
- package/dist/report/pdfExport.d.ts.map +1 -1
- package/dist/report/pdfExport.js +52 -3
- package/dist/report/reportExportOptions.d.ts +13 -2
- package/dist/report/reportExportOptions.d.ts.map +1 -1
- package/dist/report/reportExportOptions.js +13 -5
- package/package.json +2 -2
- package/src/charts/MigrationDonutChart.tsx +9 -0
- package/src/report/ChartExportProvider.tsx +18 -6
- package/src/report/ClustersOverview.tsx +451 -0
- package/src/report/ClustersOverviewStyles.ts +110 -0
- package/src/report/CpuAndMemoryOverview.tsx +277 -0
- package/src/report/FeatureStatusBadge.tsx +1 -1
- package/src/report/ReportExportMenu.tsx +69 -13
- package/src/report/StorageOverview.tsx +629 -0
- package/src/report/VMMigrationStatus.tsx +358 -0
- package/src/report/__tests__/ChartExportProvider.test.tsx +110 -2
- package/src/report/__tests__/ClustersOverview.test.tsx +241 -0
- package/src/report/__tests__/CpuAndMemoryOverview.test.tsx +200 -0
- package/src/report/__tests__/StorageOverview.test.tsx +223 -0
- package/src/report/__tests__/VMMigrationStatus.test.tsx +178 -0
- package/src/report/__tests__/captureChartElement.test.ts +120 -0
- package/src/report/__tests__/chartExportPackagers.test.ts +75 -0
- package/src/report/captureChartElement.ts +55 -10
- package/src/report/chartExport.ts +41 -1
- package/src/report/chartExportContext.tsx +9 -1
- package/src/report/dashboardStyles.ts +7 -4
- package/src/report/index.ts +24 -0
- package/src/report/pdfExport.ts +81 -2
- package/src/report/reportExportOptions.ts +28 -5
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import "@testing-library/jest-dom";
|
|
2
|
+
import {
|
|
3
|
+
chart_color_blue_300,
|
|
4
|
+
chart_color_purple_100,
|
|
5
|
+
chart_color_purple_300,
|
|
6
|
+
chart_color_teal_200,
|
|
7
|
+
chart_color_yellow_400,
|
|
8
|
+
} from "@patternfly/react-tokens";
|
|
9
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
10
|
+
import userEvent from "@testing-library/user-event";
|
|
11
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
12
|
+
import type { MigrationDonutChartProps } from "../../charts/MigrationDonutChart.js";
|
|
13
|
+
import {
|
|
14
|
+
ClustersOverview,
|
|
15
|
+
type InventoryDataLike,
|
|
16
|
+
} from "../ClustersOverview.js";
|
|
17
|
+
|
|
18
|
+
const donutProps = vi.hoisted(() => ({
|
|
19
|
+
current: null as MigrationDonutChartProps | null,
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
vi.mock("../../charts/MigrationDonutChart.js", () => ({
|
|
23
|
+
MigrationDonutChart: (props: MigrationDonutChartProps): JSX.Element => {
|
|
24
|
+
donutProps.current = props;
|
|
25
|
+
return (
|
|
26
|
+
<div data-testid="clusters-donut">
|
|
27
|
+
{props.title} {props.subTitle}
|
|
28
|
+
</div>
|
|
29
|
+
);
|
|
30
|
+
},
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
donutProps.current = null;
|
|
35
|
+
cleanup();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const renderedDonut = (): MigrationDonutChartProps => {
|
|
39
|
+
const props = donutProps.current;
|
|
40
|
+
if (!props) {
|
|
41
|
+
throw new Error("expected a clusters donut to render");
|
|
42
|
+
}
|
|
43
|
+
return props;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const selectView = async (name: string): Promise<void> => {
|
|
47
|
+
const user = userEvent.setup();
|
|
48
|
+
await user.click(
|
|
49
|
+
screen.getByRole("button", { name: "VM distribution by cluster" }),
|
|
50
|
+
);
|
|
51
|
+
await user.click(screen.getByRole("menuitem", { name }));
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
describe("ClustersOverview", () => {
|
|
55
|
+
it("shows the cluster empty state when no clusters were collected", () => {
|
|
56
|
+
render(<ClustersOverview />);
|
|
57
|
+
|
|
58
|
+
expect(screen.getByText("Clusters")).toBeInTheDocument();
|
|
59
|
+
expect(screen.getByText("Top 5 clusters")).toBeInTheDocument();
|
|
60
|
+
expect(screen.getByText("Cluster data not collected")).toBeInTheDocument();
|
|
61
|
+
expect(screen.queryByTestId("clusters-donut")).not.toBeInTheDocument();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("keeps the top 4 clusters and rolls the rest into one slice", () => {
|
|
65
|
+
render(
|
|
66
|
+
<ClustersOverview
|
|
67
|
+
clusters={{
|
|
68
|
+
a: { vms: { total: 10 } },
|
|
69
|
+
b: { vms: { total: 8 } },
|
|
70
|
+
c: { vms: { total: 6 } },
|
|
71
|
+
d: { vms: { total: 4 } },
|
|
72
|
+
e: { vms: { total: 3 } },
|
|
73
|
+
f: {},
|
|
74
|
+
g: { vms: { total: Number.NaN } },
|
|
75
|
+
h: { vms: { total: -2 } },
|
|
76
|
+
}}
|
|
77
|
+
/>,
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
expect(screen.getByTestId("clusters-donut")).toHaveTextContent("31 VMs");
|
|
81
|
+
|
|
82
|
+
const props = renderedDonut();
|
|
83
|
+
expect(props.data.map((slice) => [slice.name, slice.count])).toEqual([
|
|
84
|
+
["Cluster 1", 10],
|
|
85
|
+
["Cluster 2", 8],
|
|
86
|
+
["Cluster 3", 6],
|
|
87
|
+
["Cluster 4", 4],
|
|
88
|
+
["Rest of clusters", 3],
|
|
89
|
+
]);
|
|
90
|
+
expect(props.data[0]?.countDisplay).toBe("10 VMs");
|
|
91
|
+
expect(props.legend).toEqual({
|
|
92
|
+
"Cluster 1": chart_color_blue_300.value,
|
|
93
|
+
"Cluster 2": chart_color_purple_300.value,
|
|
94
|
+
"Cluster 3": chart_color_purple_100.value,
|
|
95
|
+
"Cluster 4": chart_color_teal_200.value,
|
|
96
|
+
"Rest of clusters": chart_color_yellow_400.value,
|
|
97
|
+
});
|
|
98
|
+
expect(props.legendVariant).toBe("html");
|
|
99
|
+
expect(props.height).toBe(300);
|
|
100
|
+
expect(props.width).toBe(420);
|
|
101
|
+
expect(props.donutThickness).toBe(18);
|
|
102
|
+
expect(props.titleFontSize).toBe(34);
|
|
103
|
+
expect(props.subTitleColor).toBe(
|
|
104
|
+
"var(--pf-t--global--text--color--subtle)",
|
|
105
|
+
);
|
|
106
|
+
expect(
|
|
107
|
+
props.tooltipLabelFormatter?.({
|
|
108
|
+
datum: {
|
|
109
|
+
x: "Cluster 1",
|
|
110
|
+
y: 10,
|
|
111
|
+
countDisplay: "10 VMs",
|
|
112
|
+
legendCategory: "Cluster 1",
|
|
113
|
+
},
|
|
114
|
+
percent: 32.258,
|
|
115
|
+
total: 31,
|
|
116
|
+
}),
|
|
117
|
+
).toBe("10 VMs\n32.3%");
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("passes the chart legend variant through", () => {
|
|
121
|
+
render(
|
|
122
|
+
<ClustersOverview
|
|
123
|
+
legendVariant="chart"
|
|
124
|
+
clusters={{ a: { vms: { total: 2 } } }}
|
|
125
|
+
/>,
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
expect(renderedDonut().legendVariant).toBe("chart");
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("plots cluster counts per data center and ignores non-numeric entries", async () => {
|
|
132
|
+
render(
|
|
133
|
+
<ClustersOverview
|
|
134
|
+
clustersPerDatacenter={
|
|
135
|
+
[1, 5, Number.NaN, 2, 4, 3, -1, "3"] as unknown as number[]
|
|
136
|
+
}
|
|
137
|
+
clusters={{ a: { vms: { total: 1 } } }}
|
|
138
|
+
/>,
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
await selectView("Cluster distribution by data center");
|
|
142
|
+
|
|
143
|
+
expect(screen.getByText("Top 5 datacenters")).toBeInTheDocument();
|
|
144
|
+
expect(screen.getByTestId("clusters-donut")).toHaveTextContent(
|
|
145
|
+
"15 Clusters",
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
const props = renderedDonut();
|
|
149
|
+
expect(props.data.map((slice) => [slice.name, slice.count])).toEqual([
|
|
150
|
+
["Data center 1", 5],
|
|
151
|
+
["Data center 2", 4],
|
|
152
|
+
["Data center 3", 3],
|
|
153
|
+
["Data center 4", 2],
|
|
154
|
+
["Rest of datacenters", 1],
|
|
155
|
+
]);
|
|
156
|
+
expect(props.data[4]?.countDisplay).toBe("1 clusters");
|
|
157
|
+
expect(props.subTitle).toBe("Clusters");
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("shows the cluster empty state when datacenter counts are unusable", async () => {
|
|
161
|
+
render(
|
|
162
|
+
<ClustersOverview
|
|
163
|
+
clustersPerDatacenter={"nope" as unknown as number[]}
|
|
164
|
+
clusters={{ a: { vms: { total: 1 } } }}
|
|
165
|
+
/>,
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
await selectView("Cluster distribution by data center");
|
|
169
|
+
|
|
170
|
+
expect(screen.getByText("Cluster data not collected")).toBeInTheDocument();
|
|
171
|
+
expect(screen.queryByTestId("clusters-donut")).not.toBeInTheDocument();
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("renders the top 5 CPU overcommitment ratios as boxes and a legend", async () => {
|
|
175
|
+
render(
|
|
176
|
+
<ClustersOverview
|
|
177
|
+
clusters={{
|
|
178
|
+
low: { infra: { cpuOverCommitment: 0.5 } },
|
|
179
|
+
high: { infra: { cpuOverCommitment: 8 } },
|
|
180
|
+
ratio: { infra: { cpuOverCommitment: " 1 : 4.25 " } },
|
|
181
|
+
numericString: { infra: { cpuOverCommitment: "3.5" } },
|
|
182
|
+
integer: { infra: { cpuOverCommitment: 2 } },
|
|
183
|
+
sixth: { infra: { cpuOverCommitment: 1 } },
|
|
184
|
+
}}
|
|
185
|
+
/>,
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
await selectView("Cluster CPU over commitment");
|
|
189
|
+
|
|
190
|
+
expect(screen.queryByTestId("clusters-donut")).not.toBeInTheDocument();
|
|
191
|
+
expect(screen.getByText("8")).toHaveStyle({
|
|
192
|
+
background: chart_color_blue_300.value,
|
|
193
|
+
});
|
|
194
|
+
expect(screen.getByText("4.25")).toHaveStyle({
|
|
195
|
+
background: chart_color_purple_300.value,
|
|
196
|
+
});
|
|
197
|
+
expect(screen.getByText("3.5")).toHaveStyle({
|
|
198
|
+
background: chart_color_purple_100.value,
|
|
199
|
+
});
|
|
200
|
+
expect(screen.getByText("2")).toHaveStyle({
|
|
201
|
+
background: chart_color_teal_200.value,
|
|
202
|
+
});
|
|
203
|
+
expect(screen.getByText("1")).toHaveStyle({
|
|
204
|
+
background: chart_color_yellow_400.value,
|
|
205
|
+
});
|
|
206
|
+
expect(screen.queryByText("0.5")).not.toBeInTheDocument();
|
|
207
|
+
expect(screen.getByText("Cluster 1 (8)")).toBeInTheDocument();
|
|
208
|
+
expect(screen.getByText("Cluster 5 (1)")).toBeInTheDocument();
|
|
209
|
+
expect(screen.queryByText("Cluster 6 (0.5)")).not.toBeInTheDocument();
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it("does not crash when cpuOverCommitment is missing or an unexpected shape", async () => {
|
|
213
|
+
const clusters: Record<string, InventoryDataLike> = {
|
|
214
|
+
missing: {},
|
|
215
|
+
blank: { infra: { cpuOverCommitment: " " } },
|
|
216
|
+
garbage: { infra: { cpuOverCommitment: "lots" } },
|
|
217
|
+
negative: { infra: { cpuOverCommitment: -2 } },
|
|
218
|
+
objectRatio: { infra: { cpuOverCommitment: { ratio: 4 } } },
|
|
219
|
+
nonObject: "cluster" as unknown as InventoryDataLike,
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
render(
|
|
223
|
+
<ClustersOverview
|
|
224
|
+
clusters={{
|
|
225
|
+
...clusters,
|
|
226
|
+
stringInfra: {
|
|
227
|
+
infra: "nope" as unknown as InventoryDataLike["infra"],
|
|
228
|
+
},
|
|
229
|
+
arrayClusters: ["1:4"] as unknown as InventoryDataLike,
|
|
230
|
+
}}
|
|
231
|
+
/>,
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
await selectView("Cluster CPU over commitment");
|
|
235
|
+
|
|
236
|
+
expect(
|
|
237
|
+
screen.getByText("CPU overcommitment data not collected"),
|
|
238
|
+
).toBeInTheDocument();
|
|
239
|
+
expect(screen.queryByTestId("clusters-donut")).not.toBeInTheDocument();
|
|
240
|
+
});
|
|
241
|
+
});
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import "@testing-library/jest-dom";
|
|
2
|
+
import {
|
|
3
|
+
chart_color_blue_300,
|
|
4
|
+
chart_color_purple_100,
|
|
5
|
+
chart_color_purple_300,
|
|
6
|
+
chart_color_teal_300,
|
|
7
|
+
chart_color_yellow_400,
|
|
8
|
+
} from "@patternfly/react-tokens";
|
|
9
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
10
|
+
import userEvent from "@testing-library/user-event";
|
|
11
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
12
|
+
import type { MigrationDonutChartProps } from "../../charts/MigrationDonutChart.js";
|
|
13
|
+
import { StorageOverview } from "../StorageOverview.js";
|
|
14
|
+
|
|
15
|
+
const donutProps = vi.hoisted(() => ({
|
|
16
|
+
current: null as MigrationDonutChartProps | null,
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
vi.mock("../../charts/MigrationDonutChart.js", () => ({
|
|
20
|
+
MigrationDonutChart: (props: MigrationDonutChartProps): JSX.Element => {
|
|
21
|
+
donutProps.current = props;
|
|
22
|
+
return (
|
|
23
|
+
<div data-testid="storage-donut">
|
|
24
|
+
{props.title} {props.subTitle}
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
},
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
donutProps.current = null;
|
|
32
|
+
cleanup();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const renderedDonut = (): MigrationDonutChartProps => {
|
|
36
|
+
const props = donutProps.current;
|
|
37
|
+
if (!props) {
|
|
38
|
+
throw new Error("expected a storage donut to render");
|
|
39
|
+
}
|
|
40
|
+
return props;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const selectView = async (name: string): Promise<void> => {
|
|
44
|
+
const user = userEvent.setup();
|
|
45
|
+
await user.click(
|
|
46
|
+
screen.getByRole("button", { name: "VM count by disk size tier" }),
|
|
47
|
+
);
|
|
48
|
+
await user.click(screen.getByRole("menuitem", { name }));
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
describe("StorageOverview", () => {
|
|
52
|
+
it("shows the storage empty state when no disk tiers were collected", () => {
|
|
53
|
+
render(<StorageOverview />);
|
|
54
|
+
|
|
55
|
+
expect(screen.getByText("Disks")).toBeInTheDocument();
|
|
56
|
+
expect(screen.getByText("Storage data not collected")).toBeInTheDocument();
|
|
57
|
+
expect(screen.queryByTestId("storage-donut")).not.toBeInTheDocument();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("orders VM-count tiers and totals the VM count", () => {
|
|
61
|
+
render(
|
|
62
|
+
<StorageOverview
|
|
63
|
+
diskSizeTier={{
|
|
64
|
+
Hard: { vmCount: 3, totalSizeTB: 30 },
|
|
65
|
+
Easy: { vmCount: 10, totalSizeTB: 5 },
|
|
66
|
+
Medium: { vmCount: 6, totalSizeTB: 15 },
|
|
67
|
+
}}
|
|
68
|
+
/>,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
expect(screen.getByTestId("storage-donut")).toHaveTextContent("19 VMs");
|
|
72
|
+
|
|
73
|
+
const props = renderedDonut();
|
|
74
|
+
expect(props.data.map((slice) => [slice.name, slice.count])).toEqual([
|
|
75
|
+
["0-10 TB", 10],
|
|
76
|
+
["11-20 TB", 6],
|
|
77
|
+
["21-50 TB", 3],
|
|
78
|
+
]);
|
|
79
|
+
expect(props.data[0]?.countDisplay).toBe("10 VMs");
|
|
80
|
+
expect(props.legend).toEqual({
|
|
81
|
+
Easy: chart_color_blue_300.value,
|
|
82
|
+
Medium: chart_color_purple_300.value,
|
|
83
|
+
Hard: chart_color_purple_100.value,
|
|
84
|
+
});
|
|
85
|
+
expect(props.legendVariant).toBe("html");
|
|
86
|
+
expect(props.subTitleColor).toBe(
|
|
87
|
+
"var(--pf-t--global--text--color--subtle)",
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("switches to total disk size and formats TB totals", async () => {
|
|
92
|
+
render(
|
|
93
|
+
<StorageOverview
|
|
94
|
+
diskSizeTier={{
|
|
95
|
+
Easy: { vmCount: 10, totalSizeTB: 5.5 },
|
|
96
|
+
Medium: { vmCount: 6, totalSizeTB: 15 },
|
|
97
|
+
}}
|
|
98
|
+
/>,
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
await selectView("Total disk size by tier");
|
|
102
|
+
|
|
103
|
+
const props = renderedDonut();
|
|
104
|
+
expect(props.title).toBe("20.50 TB");
|
|
105
|
+
expect(props.subTitle).toBe("16 VMs");
|
|
106
|
+
expect(props.data[0]?.countDisplay).toBe("5.50 TB");
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("drills down into a disk-size range when a tier slice is clicked", () => {
|
|
110
|
+
const onDiskTierSelect = vi.fn();
|
|
111
|
+
render(
|
|
112
|
+
<StorageOverview
|
|
113
|
+
diskSizeTier={{ Easy: { vmCount: 10, totalSizeTB: 5 } }}
|
|
114
|
+
onDiskTierSelect={onDiskTierSelect}
|
|
115
|
+
/>,
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const props = renderedDonut();
|
|
119
|
+
const slice = props.data[0];
|
|
120
|
+
if (!slice) {
|
|
121
|
+
throw new Error("expected a tier slice");
|
|
122
|
+
}
|
|
123
|
+
props.onItemClick?.(slice);
|
|
124
|
+
|
|
125
|
+
expect(onDiskTierSelect).toHaveBeenCalledWith({
|
|
126
|
+
min: 0,
|
|
127
|
+
max: 10 * 1024 * 1024,
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("renders the disk-type bar chart and its empty state", async () => {
|
|
132
|
+
const { rerender } = render(
|
|
133
|
+
<StorageOverview
|
|
134
|
+
diskTypes={{ NFS: { vmCount: 2 }, VMFS: { vmCount: 5 } }}
|
|
135
|
+
/>,
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
await selectView("VM count by disk type");
|
|
139
|
+
|
|
140
|
+
// Preferred order places VMFS before NFS.
|
|
141
|
+
const vmfs = screen.getByText("VMFS");
|
|
142
|
+
const nfs = screen.getByText("NFS");
|
|
143
|
+
expect(vmfs.compareDocumentPosition(nfs)).toBe(
|
|
144
|
+
Node.DOCUMENT_POSITION_FOLLOWING,
|
|
145
|
+
);
|
|
146
|
+
expect(
|
|
147
|
+
screen.getByText(/Totals may exceed the unique VM count/),
|
|
148
|
+
).toBeInTheDocument();
|
|
149
|
+
|
|
150
|
+
rerender(<StorageOverview diskTypes={{}} />);
|
|
151
|
+
expect(
|
|
152
|
+
screen.getByText("Disk type data not collected"),
|
|
153
|
+
).toBeInTheDocument();
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("renders the shared-disks donut", async () => {
|
|
157
|
+
render(<StorageOverview totalVMs={10} totalWithSharedDisks={4} />);
|
|
158
|
+
|
|
159
|
+
await selectView("Shared disks VS. No shared disks");
|
|
160
|
+
|
|
161
|
+
const props = renderedDonut();
|
|
162
|
+
expect(props.title).toBe("10 VMs");
|
|
163
|
+
expect(props.subTitle).toBe("4 with shared disks");
|
|
164
|
+
expect(props.data.map((slice) => [slice.name, slice.count])).toEqual([
|
|
165
|
+
["With shared disks", 4],
|
|
166
|
+
["No shared disks", 6],
|
|
167
|
+
]);
|
|
168
|
+
expect(props.customColors).toEqual({
|
|
169
|
+
"With shared disks": chart_color_yellow_400.value,
|
|
170
|
+
"No shared disks": chart_color_blue_300.value,
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("disables the shared-disks view when no VMs have shared disks", async () => {
|
|
175
|
+
const user = userEvent.setup();
|
|
176
|
+
render(<StorageOverview totalVMs={10} totalWithSharedDisks={0} />);
|
|
177
|
+
|
|
178
|
+
await user.click(
|
|
179
|
+
screen.getByRole("button", { name: "VM count by disk size tier" }),
|
|
180
|
+
);
|
|
181
|
+
const sharedItem = screen.getByRole("menuitem", {
|
|
182
|
+
name: "Shared disks VS. No shared disks",
|
|
183
|
+
});
|
|
184
|
+
expect(sharedItem).toBeDisabled();
|
|
185
|
+
|
|
186
|
+
await user.click(sharedItem);
|
|
187
|
+
// The disabled item does not switch the active view.
|
|
188
|
+
expect(
|
|
189
|
+
screen.getByRole("button", { name: "VM count by disk size tier" }),
|
|
190
|
+
).toBeInTheDocument();
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("passes the chart legend variant through", () => {
|
|
194
|
+
render(
|
|
195
|
+
<StorageOverview
|
|
196
|
+
legendVariant="chart"
|
|
197
|
+
diskSizeTier={{ Easy: { vmCount: 2, totalSizeTB: 1 } }}
|
|
198
|
+
/>,
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
expect(renderedDonut().legendVariant).toBe("chart");
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("keeps the configured tier palette aligned with the categorical order", () => {
|
|
205
|
+
render(
|
|
206
|
+
<StorageOverview
|
|
207
|
+
diskSizeTier={{
|
|
208
|
+
Easy: { vmCount: 1 },
|
|
209
|
+
Medium: { vmCount: 1 },
|
|
210
|
+
Hard: { vmCount: 1 },
|
|
211
|
+
White: { vmCount: 1 },
|
|
212
|
+
}}
|
|
213
|
+
/>,
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
expect(renderedDonut().legend).toEqual({
|
|
217
|
+
Easy: chart_color_blue_300.value,
|
|
218
|
+
Medium: chart_color_purple_300.value,
|
|
219
|
+
Hard: chart_color_purple_100.value,
|
|
220
|
+
"White glove": chart_color_teal_300.value,
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
});
|