Some checks failed
PR Review Automation / review (pull_request) Has been cancelled
Test / frontend-typecheck (pull_request) Has been cancelled
Test / rust-clippy (pull_request) Has been cancelled
Test / frontend-tests (pull_request) Has been cancelled
Test / rust-fmt-check (pull_request) Has been cancelled
Test / rust-tests (pull_request) Has been cancelled
Complete overhaul of the Kubernetes management page from a basic config panel into a full Lens-style IDE shell with 26 resource types, real-time data, and a comprehensive test suite. Layout & navigation: - Rewrite KubernetesPage as a Lens v5-style shell: collapsible sidebar (Workloads / Services & Networking / Config & Storage / Access Control / Cluster), top hotbar with cluster+namespace selectors, Ctrl+K command palette - All 26 resource types now accessible via sidebar navigation (previously 5) New resource types (Rust + TypeScript + React): - StorageClasses, NetworkPolicies, ResourceQuotas, LimitRanges - 4 new Tauri commands registered in generate_handler![] Component implementations (replacing stubs with real IPC): - Terminal: full xterm.js with multi-tab sessions and exec_pod IPC - YamlEditor: Monaco editor with YAML syntax highlighting - MetricsChart: recharts LineChart/BarChart - ClusterOverview: live node/pod/deployment/namespace counts - ClusterDetails: real kubeconfig + node data - PodDetail, DeploymentDetail, ServiceDetail, ConfigMapDetail, SecretDetail: all connected to real IPC data, zero hardcoded values - CreateResourceModal, EditResourceModal: wired to createResourceCmd / editResourceCmd - RbacViewer: live data from 4 RBAC IPC commands - RbacEditor: create roles/cluster-roles via YAML editor - CommandPalette: 12 real navigation commands, keyboard nav Dependencies added: xterm@5, xterm-addon-fit, xterm-addon-web-links, @monaco-editor/react@4, recharts@2 Tooling: - Replace eslint-plugin-react (incompatible with ESLint 10) with @eslint-react/eslint-plugin; fix eslint.config.js for flat config - Fix pre-existing hoisting lint errors in Security.tsx, PortForwardForm.tsx - Fix eventBus.ts: replace all `any` generics with `unknown` Tests: 251 passing across 35 test files (was 94/19) - 16 new test files covering all new and fixed components (TDD) - npx tsc --noEmit: 0 errors - cargo clippy -- -D warnings: 0 warnings - cargo fmt --check: passes - eslint src/ --max-warnings 0: 0 issues
89 lines
3.0 KiB
TypeScript
89 lines
3.0 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { render, screen, fireEvent } from "@testing-library/react";
|
|
import { YamlEditor } from "@/components/Kubernetes/YamlEditor";
|
|
|
|
vi.mock("@monaco-editor/react", () => ({
|
|
default: ({
|
|
value,
|
|
onChange,
|
|
}: {
|
|
value?: string;
|
|
onChange?: (v: string | undefined) => void;
|
|
}) => (
|
|
<textarea
|
|
data-testid="monaco-editor"
|
|
value={value ?? ""}
|
|
onChange={(e) => onChange?.(e.target.value)}
|
|
readOnly={false}
|
|
/>
|
|
),
|
|
}));
|
|
|
|
describe("YamlEditor", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it("renders without crashing", () => {
|
|
render(<YamlEditor />);
|
|
expect(screen.getByTestId("monaco-editor")).toBeInTheDocument();
|
|
});
|
|
|
|
it("renders Monaco editor with initial content", () => {
|
|
const content = "apiVersion: v1\nkind: Pod";
|
|
render(<YamlEditor content={content} />);
|
|
const editor = screen.getByTestId("monaco-editor") as HTMLTextAreaElement;
|
|
expect(editor.value).toBe(content);
|
|
});
|
|
|
|
it("Apply button fires onApply with current YAML content", () => {
|
|
const onApply = vi.fn();
|
|
const content = "apiVersion: v1\nkind: Service";
|
|
render(<YamlEditor content={content} showControls onApply={onApply} />);
|
|
|
|
const editor = screen.getByTestId("monaco-editor") as HTMLTextAreaElement;
|
|
fireEvent.change(editor, { target: { value: "apiVersion: v1\nkind: Pod" } });
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: /apply/i }));
|
|
expect(onApply).toHaveBeenCalledWith("apiVersion: v1\nkind: Pod");
|
|
});
|
|
|
|
it("Apply button also fires onChange with YAML content", () => {
|
|
const onChange = vi.fn();
|
|
const content = "apiVersion: v1\nkind: Service";
|
|
render(<YamlEditor content={content} showControls onChange={onChange} />);
|
|
|
|
const editor = screen.getByTestId("monaco-editor") as HTMLTextAreaElement;
|
|
fireEvent.change(editor, { target: { value: "new: yaml" } });
|
|
fireEvent.click(screen.getByRole("button", { name: /apply/i }));
|
|
|
|
expect(onChange).toHaveBeenCalledWith("new: yaml");
|
|
});
|
|
|
|
it("Cancel button fires onCancel callback", () => {
|
|
const onCancel = vi.fn();
|
|
render(<YamlEditor showControls onCancel={onCancel} />);
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: /cancel/i }));
|
|
expect(onCancel).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("showControls defaults to true — Apply and Cancel are visible", () => {
|
|
render(<YamlEditor />);
|
|
expect(screen.getByRole("button", { name: /apply/i })).toBeInTheDocument();
|
|
expect(screen.getByRole("button", { name: /cancel/i })).toBeInTheDocument();
|
|
});
|
|
|
|
it("showControls=false hides Apply and Cancel buttons", () => {
|
|
render(<YamlEditor showControls={false} />);
|
|
expect(screen.queryByRole("button", { name: /apply/i })).toBeNull();
|
|
expect(screen.queryByRole("button", { name: /cancel/i })).toBeNull();
|
|
});
|
|
|
|
it("readOnly=true disables the Apply button", () => {
|
|
render(<YamlEditor readOnly showControls />);
|
|
const applyBtn = screen.getByRole("button", { name: /apply/i });
|
|
expect(applyBtn).toBeDisabled();
|
|
});
|
|
});
|