@openshift-migration-advisor/shared-components 0.27.0-5d313f88dc52 → 0.27.0-ad43dbdf05ab
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/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/index.d.ts +2 -0
- package/dist/report/index.d.ts.map +1 -1
- package/dist/report/index.js +2 -0
- package/package.json +2 -2
- package/src/report/ClustersOverview.tsx +451 -0
- package/src/report/ClustersOverviewStyles.ts +110 -0
- package/src/report/CpuAndMemoryOverview.tsx +277 -0
- package/src/report/__tests__/ClustersOverview.test.tsx +241 -0
- package/src/report/__tests__/CpuAndMemoryOverview.test.tsx +200 -0
- package/src/report/index.ts +9 -0
|
@@ -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
|
+
});
|
package/src/report/index.ts
CHANGED
|
@@ -17,6 +17,15 @@ export {
|
|
|
17
17
|
type ZipChartFiles,
|
|
18
18
|
} from "./ChartExportProvider.js";
|
|
19
19
|
export { ChartExportSurface } from "./ChartExportSurface.js";
|
|
20
|
+
export {
|
|
21
|
+
ClustersOverview,
|
|
22
|
+
type ClustersOverviewProps,
|
|
23
|
+
type InventoryDataLike,
|
|
24
|
+
} from "./ClustersOverview.js";
|
|
25
|
+
export {
|
|
26
|
+
CpuAndMemoryOverview,
|
|
27
|
+
type CpuAndMemoryOverviewProps,
|
|
28
|
+
} from "./CpuAndMemoryOverview.js";
|
|
20
29
|
export { captureChartElement } from "./captureChartElement.js";
|
|
21
30
|
export {
|
|
22
31
|
CHART_EXPORT_CAPTURING_ATTR,
|