Some checks failed
PR Review Automation / review (pull_request) Has been cancelled
Test / frontend-tests (pull_request) Successful in 1m37s
Test / frontend-typecheck (pull_request) Successful in 1m46s
Test / rust-fmt-check (pull_request) Failing after 10m52s
Test / rust-clippy (pull_request) Successful in 12m34s
Test / rust-tests (pull_request) Successful in 14m8s
Resolves four bugs in the Kubernetes management interface: 1. **Cluster not found error** - commands/kube.rs::list_nodes (and all other kube resource commands) look up clusters from state.clusters (in-memory map) which was never populated from the kubeconfig_files table. Add a new connect_cluster_from_kubeconfig Tauri command that reads the encrypted kubeconfig from the DB, decrypts it, and inserts a ClusterClient into state.clusters. Wire it into KubernetesPage on initial load and cluster change so the in-memory map is always populated before any kube command runs. 2. **Dropdown selection has no effect** - same root cause as #1; activating a kubeconfig only updated the DB flag but never loaded the client into memory. handleClusterChange now calls connectClusterFromKubeconfigCmd after activation. 3. **GUID shown instead of cluster name** - ClusterOverview displayed the raw internal UUID as the page subtitle. Now accepts a clusterName prop (populated from kubeconfig.context) and renders that instead. ClusterDetails similarly changed to show kubeconfig.context in the header, not the UUID. 4. **Bell icon not clickable** - Hotbar bell button had no onClick handler. Add optional onNotifications / notificationCount props; badge count is now dynamic rather than hardcoded. KubernetesPage wires up a notifications dialog showing active cluster context and a link to the Events section. All changes follow TDD: failing tests written first, then implementation.
149 lines
4.4 KiB
TypeScript
149 lines
4.4 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { render, screen, waitFor } from "@testing-library/react";
|
|
import { invoke } from "@tauri-apps/api/core";
|
|
import { ClusterDetails } from "@/components/Kubernetes/ClusterDetails";
|
|
|
|
type MockedInvoke = typeof invoke & {
|
|
mockResolvedValue: (v: unknown) => void;
|
|
mockRejectedValue: (e: Error) => void;
|
|
mockImplementation: (fn: (cmd: string) => Promise<unknown>) => void;
|
|
};
|
|
|
|
const mockInvoke = invoke as MockedInvoke;
|
|
|
|
const mockKubeconfigs = [
|
|
{
|
|
id: "cluster-1",
|
|
name: "production-k8s",
|
|
context: "prod-context",
|
|
cluster_url: "https://k8s.example.com:6443",
|
|
is_active: true,
|
|
},
|
|
{
|
|
id: "cluster-2",
|
|
name: "staging-k8s",
|
|
context: "staging-context",
|
|
cluster_url: "https://staging.example.com:6443",
|
|
is_active: false,
|
|
},
|
|
];
|
|
|
|
const mockNodes = [
|
|
{
|
|
name: "node-1",
|
|
status: "Ready",
|
|
roles: "control-plane",
|
|
version: "v1.28.4",
|
|
internal_ip: "10.0.0.1",
|
|
os_image: "Ubuntu 22.04",
|
|
kernel_version: "5.15.0",
|
|
kubelet_version: "v1.28.4",
|
|
age: "30d",
|
|
},
|
|
{
|
|
name: "node-2",
|
|
status: "Ready",
|
|
roles: "worker",
|
|
version: "v1.28.4",
|
|
internal_ip: "10.0.0.2",
|
|
os_image: "Ubuntu 22.04",
|
|
kernel_version: "5.15.0",
|
|
kubelet_version: "v1.28.4",
|
|
age: "30d",
|
|
},
|
|
];
|
|
|
|
describe("ClusterDetails", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it("renders cluster name from kubeconfig", async () => {
|
|
mockInvoke.mockImplementation((cmd: string) => {
|
|
if (cmd === "list_kubeconfigs") return Promise.resolve(mockKubeconfigs);
|
|
if (cmd === "list_nodes") return Promise.resolve(mockNodes);
|
|
return Promise.resolve([]);
|
|
});
|
|
|
|
render(<ClusterDetails clusterId="cluster-1" />);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId("cluster-name")).toHaveTextContent("production-k8s");
|
|
});
|
|
});
|
|
|
|
it("renders API server URL from kubeconfig", async () => {
|
|
mockInvoke.mockImplementation((cmd: string) => {
|
|
if (cmd === "list_kubeconfigs") return Promise.resolve(mockKubeconfigs);
|
|
if (cmd === "list_nodes") return Promise.resolve(mockNodes);
|
|
return Promise.resolve([]);
|
|
});
|
|
|
|
render(<ClusterDetails clusterId="cluster-1" />);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId("cluster-api-server")).toHaveTextContent(
|
|
"https://k8s.example.com:6443"
|
|
);
|
|
});
|
|
});
|
|
|
|
it("renders context name", async () => {
|
|
mockInvoke.mockImplementation((cmd: string) => {
|
|
if (cmd === "list_kubeconfigs") return Promise.resolve(mockKubeconfigs);
|
|
if (cmd === "list_nodes") return Promise.resolve(mockNodes);
|
|
return Promise.resolve([]);
|
|
});
|
|
|
|
render(<ClusterDetails clusterId="cluster-1" />);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId("cluster-context")).toHaveTextContent("prod-context");
|
|
});
|
|
});
|
|
|
|
it("shows node information from listNodesCmd", async () => {
|
|
mockInvoke.mockImplementation((cmd: string) => {
|
|
if (cmd === "list_kubeconfigs") return Promise.resolve(mockKubeconfigs);
|
|
if (cmd === "list_nodes") return Promise.resolve(mockNodes);
|
|
return Promise.resolve([]);
|
|
});
|
|
|
|
render(<ClusterDetails clusterId="cluster-1" />);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByText("node-1")).toBeInTheDocument();
|
|
expect(screen.getByText("node-2")).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
it("shows 'No data' message when cluster info unavailable", async () => {
|
|
mockInvoke.mockImplementation((cmd: string) => {
|
|
if (cmd === "list_kubeconfigs") return Promise.resolve([]);
|
|
if (cmd === "list_nodes") return Promise.resolve([]);
|
|
return Promise.resolve([]);
|
|
});
|
|
|
|
render(<ClusterDetails clusterId="cluster-unknown" />);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId("cluster-no-data")).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
it("shows context name in header instead of raw GUID", async () => {
|
|
mockInvoke.mockImplementation((cmd: string) => {
|
|
if (cmd === "list_kubeconfigs") return Promise.resolve(mockKubeconfigs);
|
|
if (cmd === "list_nodes") return Promise.resolve(mockNodes);
|
|
return Promise.resolve([]);
|
|
});
|
|
|
|
render(<ClusterDetails clusterId="cluster-1" />);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId("cluster-context-header")).toHaveTextContent("prod-context");
|
|
expect(screen.queryByText("cluster-1")).not.toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|