mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-23 20:42:02 +00:00
fix(ui): mark active Lighthouse chat in sidebar
This commit is contained in:
+43
@@ -112,6 +112,49 @@ describe("LighthouseV2SessionHistory", () => {
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("marks the active session with a visible sidebar indicator", () => {
|
||||
// Given / When
|
||||
renderHistory({
|
||||
activeSessionId: "session-active",
|
||||
sessions: [
|
||||
session({
|
||||
id: "session-active",
|
||||
title: "Active chat",
|
||||
updatedAt: "2026-06-25T09:00:00Z",
|
||||
}),
|
||||
session({
|
||||
id: "session-other",
|
||||
title: "Other chat",
|
||||
updatedAt: "2026-06-25T09:00:00Z",
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
// Then
|
||||
const activeSessionButton = screen.getByRole("button", {
|
||||
name: /Active chat.*Today/,
|
||||
});
|
||||
const otherSessionButton = screen.getByRole("button", {
|
||||
name: /Other chat.*Today/,
|
||||
});
|
||||
const activeSessionTitle =
|
||||
within(activeSessionButton).getByText("Active chat");
|
||||
const otherSessionTitle =
|
||||
within(otherSessionButton).getByText("Other chat");
|
||||
|
||||
expect(activeSessionButton.parentElement).toHaveClass(
|
||||
"before:bg-button-primary",
|
||||
"before:absolute",
|
||||
"before:left-0",
|
||||
);
|
||||
expect(activeSessionButton).toHaveClass("text-text-neutral-primary");
|
||||
expect(activeSessionTitle).toHaveClass("font-medium");
|
||||
expect(otherSessionButton.parentElement).not.toHaveClass(
|
||||
"before:bg-button-primary",
|
||||
);
|
||||
expect(otherSessionTitle).not.toHaveClass("font-medium");
|
||||
});
|
||||
|
||||
it("replaces the age label with the archive action on row hover", () => {
|
||||
// Given / When
|
||||
renderHistory({
|
||||
|
||||
@@ -88,23 +88,33 @@ export function LighthouseV2SessionHistory({
|
||||
<div className="grid min-w-0">
|
||||
{visibleSessions.map((session) => {
|
||||
const sessionTitle = session.title || "Untitled chat";
|
||||
const isActive = activeSessionId === session.id;
|
||||
|
||||
return (
|
||||
<div
|
||||
key={session.id}
|
||||
className={cn(
|
||||
"hover:bg-bg-neutral-tertiary group relative flex min-w-0 items-center overflow-hidden rounded-[8px] transition-colors",
|
||||
activeSessionId === session.id && "bg-bg-neutral-tertiary",
|
||||
isActive &&
|
||||
"bg-bg-neutral-tertiary before:bg-button-primary before:absolute before:top-1/2 before:left-0 before:h-5 before:w-0.5 before:-translate-y-1/2 before:rounded-full",
|
||||
)}
|
||||
>
|
||||
<Tooltip delayDuration={100}>
|
||||
<TooltipTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
className="flex min-w-0 flex-1 items-center gap-2 overflow-hidden rounded-[8px] px-2 py-2 text-left text-sm"
|
||||
className={cn(
|
||||
"flex min-w-0 flex-1 items-center gap-2 overflow-hidden rounded-[8px] px-2 py-2 text-left text-sm",
|
||||
isActive && "text-text-neutral-primary",
|
||||
)}
|
||||
onClick={() => onOpenSession(session.id)}
|
||||
>
|
||||
<span className="min-w-0 flex-1 truncate">
|
||||
<span
|
||||
className={cn(
|
||||
"min-w-0 flex-1 truncate",
|
||||
isActive && "font-medium",
|
||||
)}
|
||||
>
|
||||
{sessionTitle}
|
||||
</span>
|
||||
<span className="text-text-neutral-tertiary min-w-[3.25rem] shrink-0 text-right text-xs whitespace-nowrap transition-opacity group-focus-within:opacity-0 group-hover:opacity-0">
|
||||
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
import { render, screen, waitFor } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import type { LighthouseV2Session } from "@/app/(prowler)/lighthouse/_types";
|
||||
|
||||
import { LighthouseV2SidebarChat } from "./lighthouse-v2-sidebar-chat";
|
||||
|
||||
const navigationMocks = vi.hoisted(() => ({
|
||||
push: vi.fn(),
|
||||
searchParams: "",
|
||||
}));
|
||||
|
||||
vi.mock("next/navigation", () => ({
|
||||
useRouter: () => ({ push: navigationMocks.push }),
|
||||
useSearchParams: () => new URLSearchParams(navigationMocks.searchParams),
|
||||
}));
|
||||
|
||||
const actions = vi.hoisted(() => ({
|
||||
archiveLighthouseV2Session: vi.fn(),
|
||||
getLighthouseV2Sessions: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("@/app/(prowler)/lighthouse/_actions", () => ({
|
||||
archiveLighthouseV2Session: actions.archiveLighthouseV2Session,
|
||||
getLighthouseV2Sessions: actions.getLighthouseV2Sessions,
|
||||
}));
|
||||
|
||||
describe("LighthouseV2SidebarChat", () => {
|
||||
beforeEach(() => {
|
||||
navigationMocks.push.mockReset();
|
||||
navigationMocks.searchParams = "";
|
||||
actions.archiveLighthouseV2Session.mockReset();
|
||||
actions.getLighthouseV2Sessions.mockReset();
|
||||
});
|
||||
|
||||
it("marks the URL session as active in chat history", async () => {
|
||||
// Given
|
||||
navigationMocks.searchParams = "session=session-active";
|
||||
actions.getLighthouseV2Sessions.mockResolvedValue({
|
||||
data: [
|
||||
session({ id: "session-active", title: "Active chat" }),
|
||||
session({ id: "session-other", title: "Other chat" }),
|
||||
],
|
||||
});
|
||||
|
||||
// When
|
||||
render(<LighthouseV2SidebarChat isOpen />);
|
||||
|
||||
// Then
|
||||
const activeSession = await screen.findByRole("button", {
|
||||
name: /^Active chat/,
|
||||
});
|
||||
const otherSession = screen.getByRole("button", {
|
||||
name: /^Other chat/,
|
||||
});
|
||||
|
||||
await waitFor(() =>
|
||||
expect(activeSession.parentElement).toHaveClass("bg-bg-neutral-tertiary"),
|
||||
);
|
||||
expect(otherSession.parentElement).not.toHaveClass(
|
||||
"bg-bg-neutral-tertiary",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
function session(
|
||||
overrides: Partial<LighthouseV2Session> = {},
|
||||
): LighthouseV2Session {
|
||||
return {
|
||||
id: "session-1",
|
||||
title: "Session",
|
||||
isArchived: false,
|
||||
insertedAt: "2026-06-30T09:00:00Z",
|
||||
updatedAt: new Date().toISOString(),
|
||||
activeTaskId: null,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { MessageSquare, Plus } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
|
||||
import {
|
||||
@@ -25,6 +25,8 @@ import { LighthouseV2SessionHistory } from "../history";
|
||||
|
||||
export function LighthouseV2SidebarChat({ isOpen }: { isOpen: boolean }) {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const activeSessionId = searchParams.get("session");
|
||||
const [sessions, setSessions] = useState<LighthouseV2Session[]>([]);
|
||||
const [search, setSearch] = useState("");
|
||||
|
||||
@@ -93,6 +95,7 @@ export function LighthouseV2SidebarChat({ isOpen }: { isOpen: boolean }) {
|
||||
<LighthouseV2SessionHistory
|
||||
compact
|
||||
sessions={sessions}
|
||||
activeSessionId={activeSessionId}
|
||||
search={search}
|
||||
onSearchChange={handleSearchChange}
|
||||
onNewSession={handleNewSession}
|
||||
|
||||
Reference in New Issue
Block a user