@openshift-migration-advisor/shared-components 0.28.0 → 0.29.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.
Files changed (44) hide show
  1. package/dist/charts/MigrationDonutChart.d.ts.map +1 -1
  2. package/dist/charts/MigrationDonutChart.js +15 -4
  3. package/dist/report/ChartExportProvider.d.ts +1 -1
  4. package/dist/report/ChartExportProvider.d.ts.map +1 -1
  5. package/dist/report/ChartExportProvider.js +4 -1
  6. package/dist/report/FeatureStatusBadge.js +1 -1
  7. package/dist/report/ReportExportMenu.d.ts +1 -0
  8. package/dist/report/ReportExportMenu.d.ts.map +1 -1
  9. package/dist/report/ReportExportMenu.js +38 -4
  10. package/dist/report/StorageOverview.d.ts +27 -0
  11. package/dist/report/StorageOverview.d.ts.map +1 -0
  12. package/dist/report/StorageOverview.js +331 -0
  13. package/dist/report/VMMigrationStatus.d.ts +33 -0
  14. package/dist/report/VMMigrationStatus.d.ts.map +1 -0
  15. package/dist/report/VMMigrationStatus.js +129 -0
  16. package/dist/report/captureChartElement.d.ts +6 -1
  17. package/dist/report/captureChartElement.d.ts.map +1 -1
  18. package/dist/report/captureChartElement.js +13 -4
  19. package/dist/report/chartExport.js +1 -1
  20. package/dist/report/dashboardStyles.d.ts +6 -0
  21. package/dist/report/dashboardStyles.d.ts.map +1 -1
  22. package/dist/report/dashboardStyles.js +7 -4
  23. package/dist/report/index.d.ts +3 -1
  24. package/dist/report/index.d.ts.map +1 -1
  25. package/dist/report/index.js +2 -0
  26. package/dist/report/reportExportOptions.d.ts +13 -2
  27. package/dist/report/reportExportOptions.d.ts.map +1 -1
  28. package/dist/report/reportExportOptions.js +13 -5
  29. package/package.json +2 -2
  30. package/src/charts/MigrationDonutChart.tsx +27 -6
  31. package/src/charts/__tests__/MigrationDonutChart.test.tsx +53 -0
  32. package/src/report/ChartExportProvider.tsx +5 -1
  33. package/src/report/FeatureStatusBadge.tsx +1 -1
  34. package/src/report/ReportExportMenu.tsx +69 -13
  35. package/src/report/StorageOverview.tsx +646 -0
  36. package/src/report/VMMigrationStatus.tsx +358 -0
  37. package/src/report/__tests__/StorageOverview.test.tsx +267 -0
  38. package/src/report/__tests__/VMMigrationStatus.test.tsx +178 -0
  39. package/src/report/__tests__/captureChartElement.test.ts +47 -0
  40. package/src/report/captureChartElement.ts +18 -3
  41. package/src/report/chartExport.ts +1 -1
  42. package/src/report/dashboardStyles.ts +7 -4
  43. package/src/report/index.ts +12 -0
  44. package/src/report/reportExportOptions.ts +28 -5
