Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 15 additions & 43 deletions ui/apps/console/src/pages/devices/__tests__/Devices.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { describe, it, expect, vi, beforeEach } from "vitest";
import { render, screen, act, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import React from "react";
import type { UseActionDialogResult } from "@/hooks/useActionDialog";
import { createTestWrapper } from "@/tests/wrapper";
import { mockDevice, mockNamespace } from "@/tests/factories";
import { mockSdkResponse, paginatedResponse } from "@/tests/sdk";
Expand Down Expand Up @@ -88,22 +87,6 @@ vi.mock("@/components/common/TagsPopover", () => ({
),
}));

vi.mock("@/components/common/ActionDialog", () => ({
default: () => null,
}));

const mockRequestAction = vi.fn();
const mockDeviceActionsController: UseActionDialogResult = {
action: undefined,
actionKey: "closed",
requestAction: mockRequestAction,
close: vi.fn(),
handleSuccess: vi.fn(),
};
vi.mock("@/hooks/useActionDialog", () => ({
useActionDialog: vi.fn(() => mockDeviceActionsController),
}));

vi.mock("@/components/common/RestrictedAction", () => ({
default: ({ children }: { children: React.ReactNode }) => <>{children}</>,
}));
Expand Down Expand Up @@ -133,7 +116,6 @@ beforeEach(() => {
sdk.pullTagFromDevice.mockResolvedValue(mockSdkResponse(undefined));
mockNavigate.mockReset();
mockManageTagsDrawer.mockReset();
mockRequestAction.mockReset();
});

describe("Devices list", () => {
Expand All @@ -145,22 +127,23 @@ describe("Devices list", () => {
).toBeInTheDocument();
});

it("renders the Accepted tab and the Install Keys link, not the pending/rejected tabs", async () => {
it("shows the list is the accepted devices, with no status to switch", async () => {
renderPage();
expect(
await screen.findByRole("button", { name: "Accepted" }),
).toBeInTheDocument();
expect(
screen.getByRole("link", { name: "Install Keys" }),
).toBeInTheDocument();
expect(
screen.queryByRole("button", { name: "Pending" }),
).not.toBeInTheDocument();

expect(await screen.findByText("Accepted")).toBeInTheDocument();
expect(
screen.queryByRole("button", { name: "Rejected" }),
).not.toBeInTheDocument();
});

it("links out to the install keys", async () => {
renderPage();

expect(
await screen.findByRole("link", { name: "Install Keys" }),
).toHaveAttribute("href", "/install-keys");
});

it("renders the search input", async () => {
renderPage();
expect(
Expand Down Expand Up @@ -278,12 +261,12 @@ describe("Devices list", () => {
});

describe("URL hydration — URL params seed page state on mount", () => {
it("passes status from URL to the SDK", async () => {
renderPage(["/?status=pending&tags=a&tags=b&page=2"]);
it("always asks for accepted devices, whatever the URL says", async () => {
renderPage(["/?status=pending"]);
await waitFor(() => {
expect(sdk.getDevices).toHaveBeenCalledWith(
expect.objectContaining({
query: expect.objectContaining({ status: "pending" }),
query: expect.objectContaining({ status: "accepted" }),
}),
);
});
Expand Down Expand Up @@ -312,7 +295,7 @@ describe("Devices list", () => {
});
});

it("falls back to status=accepted and page=1 when URL has no params", async () => {
it("defaults to accepted devices and page 1 when the URL has no params", async () => {
renderPage(["/"]);
await waitFor(() => {
expect(sdk.getDevices).toHaveBeenCalledWith(
Expand All @@ -323,17 +306,6 @@ describe("Devices list", () => {
});
});

it("falls back to status=accepted for an invalid status value", async () => {
renderPage(["/?status=invalid"]);
await waitFor(() => {
expect(sdk.getDevices).toHaveBeenCalledWith(
expect.objectContaining({
query: expect.objectContaining({ status: "accepted" }),
}),
);
});
});

it("passes no tag filter when no tags param is present", async () => {
renderPage(["/"]);
await waitFor(() => {
Expand Down
Loading
Loading