Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
refactor(browser-profiles): single source-of-truth for paginated row selection (SKY-10853) (#6499)
Aaron Perez6f7a5f5bfa55
diff --git a/skyvern-frontend/src/routes/browserProfiles/BrowserProfilesList.test.tsx b/skyvern-frontend/src/routes/browserProfiles/BrowserProfilesList.test.tsxnew file mode 100644index 000000000..5c4b33356--- /dev/null+++ b/skyvern-frontend/src/routes/browserProfiles/BrowserProfilesList.test.tsx@@ -0,0 +1,118 @@+// @vitest-environment jsdom++import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import { cleanup, fireEvent, render, screen } from "@testing-library/react";+import { MemoryRouter } from "react-router-dom";+import { afterEach, describe, expect, it, vi } from "vitest";++import type { BrowserProfileApiResponse } from "@/api/types";+import { useBrowserProfilesQuery } from "@/routes/workflows/hooks/useBrowserProfilesQuery";++import { BrowserProfilesList } from "./BrowserProfilesList";++vi.mock("@/routes/workflows/hooks/useBrowserProfilesQuery", () => ({+ useBrowserProfilesQuery: vi.fn(),+}));++vi.mock("./BrowserProfileItem", () => ({+ BrowserProfileItem: ({+ profile,+ index,+ selected = false,+ onSelect,+ }: {+ profile: BrowserProfileApiResponse;+ index: number;+ selected?: boolean;+ onSelect?: (index: number, shiftKey: boolean) => void;+ }) => (+ <tr data-testid="profile-row" data-selected={selected ? "true" : "false"}>+ <td>+ <button+ aria-label={`select-${profile.name}`}+ onClick={(event) => onSelect?.(index, event.shiftKey)}+ >+ {profile.name}+ </button>+ </td>+ </tr>+ ),+}));++const mockedUseBrowserProfilesQuery = vi.mocked(useBrowserProfilesQuery);++function makeProfile(index: number): BrowserProfileApiResponse {+ return {+ browser_profile_id: `bp_${index}`,+ organization_id: "org_1",+ name: `Profile ${index}`,+ description: null,+ source_browser_type: null,+ created_at: "2026-06-01T00:00:00.000Z",+ modified_at: "2026-06-01T00:00:00.000Z",+ deleted_at: null,+ };+}++function makeProfiles(count: number): BrowserProfileApiResponse[] {+ return Array.from({ length: count }, (_, index) => makeProfile(index));+}++function renderList(profiles: BrowserProfileApiResponse[]) {+ // Page 1 returns the rendered rows; the lookahead query for page 2 returns empty.+ mockedUseBrowserProfilesQuery.mockImplementation(+ ({ page }: { page?: number } = {}) =>+ ({+ data: page === 1 ? profiles : [],+ isLoading: false,+ isError: false,+ isFetching: false,+ refetch: vi.fn(),+ }) as unknown as ReturnType<typeof useBrowserProfilesQuery>,+ );++ render(+ <QueryClientProvider client={new QueryClient()}>+ <MemoryRouter+ initialEntries={["/browser-profiles"]}+ future={{ v7_relativeSplatPath: true, v7_startTransition: true }}+ >+ <BrowserProfilesList />+ </MemoryRouter>+ </QueryClientProvider>,+ );+}++function selectionState(): string[] {+ return screen+ .getAllByTestId("profile-row")+ .map((row) => row.getAttribute("data-selected") ?? "false");+}++afterEach(() => {+ cleanup();+ vi.clearAllMocks();+});++describe("BrowserProfilesList paginated row selection", () => {+ it("selects only the clicked row on a plain click", () => {+ renderList(makeProfiles(3));++ fireEvent.click(screen.getByLabelText("select-Profile 1"));++ expect(selectionState()).toEqual(["false", "true", "false"]);+ });++ it("shift-click selects the contiguous range of rendered rows from the anchor", () => {+ renderList(makeProfiles(4));++ fireEvent.click(screen.getByLabelText("select-Profile 0"));+ fireEvent.click(screen.getByLabelText("select-Profile 3"), {+ shiftKey: true,+ });++ // Indices passed to the selection hook must address the same array the+ // table renders, so the highlighted rows are exactly the rendered range.+ expect(selectionState()).toEqual(["true", "true", "true", "true"]);+ });+});diff --git a/skyvern-frontend/src/routes/browserProfiles/BrowserProfilesList.tsx b/skyvern-frontend/src/routes/browserProfiles/BrowserProfilesList.tsxindex e023eb31c..392fb4089 100644--- a/skyvern-frontend/src/routes/browserProfiles/BrowserProfilesList.tsx+++ b/skyvern-frontend/src/routes/browserProfiles/BrowserProfilesList.tsx@@ -107,6 +107,10 @@ function BrowserProfilesList({ searchKey }: Props = {}) {open: boolean;targets: string[];}>({ open: false, targets: [] });++ // Selection indices must address the same array the table renders; keep one source for both.+ const pageItems = profiles ?? [];+const {selected,selectedItems: selectedProfiles,@@ -118,7 +122,7 @@ function BrowserProfilesList({ searchKey }: Props = {}) {clearSelection,replaceSelection,} = useRowSelection({- items: profiles ?? [],+ items: pageItems,getId: (profile) => profile.browser_profile_id,resetKey: JSON.stringify([page, itemsPerPage, searchKey ?? ""]),});@@ -202,8 +206,6 @@ function BrowserProfilesList({ searchKey }: Props = {}) {);}- const pageItems = profiles ?? [];-if (pageItems.length === 0 && page === 1 && !showPlaceholderRow) {return (<div className="rounded-md border border-slate-700 bg-slate-elevation1 p-10 text-sm text-neutral-600 dark:text-slate-300">