@@ -0,0 +1,358 @@
1
+ import { css } from "@emotion/css";
2
+ import {
3
+ Card,
4
+ CardBody,
5
+ CardTitle,
6
+ Content,
7
+ Dropdown,
8
+ DropdownItem,
9
+ DropdownList,
10
+ Flex,
11
+ FlexItem,
12
+ MenuToggle,
13
+ type MenuToggleElement,
14
+ } from "@patternfly/react-core";
15
+ import { VirtualMachineIcon } from "@patternfly/react-icons";
16
+ import {
17
+ chart_color_blue_300,
18
+ chart_color_purple_100,
19
+ chart_color_purple_300,
20
+ chart_color_teal_200,
21
+ chart_color_yellow_400,
22
+ } from "@patternfly/react-tokens";
23
+ import type { FC, Ref } from "react";
24
+ import { useMemo, useState } from "react";
25
+ import {
26
+ MigrationDonutChart,
27
+ type MigrationDonutChartLegendVariant,
28
+ } from "../charts/MigrationDonutChart.js";
29
+ import { CardEmptyState } from "./CardEmptyState.js";
30
+ import { ChartHeaderActions } from "./ChartDownloadButton.js";
31
+ import { ChartExportSurface } from "./ChartExportSurface.js";
32
+ import { chartExportViewsFromLabels } from "./chartExport.js";
33
+ import {
34
+ chartColorFailure,
35
+ chartColorSuccess,
36
+ REPORT_CARD_EMPTY_STATE_TITLES,
37
+ } from "./constants.js";
38
+ import { dashboardStyles } from "./dashboardStyles.js";
39
+
40
+ /**
41
+ * VM-issue counts this card reads. agent-sdk's `IssuesBreakdown` satisfies it;
42
+ * each field stays optional so older or partial payloads do not throw.
43
+ */
44
+ export interface IssuesBreakdownLike {
45
+ critical?: number;
46
+ error?: number;
47
+ warning?: number;
48
+ information?: number;
49
+ advisory?: number;
50
+ }
51
+
52
+ export interface VMMigrationStatusProps {
53
+ data: {
54
+ migratable: number;
55
+ nonMigratable: number;
56
+ };
57
+ issuesBreakdown?: IssuesBreakdownLike;
58
+ /**
59
+ * Donut-slice click. `true` for the migratable slice, `false` otherwise.
60
+ * Agent-ui maps it to a VM migration-readiness filter; ui-app omits it.
61
+ */
62
+ onReadinessSelect?: (isMigratable: boolean) => void;
63
+ /** Breakdown-bar click. The argument is the concern category label. */
64
+ onCategorySelect?: (category: string) => void;
65
+ /** Center-title click. Agent-ui opens the VM list with no extra filters. */
66
+ onTitleClick?: () => void;
67
+ /** `"html"` in agent-ui; ui-app passes `"chart"`. */
68
+ legendVariant?: MigrationDonutChartLegendVariant;
69
+ }
70
+
71
+ type ViewMode = "issuesVsNoIssues" | "issuesBreakdown";
72
+
73
+ const VIEW_MODE_LABELS: Record<ViewMode, string> = {
74
+ issuesVsNoIssues: "No issues vs with issues",
75
+ issuesBreakdown: "With issues breakdown",
76
+ };
77
+
78
+ const CHART_ID = "vm-migration-status";
79
+ const CHART_TITLE = "VM migration status";
80
+
81
+ const MIGRATABLE_LABEL = "Migratable";
82
+ const NOT_MIGRATABLE_LABEL = "Not ready for migration";
83
+
84
+ const CATEGORY_ORDER: Array<{ label: string; key: keyof IssuesBreakdownLike }> =
85
+ [
86
+ { label: "Critical", key: "critical" },
87
+ { label: "Error", key: "error" },
88
+ { label: "Warning", key: "warning" },
89
+ { label: "Information", key: "information" },
90
+ { label: "Advisory", key: "advisory" },
91
+ ];
92
+
93
+ /**
94
+ * Same categorical order as the previous breakdown hex palette, mapped onto
95
+ * PatternFly `chart_color_*` tokens (nearest token where the old hex was not
96
+ * itself a token).
97
+ */
98
+ const CATEGORY_COLORS: Record<string, string> = {
99
+ Critical: chart_color_blue_300.value,
100
+ Error: chart_color_purple_300.value,
101
+ Warning: chart_color_purple_100.value,
102
+ Information: chart_color_teal_200.value,
103
+ Advisory: chart_color_yellow_400.value,
104
+ };
105
+
106
+ const menuToggleMinWidth = css`
107
+ min-width: 250px;
108
+ `;
109
+
110
+ const isViewMode = (value: string | number | undefined): value is ViewMode =>
111
+ value === "issuesVsNoIssues" || value === "issuesBreakdown";
112
+
113
+ const toCount = (value: number | undefined): number =>
114
+ typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
115
+
116
+ export const VMMigrationStatus: FC<VMMigrationStatusProps> = ({
117
+ data,
118
+ issuesBreakdown,
119
+ onReadinessSelect,
120
+ onCategorySelect,
121
+ onTitleClick,
122
+ legendVariant = "html",
123
+ }) => {
124
+ const [viewMode, setViewMode] = useState<ViewMode>("issuesVsNoIssues");
125
+ const [isDropdownOpen, setIsDropdownOpen] = useState(false);
126
+
127
+ const totalVMs = data.migratable + data.nonMigratable;
128
+
129
+ const donutData = [
130
+ {
131
+ name: MIGRATABLE_LABEL,
132
+ count: data.migratable,
133
+ countDisplay: `${data.migratable} VMs`,
134
+ legendCategory: MIGRATABLE_LABEL,
135
+ },
136
+ {
137
+ name: NOT_MIGRATABLE_LABEL,
138
+ count: data.nonMigratable,
139
+ countDisplay: `${data.nonMigratable} VMs`,
140
+ legendCategory: NOT_MIGRATABLE_LABEL,
141
+ },
142
+ ];
143
+
144
+ const legend = {
145
+ [MIGRATABLE_LABEL]: chartColorSuccess,
146
+ [NOT_MIGRATABLE_LABEL]: chartColorFailure,
147
+ };
148
+
149
+ const breakdownData = useMemo(() => {
150
+ if (!issuesBreakdown) {
151
+ return [];
152
+ }
153
+ return CATEGORY_ORDER.map(({ label, key }) => ({
154
+ name: label,
155
+ count: toCount(issuesBreakdown[key]),
156
+ }));
157
+ }, [issuesBreakdown]);
158
+
159
+ const maxCount = useMemo(
160
+ () =>
161
+ breakdownData.length > 0
162
+ ? Math.max(...breakdownData.map((d) => d.count))
163
+ : 0,
164
+ [breakdownData],
165
+ );
166
+
167
+ const chartTitle = `${CHART_TITLE} — ${VIEW_MODE_LABELS[viewMode]}`;
168
+
169
+ return (
170
+ <ChartExportSurface
171
+ id={CHART_ID}
172
+ title={chartTitle}
173
+ exportViews={chartExportViewsFromLabels(CHART_TITLE, VIEW_MODE_LABELS)}
174
+ activeExportViewId={viewMode}
175
+ onExportViewChange={(viewId) => {
176
+ if (isViewMode(viewId)) {
177
+ setViewMode(viewId);
178
+ }
179
+ }}
180
+ >
181
+ <Card className={dashboardStyles.card}>
182
+ <CardTitle>
183
+ <Flex
184
+ alignItems={{ default: "alignItemsCenter" }}
185
+ justifyContent={{ default: "justifyContentSpaceBetween" }}
186
+ >
187
+ <FlexItem>
188
+ <VirtualMachineIcon /> VM Migration Status
189
+ </FlexItem>
190
+ <ChartHeaderActions chartId={CHART_ID} title={chartTitle}>
191
+ <Dropdown
192
+ isOpen={isDropdownOpen}
193
+ onSelect={(_event, value) => {
194
+ if (isViewMode(value)) {
195
+ setViewMode(value);
196
+ }
197
+ setIsDropdownOpen(false);
198
+ }}
199
+ onOpenChange={setIsDropdownOpen}
200
+ toggle={(toggleRef: Ref<MenuToggleElement>) => (
201
+ <MenuToggle
202
+ ref={toggleRef}
203
+ onClick={() => setIsDropdownOpen((open) => !open)}
204
+ isExpanded={isDropdownOpen}
205
+ className={menuToggleMinWidth}
206
+ >
207
+ {VIEW_MODE_LABELS[viewMode]}
208
+ </MenuToggle>
209
+ )}
210
+ >
211
+ <DropdownList>
212
+ <DropdownItem value="issuesVsNoIssues" key="issuesVsNoIssues">
213
+ {VIEW_MODE_LABELS.issuesVsNoIssues}
214
+ </DropdownItem>
215
+ <DropdownItem value="issuesBreakdown" key="issuesBreakdown">
216
+ {VIEW_MODE_LABELS.issuesBreakdown}
217
+ </DropdownItem>
218
+ </DropdownList>
219
+ </Dropdown>
220
+ </ChartHeaderActions>
221
+ </Flex>
222
+ </CardTitle>
223
+ <CardBody className={dashboardStyles.cardBodyScrollable}>
224
+ {viewMode === "issuesVsNoIssues" ? (
225
+ totalVMs === 0 ? (
226
+ <CardEmptyState
227
+ title={REPORT_CARD_EMPTY_STATE_TITLES.migrationStatus}
228
+ />
229
+ ) : (
230
+ <MigrationDonutChart
231
+ legendVariant={legendVariant}
232
+ data={donutData}
233
+ legend={legend}
234
+ height={300}
235
+ width={420}
236
+ donutThickness={18}
237
+ padAngle={1}
238
+ title={`${totalVMs}`}
239
+ subTitle="VMs"
240
+ subTitleColor="var(--pf-t--global--text--color--subtle)"
241
+ titleFontSize={34}
242
+ legendLabelFormatter={({ x, countDisplay }) =>
243
+ `${x} (${countDisplay})`
244
+ }
245
+ onItemClick={
246
+ onReadinessSelect
247
+ ? (item) =>
248
+ onReadinessSelect(item.name === MIGRATABLE_LABEL)
249
+ : undefined
250
+ }
251
+ onTitleClick={onTitleClick}
252
+ />
253
+ )
254
+ ) : breakdownData.length === 0 ? (
255
+ <CardEmptyState
256
+ title={REPORT_CARD_EMPTY_STATE_TITLES.issuesBreakdown}
257
+ />
258
+ ) : (
259
+ <div>
260
+ <div className={dashboardStyles.storageChartWrapper}>
261
+ <Flex
262
+ direction={{ default: "row" }}
263
+ alignItems={{ default: "alignItemsFlexEnd" }}
264
+ justifyContent={{ default: "justifyContentCenter" }}
265
+ spaceItems={{ default: "spaceItemsMd" }}
266
+ style={{
267
+ height: "250px",
268
+ width: "100%",
269
+ }}
270
+ >
271
+ {breakdownData.map((item) => {
272
+ const heightPercentage =
273
+ maxCount > 0 ? (item.count / maxCount) * 100 : 0;
274
+ const minHeightPercentage = item.count > 0 ? 20 : 0;
275
+ const finalHeightPercentage = Math.max(
276
+ heightPercentage,
277
+ minHeightPercentage,
278
+ );
279
+ const barColor =
280
+ CATEGORY_COLORS[item.name] || CATEGORY_COLORS.Critical;
281
+
282
+ return (
283
+ <Flex
284
+ key={item.name}
285
+ direction={{ default: "column" }}
286
+ alignItems={{ default: "alignItemsCenter" }}
287
+ spaceItems={{ default: "spaceItemsSm" }}
288
+ style={{ flex: "1", maxWidth: "120px" }}
289
+ >
290
+ <FlexItem
291
+ style={{
292
+ height: "200px",
293
+ display: "flex",
294
+ alignItems: "flex-end",
295
+ width: "100%",
296
+ justifyContent: "center",
297
+ }}
298
+ >
299
+ <button
300
+ type="button"
301
+ onClick={() => onCategorySelect?.(item.name)}
302
+ title={`${item.name}: ${item.count} VMs`}
303
+ style={{
304
+ width: "60px",
305
+ height: `${finalHeightPercentage}%`,
306
+ backgroundColor: barColor,
307
+ transition: "height 0.3s ease",
308
+ borderRadius: "4px 4px 0 0",
309
+ cursor: "pointer",
310
+ border: "none",
311
+ padding: 0,
312
+ }}
313
+ />
314
+ </FlexItem>
315
+ <FlexItem>
316
+ <Content
317
+ component="small"
318
+ style={{
319
+ fontSize: "12px",
320
+ textAlign: "center",
321
+ wordBreak: "break-word",
322
+ color:
323
+ "var(--pf-t--global--text--color--regular)",
324
+ }}
325
+ >
326
+ {item.name}
327
+ <br />({item.count} VMs)
328
+ </Content>
329
+ </FlexItem>
330
+ </Flex>
331
+ );
332
+ })}
333
+ </Flex>
334
+ </div>
335
+ <div>
336
+ <Content
337
+ component="small"
338
+ style={{
339
+ fontSize: "12px",
340
+ color: "var(--pf-t--global--text--color--subtle)",
341
+ marginTop: "16px",
342
+ textAlign: "center",
343
+ display: "block",
344
+ }}
345
+ >
346
+ Totals may exceed the unique VM count because a VM can appear
347
+ in multiple categories
348
+ </Content>
349
+ </div>
350
+ </div>
351
+ )}
352
+ </CardBody>
353
+ </Card>
354
+ </ChartExportSurface>
355
+ );
356
+ };
357
+
358
+ VMMigrationStatus.displayName = "VMMigrationStatus";
@@ -0,0 +1,267 @@
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
+ vi.mock("../ChartExportSurface.js", () => ({
31
+ ChartExportSurface: ({
32
+ exportViews,
33
+ children,
34
+ }: {
35
+ exportViews?: Array<{ id: string; title: string }>;
36
+ children?: React.ReactNode;
37
+ }): JSX.Element => (
38
+ <div
39
+ data-testid="chart-export-surface"
40
+ data-export-view-ids={JSON.stringify(exportViews?.map((view) => view.id))}
41
+ >
42
+ {children}
43
+ </div>
44
+ ),
45
+ }));
46
+
47
+ afterEach(() => {
48
+ donutProps.current = null;
49
+ cleanup();
50
+ });
51
+
52
+ const renderedDonut = (): MigrationDonutChartProps => {
53
+ const props = donutProps.current;
54
+ if (!props) {
55
+ throw new Error("expected a storage donut to render");
56
+ }
57
+ return props;
58
+ };
59
+
60
+ const selectView = async (name: string): Promise<void> => {
61
+ const user = userEvent.setup();
62
+ await user.click(
63
+ screen.getByRole("button", { name: "VM count by disk size tier" }),
64
+ );
65
+ await user.click(screen.getByRole("menuitem", { name }));
66
+ };
67
+
68
+ describe("StorageOverview", () => {
69
+ it("shows the storage empty state when no disk tiers were collected", () => {
70
+ render(<StorageOverview />);
71
+
72
+ expect(screen.getByText("Disks")).toBeInTheDocument();
73
+ expect(screen.getByText("Storage data not collected")).toBeInTheDocument();
74
+ expect(screen.queryByTestId("storage-donut")).not.toBeInTheDocument();
75
+ });
76
+
77
+ it("orders VM-count tiers and totals the VM count", () => {
78
+ render(
79
+ <StorageOverview
80
+ diskSizeTier={{
81
+ Hard: { vmCount: 3, totalSizeTB: 30 },
82
+ Easy: { vmCount: 10, totalSizeTB: 5 },
83
+ Medium: { vmCount: 6, totalSizeTB: 15 },
84
+ }}
85
+ />,
86
+ );
87
+
88
+ expect(screen.getByTestId("storage-donut")).toHaveTextContent("19 VMs");
89
+
90
+ const props = renderedDonut();
91
+ expect(props.data.map((slice) => [slice.name, slice.count])).toEqual([
92
+ ["0-10 TB", 10],
93
+ ["11-20 TB", 6],
94
+ ["21-50 TB", 3],
95
+ ]);
96
+ expect(props.data[0]?.countDisplay).toBe("10 VMs");
97
+ expect(props.legend).toEqual({
98
+ Easy: chart_color_blue_300.value,
99
+ Medium: chart_color_purple_300.value,
100
+ Hard: chart_color_purple_100.value,
101
+ });
102
+ expect(props.legendVariant).toBe("html");
103
+ expect(props.subTitleColor).toBe(
104
+ "var(--pf-t--global--text--color--subtle)",
105
+ );
106
+ });
107
+
108
+ it("switches to total disk size and formats TB totals", async () => {
109
+ render(
110
+ <StorageOverview
111
+ diskSizeTier={{
112
+ Easy: { vmCount: 10, totalSizeTB: 5.5 },
113
+ Medium: { vmCount: 6, totalSizeTB: 15 },
114
+ }}
115
+ />,
116
+ );
117
+
118
+ await selectView("Total disk size by tier");
119
+
120
+ const props = renderedDonut();
121
+ expect(props.title).toBe("20.50 TB");
122
+ expect(props.subTitle).toBe("16 VMs");
123
+ expect(props.data[0]?.countDisplay).toBe("5.50 TB");
124
+ });
125
+
126
+ it("drills down into a disk-size range when a tier slice is clicked", () => {
127
+ const onDiskTierSelect = vi.fn();
128
+ render(
129
+ <StorageOverview
130
+ diskSizeTier={{ Easy: { vmCount: 10, totalSizeTB: 5 } }}
131
+ onDiskTierSelect={onDiskTierSelect}
132
+ />,
133
+ );
134
+
135
+ const props = renderedDonut();
136
+ const slice = props.data[0];
137
+ if (!slice) {
138
+ throw new Error("expected a tier slice");
139
+ }
140
+ props.onItemClick?.(slice);
141
+
142
+ expect(onDiskTierSelect).toHaveBeenCalledWith({
143
+ min: 0,
144
+ max: 10 * 1024 * 1024,
145
+ });
146
+ });
147
+
148
+ it("renders the disk-type bar chart and its empty state", async () => {
149
+ const { rerender } = render(
150
+ <StorageOverview
151
+ diskTypes={{ NFS: { vmCount: 2 }, VMFS: { vmCount: 5 } }}
152
+ />,
153
+ );
154
+
155
+ await selectView("VM count by disk type");
156
+
157
+ // Preferred order places VMFS before NFS.
158
+ const vmfs = screen.getByText("VMFS");
159
+ const nfs = screen.getByText("NFS");
160
+ expect(vmfs.compareDocumentPosition(nfs)).toBe(
161
+ Node.DOCUMENT_POSITION_FOLLOWING,
162
+ );
163
+ expect(
164
+ screen.getByText(/Totals may exceed the unique VM count/),
165
+ ).toBeInTheDocument();
166
+
167
+ rerender(<StorageOverview diskTypes={{}} />);
168
+ expect(
169
+ screen.getByText("Disk type data not collected"),
170
+ ).toBeInTheDocument();
171
+ });
172
+
173
+ it("renders the shared-disks donut", async () => {
174
+ render(<StorageOverview totalVMs={10} totalWithSharedDisks={4} />);
175
+
176
+ await selectView("Shared disks VS. No shared disks");
177
+
178
+ const props = renderedDonut();
179
+ expect(props.title).toBe("10 VMs");
180
+ expect(props.subTitle).toBe("4 with shared disks");
181
+ expect(props.data.map((slice) => [slice.name, slice.count])).toEqual([
182
+ ["With shared disks", 4],
183
+ ["No shared disks", 6],
184
+ ]);
185
+ expect(props.customColors).toEqual({
186
+ "With shared disks": chart_color_yellow_400.value,
187
+ "No shared disks": chart_color_blue_300.value,
188
+ });
189
+ });
190
+
191
+ it("excludes the shared disks view from the chart export cycle when disabled, so PDF/PNG/HTML exports stay consistent with the dropdown", () => {
192
+ render(<StorageOverview totalVMs={10} totalWithSharedDisks={0} />);
193
+
194
+ const exportViewIds = JSON.parse(
195
+ screen
196
+ .getByTestId("chart-export-surface")
197
+ .getAttribute("data-export-view-ids") || "[]",
198
+ ) as string[];
199
+
200
+ expect(exportViewIds).not.toContain("sharedDisks");
201
+ expect(exportViewIds).toEqual(
202
+ expect.arrayContaining(["totalSize", "vmCount", "vmCountByDiskType"]),
203
+ );
204
+ });
205
+
206
+ it("includes the shared disks view in the chart export cycle when available", () => {
207
+ render(<StorageOverview totalVMs={10} totalWithSharedDisks={4} />);
208
+
209
+ const exportViewIds = JSON.parse(
210
+ screen
211
+ .getByTestId("chart-export-surface")
212
+ .getAttribute("data-export-view-ids") || "[]",
213
+ ) as string[];
214
+
215
+ expect(exportViewIds).toContain("sharedDisks");
216
+ });
217
+
218
+ it("disables the shared-disks view when no VMs have shared disks", async () => {
219
+ const user = userEvent.setup();
220
+ render(<StorageOverview totalVMs={10} totalWithSharedDisks={0} />);
221
+
222
+ await user.click(
223
+ screen.getByRole("button", { name: "VM count by disk size tier" }),
224
+ );
225
+ const sharedItem = screen.getByRole("menuitem", {
226
+ name: "Shared disks VS. No shared disks",
227
+ });
228
+ expect(sharedItem).toBeDisabled();
229
+
230
+ await user.click(sharedItem);
231
+ // The disabled item does not switch the active view.
232
+ expect(
233
+ screen.getByRole("button", { name: "VM count by disk size tier" }),
234
+ ).toBeInTheDocument();
235
+ });
236
+
237
+ it("passes the chart legend variant through", () => {
238
+ render(
239
+ <StorageOverview
240
+ legendVariant="chart"
241
+ diskSizeTier={{ Easy: { vmCount: 2, totalSizeTB: 1 } }}
242
+ />,
243
+ );
244
+
245
+ expect(renderedDonut().legendVariant).toBe("chart");
246
+ });
247
+
248
+ it("keeps the configured tier palette aligned with the categorical order", () => {
249
+ render(
250
+ <StorageOverview
251
+ diskSizeTier={{
252
+ Easy: { vmCount: 1 },
253
+ Medium: { vmCount: 1 },
254
+ Hard: { vmCount: 1 },
255
+ White: { vmCount: 1 },
256
+ }}
257
+ />,
258
+ );
259
+
260
+ expect(renderedDonut().legend).toEqual({
261
+ Easy: chart_color_blue_300.value,
262
+ Medium: chart_color_purple_300.value,
263
+ Hard: chart_color_purple_100.value,
264
+ "White glove": chart_color_teal_300.value,
265
+ });
266
+ });
267
+ });