Merge pull request #7007 from shssoichiro/docs-status-display
feat: improvements to docs indexing status visibility
This commit is contained in:
commit
f538f22aa0
14 changed files with 896 additions and 28 deletions
|
|
@ -966,6 +966,10 @@ export class Core {
|
|||
on("docs/getDetails", async (msg) => {
|
||||
return await this.docsService.getDetails(msg.data.startUrl);
|
||||
});
|
||||
on("docs/getIndexedPages", async (msg) => {
|
||||
const pages = await this.docsService.getIndexedPages(msg.data.startUrl);
|
||||
return Array.from(pages);
|
||||
});
|
||||
|
||||
on("didChangeSelectedProfile", async (msg) => {
|
||||
if (msg.data.id) {
|
||||
|
|
|
|||
|
|
@ -858,6 +858,27 @@ export default class DocsService {
|
|||
return docs.map(this.lanceDBRowToChunk);
|
||||
}
|
||||
|
||||
async getIndexedPages(startUrl: string): Promise<Set<string>> {
|
||||
try {
|
||||
const table = await this.getOrCreateLanceTable({
|
||||
initializationVector: [],
|
||||
startUrl,
|
||||
});
|
||||
|
||||
const rows = (await table
|
||||
.filter(`starturl = '${startUrl}'`)
|
||||
.select(["path"]) // Only select path to minimize data transfer
|
||||
.limit(99999999) // Default is 10, we want to show all
|
||||
.execute()) as { path: string }[];
|
||||
|
||||
// Get unique paths (pages)
|
||||
return new Set(rows.map((row) => row.path));
|
||||
} catch (e) {
|
||||
console.warn(`Error getting page list for ${startUrl}:`, e);
|
||||
return new Set();
|
||||
}
|
||||
}
|
||||
|
||||
// SQLITE DB
|
||||
private async getOrCreateSqliteDb() {
|
||||
if (!this.sqliteDb) {
|
||||
|
|
|
|||
|
|
@ -285,6 +285,7 @@ export type ToCoreFromIdeOrWebviewProtocol = {
|
|||
"docs/getSuggestedDocs": [undefined, void];
|
||||
"docs/initStatuses": [undefined, void];
|
||||
"docs/getDetails": [{ startUrl: string }, DocsIndexingDetails];
|
||||
"docs/getIndexedPages": [{ startUrl: string }, string[]];
|
||||
addAutocompleteModel: [{ model: ModelDescription }, void];
|
||||
|
||||
"auth/getAuthUrl": [{ useOnboarding: boolean }, { url: string }];
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] =
|
|||
"indexing/setPaused",
|
||||
"docs/initStatuses",
|
||||
"docs/getDetails",
|
||||
"docs/getIndexedPages",
|
||||
//
|
||||
"onboarding/complete",
|
||||
"addAutocompleteModel",
|
||||
|
|
|
|||
|
|
@ -135,6 +135,7 @@ class MessageTypes {
|
|||
"indexing/setPaused",
|
||||
"docs/initStatuses",
|
||||
"docs/getDetails",
|
||||
"docs/getIndexedPages",
|
||||
//
|
||||
"onboarding/complete",
|
||||
"addAutocompleteModel",
|
||||
|
|
|
|||
|
|
@ -1,21 +1,19 @@
|
|||
import { DocsIndexingDetails } from "core";
|
||||
import { usePostHog } from "posthog-js/react";
|
||||
import { useCallback, useContext, useEffect, useState } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { Tooltip } from "react-tooltip";
|
||||
import { SecondaryButton } from "../../../..";
|
||||
import { IdeMessengerContext } from "../../../../../context/IdeMessenger";
|
||||
import { useAppSelector } from "../../../../../redux/hooks";
|
||||
import {
|
||||
setDialogMessage,
|
||||
setShowDialog,
|
||||
} from "../../../../../redux/slices/uiSlice";
|
||||
|
||||
interface DocsDetailsDialogProps {
|
||||
startUrl: string;
|
||||
}
|
||||
|
||||
function DocsDetailsDialog({ startUrl }: DocsDetailsDialogProps) {
|
||||
const config = useAppSelector((store) => store.config.config);
|
||||
const posthog = usePostHog();
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
|
@ -49,7 +47,7 @@ function DocsDetailsDialog({ startUrl }: DocsDetailsDialogProps) {
|
|||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchData();
|
||||
void fetchData();
|
||||
}, []);
|
||||
|
||||
let comp = <div>Loading...</div>;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,377 @@
|
|||
import {
|
||||
act,
|
||||
fireEvent,
|
||||
render,
|
||||
screen,
|
||||
waitFor,
|
||||
} from "@testing-library/react";
|
||||
import { SiteIndexingConfig } from "core";
|
||||
import { Provider } from "react-redux";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { AuthProvider } from "../../../../../context/Auth";
|
||||
import { IdeMessengerContext } from "../../../../../context/IdeMessenger";
|
||||
import { createMockStore } from "../../../../../util/test/mockStore";
|
||||
import DocsIndexingStatus from "./DocsIndexingStatus";
|
||||
|
||||
const mockLumpContext = {
|
||||
hideLump: vi.fn(),
|
||||
showLump: vi.fn(),
|
||||
};
|
||||
|
||||
vi.mock("../../LumpContext", () => ({
|
||||
useLump: () => mockLumpContext,
|
||||
}));
|
||||
|
||||
describe("DocsIndexingStatus", () => {
|
||||
const mockDocConfig: SiteIndexingConfig = {
|
||||
startUrl: "https://example.com",
|
||||
title: "Example Docs",
|
||||
};
|
||||
|
||||
const mockDocFromYaml = {
|
||||
startUrl: "https://example.com",
|
||||
title: "Example Docs",
|
||||
};
|
||||
|
||||
const renderComponent = async (
|
||||
props: any = {},
|
||||
storeState = {},
|
||||
mockIdeMessengerSetup?: (mock: any) => void,
|
||||
) => {
|
||||
const { mockIdeMessenger, ...store } = createMockStore(storeState);
|
||||
|
||||
// Configure the mockIdeMessenger for this test
|
||||
if (mockIdeMessengerSetup) {
|
||||
mockIdeMessengerSetup(mockIdeMessenger);
|
||||
} else {
|
||||
mockIdeMessenger.request.mockResolvedValue({
|
||||
status: "success",
|
||||
content: ["page1.html", "page2.html"],
|
||||
});
|
||||
}
|
||||
|
||||
const result = await act(async () =>
|
||||
render(
|
||||
<Provider store={store}>
|
||||
<IdeMessengerContext.Provider value={mockIdeMessenger}>
|
||||
<AuthProvider>
|
||||
<DocsIndexingStatus
|
||||
docConfig={mockDocConfig}
|
||||
docFromYaml={mockDocFromYaml}
|
||||
{...props}
|
||||
/>
|
||||
</AuthProvider>
|
||||
</IdeMessengerContext.Provider>
|
||||
</Provider>,
|
||||
),
|
||||
);
|
||||
|
||||
return { ...result, mockIdeMessenger };
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("renders doc title and basic structure", async () => {
|
||||
await renderComponent();
|
||||
expect(screen.getByText("Example Docs")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders startUrl when title is not provided", async () => {
|
||||
const configWithoutTitle = { ...mockDocConfig, title: undefined };
|
||||
await renderComponent({ docConfig: configWithoutTitle });
|
||||
expect(screen.getByText("https://example.com")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows progress percentage when indexing", async () => {
|
||||
const storeState = {
|
||||
indexing: {
|
||||
indexing: {
|
||||
statuses: {
|
||||
"https://example.com": {
|
||||
status: "indexing",
|
||||
progress: 0.45,
|
||||
description: "Indexing pages...",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
await renderComponent({}, storeState);
|
||||
expect(screen.getByText("45%")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows stop icon when indexing", async () => {
|
||||
const storeState = {
|
||||
indexing: {
|
||||
indexing: {
|
||||
statuses: {
|
||||
"https://example.com": {
|
||||
status: "indexing",
|
||||
progress: 0.25,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
await renderComponent({}, storeState);
|
||||
const stopIcon = screen.getByTestId("stop-indexing");
|
||||
expect(stopIcon).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("calls abort when stop icon is clicked", async () => {
|
||||
const storeState = {
|
||||
indexing: {
|
||||
indexing: {
|
||||
statuses: {
|
||||
"https://example.com": {
|
||||
status: "indexing",
|
||||
progress: 0.25,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const { mockIdeMessenger } = await renderComponent({}, storeState);
|
||||
const stopButton = screen.getByTestId("stop-indexing");
|
||||
fireEvent.click(stopButton);
|
||||
|
||||
expect(mockIdeMessenger.post).toHaveBeenCalledWith("indexing/abort", {
|
||||
type: "docs",
|
||||
id: "https://example.com",
|
||||
});
|
||||
});
|
||||
|
||||
it("shows reindex icon when status is complete", async () => {
|
||||
const storeState = {
|
||||
indexing: {
|
||||
indexing: {
|
||||
statuses: {
|
||||
"https://example.com": {
|
||||
status: "complete",
|
||||
progress: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
await renderComponent({}, storeState);
|
||||
const reindexButton = screen.getByTestId("reindex-docs");
|
||||
expect(reindexButton).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("calls reindex when reindex icon is clicked", async () => {
|
||||
const storeState = {
|
||||
indexing: {
|
||||
indexing: {
|
||||
statuses: {
|
||||
"https://example.com": {
|
||||
status: "complete",
|
||||
progress: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const { mockIdeMessenger } = await renderComponent({}, storeState);
|
||||
const reindexButton = screen.getByTestId("reindex-docs");
|
||||
fireEvent.click(reindexButton);
|
||||
|
||||
expect(mockIdeMessenger.post).toHaveBeenCalledWith("indexing/reindex", {
|
||||
type: "docs",
|
||||
id: "https://example.com",
|
||||
});
|
||||
});
|
||||
|
||||
it("opens URL when title is clicked and status has URL", async () => {
|
||||
const storeState = {
|
||||
indexing: {
|
||||
indexing: {
|
||||
statuses: {
|
||||
"https://example.com": {
|
||||
status: "complete",
|
||||
url: "https://example.com/docs",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const { mockIdeMessenger } = await renderComponent({}, storeState);
|
||||
const titleElement = screen.getByText("Example Docs");
|
||||
fireEvent.click(titleElement);
|
||||
|
||||
expect(mockIdeMessenger.post).toHaveBeenCalledWith(
|
||||
"openUrl",
|
||||
"https://example.com/docs",
|
||||
);
|
||||
expect(mockLumpContext.hideLump).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("fetches indexed pages when status becomes complete", async () => {
|
||||
const storeState = {
|
||||
indexing: {
|
||||
indexing: {
|
||||
statuses: {
|
||||
"https://example.com": {
|
||||
status: "complete",
|
||||
progress: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const { mockIdeMessenger } = await renderComponent({}, storeState);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockIdeMessenger.request).toHaveBeenCalledWith(
|
||||
"docs/getIndexedPages",
|
||||
{
|
||||
startUrl: "https://example.com",
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("displays indexed pages count when available", async () => {
|
||||
const storeState = {
|
||||
indexing: {
|
||||
indexing: {
|
||||
statuses: {
|
||||
"https://example.com": {
|
||||
status: "complete",
|
||||
progress: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
await renderComponent({}, storeState, (mockIdeMessenger) => {
|
||||
mockIdeMessenger.request.mockResolvedValue({
|
||||
status: "success",
|
||||
content: ["page1.html", "page2.html", "page3.html"],
|
||||
});
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText("3 pages indexed")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it("shows singular page text for one page", async () => {
|
||||
const storeState = {
|
||||
indexing: {
|
||||
indexing: {
|
||||
statuses: {
|
||||
"https://example.com": {
|
||||
status: "complete",
|
||||
progress: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
await renderComponent({}, storeState, (mockIdeMessenger) => {
|
||||
mockIdeMessenger.request.mockResolvedValue({
|
||||
status: "success",
|
||||
content: ["page1.html"],
|
||||
});
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText("1 page indexed")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it("shows status description when not complete", async () => {
|
||||
const storeState = {
|
||||
indexing: {
|
||||
indexing: {
|
||||
statuses: {
|
||||
"https://example.com": {
|
||||
status: "indexing",
|
||||
progress: 0.5,
|
||||
description: "Processing documentation...",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
await renderComponent({}, storeState);
|
||||
expect(screen.getByText("Processing documentation...")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("handles error when fetching indexed pages", async () => {
|
||||
const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
|
||||
const storeState = {
|
||||
indexing: {
|
||||
indexing: {
|
||||
statuses: {
|
||||
"https://example.com": {
|
||||
status: "complete",
|
||||
progress: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
await renderComponent({}, storeState, (mockIdeMessenger) => {
|
||||
mockIdeMessenger.request.mockResolvedValue({
|
||||
status: "error",
|
||||
error: "Failed to fetch pages",
|
||||
});
|
||||
});
|
||||
|
||||
await waitFor(() => {
|
||||
expect(consoleSpy).toHaveBeenCalledWith(
|
||||
expect.stringContaining(
|
||||
"Unable to fetch pages list for https://example.com",
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
consoleSpy.mockRestore();
|
||||
});
|
||||
|
||||
it("returns null when hasDeleted is true", async () => {
|
||||
const { container } = await renderComponent();
|
||||
|
||||
// Simulate deletion state by accessing the component's internal state
|
||||
// In a real scenario, this would be tested through user interaction
|
||||
expect(container.firstChild).not.toBeNull();
|
||||
});
|
||||
|
||||
it("shows loading text when pages are being fetched", async () => {
|
||||
const storeState = {
|
||||
indexing: {
|
||||
indexing: {
|
||||
statuses: {
|
||||
"https://example.com": {
|
||||
status: "complete",
|
||||
progress: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
await renderComponent({}, storeState, (mockIdeMessenger) => {
|
||||
// Mock a delayed response to keep in loading state
|
||||
mockIdeMessenger.request.mockImplementation(() => new Promise(() => {}));
|
||||
});
|
||||
|
||||
expect(screen.getByText("Loading site info...")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import { ConfigYaml } from "@continuedev/config-yaml";
|
||||
import { ArrowPathIcon, StopIcon } from "@heroicons/react/24/outline";
|
||||
import { SiteIndexingConfig } from "core";
|
||||
import { useContext, useMemo, useState } from "react";
|
||||
import { useContext, useEffect, useMemo, useState } from "react";
|
||||
import { IdeMessengerContext } from "../../../../../context/IdeMessenger";
|
||||
import { useAppDispatch, useAppSelector } from "../../../../../redux/hooks";
|
||||
import { updateIndexingStatus } from "../../../../../redux/slices/indexingSlice";
|
||||
|
|
@ -11,9 +11,12 @@ import {
|
|||
} from "../../../../../redux/slices/uiSlice";
|
||||
import { fontSize } from "../../../../../util";
|
||||
import ConfirmationDialog from "../../../../dialogs/ConfirmationDialog";
|
||||
import { ToolTip } from "../../../../gui/Tooltip";
|
||||
import EditBlockButton from "../../EditBlockButton";
|
||||
import { useLump } from "../../LumpContext";
|
||||
import { IndexedPagesTooltip } from "./IndexedPagesTooltip";
|
||||
import { StatusIndicator } from "./StatusIndicator";
|
||||
|
||||
interface IndexingStatusViewerProps {
|
||||
docConfig: SiteIndexingConfig;
|
||||
docFromYaml?: NonNullable<ConfigYaml["docs"]>[number];
|
||||
|
|
@ -26,11 +29,15 @@ function DocsIndexingStatus({
|
|||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const dispatch = useAppDispatch();
|
||||
const { hideLump } = useLump();
|
||||
const [indexedPages, setIndexedPages] = useState<null | string[]>(null);
|
||||
const [showTooltip, setShowTooltip] = useState(false);
|
||||
|
||||
const status = useAppSelector(
|
||||
(store) => store.indexing.indexing.statuses[docConfig.startUrl],
|
||||
);
|
||||
|
||||
const isComplete = status?.status === "complete";
|
||||
|
||||
const reIndex = () =>
|
||||
ideMessenger.post("indexing/reindex", {
|
||||
type: "docs",
|
||||
|
|
@ -77,8 +84,39 @@ function DocsIndexingStatus({
|
|||
return Math.min(100, Math.max(0, status.progress * 100)).toFixed(0);
|
||||
}, [status?.progress]);
|
||||
|
||||
// Fetch pages list when the status changes to complete
|
||||
useEffect(() => {
|
||||
async function getPagesList() {
|
||||
try {
|
||||
const response = await ideMessenger.request("docs/getIndexedPages", {
|
||||
startUrl: docConfig.startUrl,
|
||||
});
|
||||
if (response.status === "error") {
|
||||
throw new Error(response.error);
|
||||
}
|
||||
setIndexedPages(response.content.sort());
|
||||
} catch (ex) {
|
||||
console.error(
|
||||
`Unable to fetch pages list for ${docConfig.startUrl}: ${ex}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (isComplete) {
|
||||
void getPagesList();
|
||||
}
|
||||
}, [isComplete, ideMessenger, docConfig.startUrl]);
|
||||
|
||||
const showPagesList = () => {
|
||||
if (indexedPages) {
|
||||
setShowTooltip(true);
|
||||
}
|
||||
};
|
||||
|
||||
if (hasDeleted) return null;
|
||||
|
||||
const startUrlSlug = docConfig.startUrl.replace(/[^a-zA-Z0-9_-]/g, "_");
|
||||
|
||||
return (
|
||||
<div className="mt-1 flex w-full flex-col">
|
||||
<div
|
||||
|
|
@ -120,6 +158,7 @@ function DocsIndexingStatus({
|
|||
<StopIcon
|
||||
className="h-3 w-3 cursor-pointer text-gray-400 hover:brightness-125"
|
||||
onClick={abort}
|
||||
data-testid="stop-indexing"
|
||||
/>
|
||||
)}
|
||||
|
||||
|
|
@ -135,6 +174,7 @@ function DocsIndexingStatus({
|
|||
<ArrowPathIcon
|
||||
className="h-3 w-3 cursor-pointer text-gray-400 hover:brightness-125"
|
||||
onClick={reIndex}
|
||||
data-testid="reindex-docs"
|
||||
/>
|
||||
)}
|
||||
|
||||
|
|
@ -147,6 +187,56 @@ function DocsIndexingStatus({
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{status && (
|
||||
<div
|
||||
className={`flex flex-row items-center justify-between gap-2 text-sm`}
|
||||
>
|
||||
<p
|
||||
style={{
|
||||
fontSize: fontSize(-4),
|
||||
}}
|
||||
className={`m-0 line-clamp-1 p-0 text-left text-gray-400 ${isComplete ? "cursor-pointer hover:underline" : ""}`}
|
||||
onClick={() => {
|
||||
if (isComplete) {
|
||||
showPagesList();
|
||||
}
|
||||
}}
|
||||
data-tooltip-id={`docs-tooltip-${startUrlSlug}`}
|
||||
>
|
||||
{isComplete
|
||||
? indexedPages
|
||||
? `${indexedPages.length} page${indexedPages.length === 1 ? "" : "s"} indexed`
|
||||
: "Loading site info..."
|
||||
: status.description}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{indexedPages && (
|
||||
<ToolTip
|
||||
id={`docs-tooltip-${startUrlSlug}`}
|
||||
isOpen={showTooltip}
|
||||
setIsOpen={setShowTooltip}
|
||||
clickable
|
||||
delayShow={0}
|
||||
openEvents={{
|
||||
mouseenter: false,
|
||||
click: true,
|
||||
}}
|
||||
closeEvents={{
|
||||
blur: true,
|
||||
mouseleave: false,
|
||||
click: true,
|
||||
}}
|
||||
>
|
||||
<IndexedPagesTooltip
|
||||
pages={indexedPages}
|
||||
siteTitle={docConfig.title ?? docConfig.startUrl}
|
||||
baseUrl={docConfig.startUrl}
|
||||
/>
|
||||
</ToolTip>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,213 @@
|
|||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import { Provider } from "react-redux";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { IdeMessengerContext } from "../../../../../context/IdeMessenger";
|
||||
import { createMockStore } from "../../../../../util/test/mockStore";
|
||||
import { IndexedPagesTooltip } from "./IndexedPagesTooltip";
|
||||
|
||||
describe("IndexedPagesTooltip", () => {
|
||||
const defaultProps = {
|
||||
pages: [
|
||||
"https://example.com/page1",
|
||||
"https://example.com/page2",
|
||||
"https://example.com/sub/page3",
|
||||
],
|
||||
siteTitle: "Example Documentation",
|
||||
baseUrl: "https://example.com",
|
||||
};
|
||||
|
||||
const renderComponent = (props = {}, storeState = {}) => {
|
||||
const { mockIdeMessenger, ...store } = createMockStore(storeState);
|
||||
|
||||
return {
|
||||
...render(
|
||||
<Provider store={store}>
|
||||
<IdeMessengerContext.Provider value={mockIdeMessenger}>
|
||||
<IndexedPagesTooltip {...defaultProps} {...props} />
|
||||
</IdeMessengerContext.Provider>
|
||||
</Provider>,
|
||||
),
|
||||
mockIdeMessenger,
|
||||
store,
|
||||
};
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("renders site title and page count", () => {
|
||||
renderComponent();
|
||||
expect(
|
||||
screen.getByText("Example Documentation - 3 Pages Indexed"),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders all pages in the list", () => {
|
||||
renderComponent();
|
||||
|
||||
// Check that all pages are rendered (with baseUrl prefix removed)
|
||||
expect(screen.getByText("/page1")).toBeInTheDocument();
|
||||
expect(screen.getByText("/page2")).toBeInTheDocument();
|
||||
expect(screen.getByText("/sub/page3")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("removes baseUrl prefix from page URLs", () => {
|
||||
const pages = [
|
||||
"https://example.com/docs/getting-started",
|
||||
"https://example.com/docs/api-reference",
|
||||
"https://other-domain.com/page", // This should not have prefix removed
|
||||
];
|
||||
|
||||
renderComponent({ pages, baseUrl: "https://example.com" });
|
||||
|
||||
expect(screen.getByText("/docs/getting-started")).toBeInTheDocument();
|
||||
expect(screen.getByText("/docs/api-reference")).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText("https://other-domain.com/page"),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("handles pages that don't start with baseUrl", () => {
|
||||
const pages = [
|
||||
"https://different-domain.com/page1",
|
||||
"mailto:contact@example.com",
|
||||
];
|
||||
|
||||
renderComponent({ pages });
|
||||
|
||||
expect(
|
||||
screen.getByText("https://different-domain.com/page1"),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByText("mailto:contact@example.com")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("opens URL when page is clicked", () => {
|
||||
const { mockIdeMessenger } = renderComponent();
|
||||
|
||||
const pageLink = screen.getByText("/page1");
|
||||
fireEvent.click(pageLink);
|
||||
|
||||
expect(mockIdeMessenger.post).toHaveBeenCalledWith(
|
||||
"openUrl",
|
||||
"https://example.com/page1",
|
||||
);
|
||||
});
|
||||
|
||||
it("opens each page URL correctly when clicked", () => {
|
||||
const { mockIdeMessenger } = renderComponent();
|
||||
|
||||
// Click on different pages
|
||||
fireEvent.click(screen.getByText("/page2"));
|
||||
expect(mockIdeMessenger.post).toHaveBeenCalledWith(
|
||||
"openUrl",
|
||||
"https://example.com/page2",
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getByText("/sub/page3"));
|
||||
expect(mockIdeMessenger.post).toHaveBeenCalledWith(
|
||||
"openUrl",
|
||||
"https://example.com/sub/page3",
|
||||
);
|
||||
});
|
||||
|
||||
it("renders empty list when no pages provided", () => {
|
||||
renderComponent({ pages: [] });
|
||||
|
||||
expect(
|
||||
screen.getByText("Example Documentation - 0 Pages Indexed"),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.queryByRole("listitem")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("handles single page correctly", () => {
|
||||
const pages = ["https://example.com/single-page"];
|
||||
|
||||
renderComponent({ pages });
|
||||
|
||||
expect(
|
||||
screen.getByText("Example Documentation - 1 Pages Indexed"),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByText("/single-page")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("preserves page order", () => {
|
||||
const pages = [
|
||||
"https://example.com/z-last",
|
||||
"https://example.com/a-first",
|
||||
"https://example.com/m-middle",
|
||||
];
|
||||
|
||||
renderComponent({ pages });
|
||||
|
||||
const listItems = screen.getAllByRole("listitem");
|
||||
expect(listItems).toHaveLength(3);
|
||||
|
||||
// Check that the order is preserved as provided, not alphabetically sorted
|
||||
expect(listItems[0]).toHaveTextContent("/z-last");
|
||||
expect(listItems[1]).toHaveTextContent("/a-first");
|
||||
expect(listItems[2]).toHaveTextContent("/m-middle");
|
||||
});
|
||||
|
||||
it("applies correct CSS classes for styling", () => {
|
||||
renderComponent();
|
||||
|
||||
const pageItems = screen.getAllByRole("listitem");
|
||||
pageItems.forEach((item) => {
|
||||
expect(item).toHaveClass(
|
||||
"my-1",
|
||||
"cursor-pointer",
|
||||
"truncate",
|
||||
"text-left",
|
||||
"text-gray-400",
|
||||
"hover:underline",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("shows scrollable container for long lists", () => {
|
||||
// Create a long list of pages
|
||||
const longPageList = Array.from(
|
||||
{ length: 20 },
|
||||
(_, i) => `https://example.com/page-${i + 1}`,
|
||||
);
|
||||
|
||||
const { container } = renderComponent({ pages: longPageList });
|
||||
|
||||
// Check that the scrollable container exists
|
||||
const scrollContainer = container.querySelector(
|
||||
".max-h-48.overflow-y-auto",
|
||||
);
|
||||
expect(scrollContainer).toBeInTheDocument();
|
||||
|
||||
// Check that all pages are rendered
|
||||
expect(
|
||||
screen.getByText("Example Documentation - 20 Pages Indexed"),
|
||||
).toBeInTheDocument();
|
||||
longPageList.forEach((_, index) => {
|
||||
expect(screen.getByText(`/page-${index + 1}`)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("removePrefix utility", () => {
|
||||
it("removes prefix when string starts with it", () => {
|
||||
const pages = ["https://example.com/docs/guide"];
|
||||
renderComponent({ pages, baseUrl: "https://example.com" });
|
||||
expect(screen.getByText("/docs/guide")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("returns original string when it doesn't start with prefix", () => {
|
||||
const pages = ["https://other-site.com/page"];
|
||||
renderComponent({ pages, baseUrl: "https://example.com" });
|
||||
expect(
|
||||
screen.getByText("https://other-site.com/page"),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("handles empty prefix", () => {
|
||||
const pages = ["https://example.com/page"];
|
||||
renderComponent({ pages, baseUrl: "" });
|
||||
expect(screen.getByText("https://example.com/page")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
import { EyeIcon } from "@heroicons/react/24/outline";
|
||||
import { useContext } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { IdeMessengerContext } from "../../../../../context/IdeMessenger";
|
||||
import {
|
||||
setDialogMessage,
|
||||
setShowDialog,
|
||||
} from "../../../../../redux/slices/uiSlice";
|
||||
import { fontSize } from "../../../../../util";
|
||||
import DocsDetailsDialog from "./DocsDetailsDialog";
|
||||
|
||||
interface IndexedPagesTooltipProps {
|
||||
pages: string[];
|
||||
siteTitle: string;
|
||||
baseUrl: string;
|
||||
}
|
||||
|
||||
function removePrefix(str: string, prefix: string): string {
|
||||
return str.startsWith(prefix) ? str.slice(prefix.length) : str;
|
||||
}
|
||||
|
||||
export const IndexedPagesTooltip = ({
|
||||
pages,
|
||||
siteTitle,
|
||||
baseUrl,
|
||||
}: IndexedPagesTooltipProps) => {
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const handleEyeIconClick = (e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
|
||||
// Open the DocsDetailsDialog component as a modal
|
||||
dispatch(setShowDialog(true));
|
||||
dispatch(setDialogMessage(<DocsDetailsDialog startUrl={baseUrl} />));
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div
|
||||
className="mx-1 my-2 flex items-center justify-between font-semibold"
|
||||
style={{ fontSize: fontSize(-3) }}
|
||||
>
|
||||
<span>
|
||||
{siteTitle} - {pages.length} Pages Indexed
|
||||
</span>
|
||||
<EyeIcon
|
||||
className="ml-2 h-4 w-4 cursor-pointer text-red-500 transition-colors hover:text-red-400"
|
||||
onClick={handleEyeIconClick}
|
||||
title="View detailed docs information"
|
||||
/>
|
||||
</div>
|
||||
<div className="max-h-48 overflow-y-auto px-1">
|
||||
<ul className="list-none pl-0">
|
||||
{pages.map((page, index) => (
|
||||
<li
|
||||
key={index}
|
||||
className="my-1 cursor-pointer truncate text-left text-gray-400 hover:underline"
|
||||
style={{ fontSize: fontSize(-4) }}
|
||||
onClick={() => {
|
||||
ideMessenger.post("openUrl", page);
|
||||
}}
|
||||
>
|
||||
{removePrefix(page, baseUrl)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
@ -567,13 +567,21 @@ describe("streamResponseThunk", () => {
|
|||
returnToMode: "chat",
|
||||
},
|
||||
indexing: {
|
||||
indexingState: "disabled",
|
||||
indexing: {
|
||||
statuses: {},
|
||||
hiddenChatPeekTypes: {
|
||||
docs: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
tabs: {
|
||||
tabsItems: [],
|
||||
},
|
||||
profiles: {
|
||||
profiles: [],
|
||||
organizations: [],
|
||||
selectedProfileId: null,
|
||||
selectedOrganizationId: null,
|
||||
preferencesByProfileId: {},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
@ -1087,13 +1095,21 @@ describe("streamResponseThunk", () => {
|
|||
returnToMode: "chat",
|
||||
},
|
||||
indexing: {
|
||||
indexingState: "disabled",
|
||||
indexing: {
|
||||
statuses: {},
|
||||
hiddenChatPeekTypes: {
|
||||
docs: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
tabs: {
|
||||
tabsItems: [],
|
||||
},
|
||||
profiles: {
|
||||
profiles: [],
|
||||
organizations: [],
|
||||
selectedProfileId: null,
|
||||
selectedOrganizationId: null,
|
||||
preferencesByProfileId: {},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
@ -1632,13 +1648,21 @@ describe("streamResponseThunk", () => {
|
|||
returnToMode: "chat",
|
||||
},
|
||||
indexing: {
|
||||
indexingState: "disabled",
|
||||
indexing: {
|
||||
statuses: {},
|
||||
hiddenChatPeekTypes: {
|
||||
docs: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
tabs: {
|
||||
tabsItems: [],
|
||||
},
|
||||
profiles: {
|
||||
profiles: [],
|
||||
organizations: [],
|
||||
selectedProfileId: null,
|
||||
selectedOrganizationId: null,
|
||||
preferencesByProfileId: {},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -392,13 +392,21 @@ describe("streamResponseThunk", () => {
|
|||
returnToMode: "chat",
|
||||
},
|
||||
indexing: {
|
||||
indexingState: "disabled",
|
||||
indexing: {
|
||||
statuses: {},
|
||||
hiddenChatPeekTypes: {
|
||||
docs: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
tabs: {
|
||||
tabsItems: [],
|
||||
},
|
||||
profiles: {
|
||||
profiles: [],
|
||||
organizations: [],
|
||||
selectedProfileId: null,
|
||||
selectedOrganizationId: null,
|
||||
preferencesByProfileId: {},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
@ -775,13 +783,21 @@ describe("streamResponseThunk", () => {
|
|||
returnToMode: "chat",
|
||||
},
|
||||
indexing: {
|
||||
indexingState: "disabled",
|
||||
indexing: {
|
||||
statuses: {},
|
||||
hiddenChatPeekTypes: {
|
||||
docs: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
tabs: {
|
||||
tabsItems: [],
|
||||
},
|
||||
profiles: {
|
||||
profiles: [],
|
||||
organizations: [],
|
||||
selectedProfileId: null,
|
||||
selectedOrganizationId: null,
|
||||
preferencesByProfileId: {},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
@ -1088,13 +1104,21 @@ describe("streamResponseThunk", () => {
|
|||
returnToMode: "chat",
|
||||
},
|
||||
indexing: {
|
||||
indexingState: "disabled",
|
||||
indexing: {
|
||||
statuses: {},
|
||||
hiddenChatPeekTypes: {
|
||||
docs: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
tabs: {
|
||||
tabsItems: [],
|
||||
},
|
||||
profiles: {
|
||||
profiles: [],
|
||||
organizations: [],
|
||||
selectedProfileId: null,
|
||||
selectedOrganizationId: null,
|
||||
preferencesByProfileId: {},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -726,13 +726,21 @@ describe("streamResponseThunk - tool calls", () => {
|
|||
returnToMode: "chat",
|
||||
},
|
||||
indexing: {
|
||||
indexingState: "disabled",
|
||||
indexing: {
|
||||
statuses: {},
|
||||
hiddenChatPeekTypes: {
|
||||
docs: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
tabs: {
|
||||
tabsItems: [],
|
||||
},
|
||||
profiles: {
|
||||
profiles: [],
|
||||
organizations: [],
|
||||
selectedProfileId: null,
|
||||
selectedOrganizationId: null,
|
||||
preferencesByProfileId: {},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
@ -1352,13 +1360,21 @@ describe("streamResponseThunk - tool calls", () => {
|
|||
returnToMode: "chat",
|
||||
},
|
||||
indexing: {
|
||||
indexingState: "disabled",
|
||||
indexing: {
|
||||
statuses: {},
|
||||
hiddenChatPeekTypes: {
|
||||
docs: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
tabs: {
|
||||
tabsItems: [],
|
||||
},
|
||||
profiles: {
|
||||
profiles: [],
|
||||
organizations: [],
|
||||
selectedProfileId: null,
|
||||
selectedOrganizationId: null,
|
||||
preferencesByProfileId: {},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
@ -1986,13 +2002,21 @@ describe("streamResponseThunk - tool calls", () => {
|
|||
returnToMode: "chat",
|
||||
},
|
||||
indexing: {
|
||||
indexingState: "disabled",
|
||||
indexing: {
|
||||
statuses: {},
|
||||
hiddenChatPeekTypes: {
|
||||
docs: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
tabs: {
|
||||
tabsItems: [],
|
||||
},
|
||||
profiles: {
|
||||
profiles: [],
|
||||
organizations: [],
|
||||
selectedProfileId: null,
|
||||
selectedOrganizationId: null,
|
||||
preferencesByProfileId: {},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
@ -2929,13 +2953,21 @@ describe("streamResponseThunk - tool calls", () => {
|
|||
returnToMode: "chat",
|
||||
},
|
||||
indexing: {
|
||||
indexingState: "disabled",
|
||||
indexing: {
|
||||
statuses: {},
|
||||
hiddenChatPeekTypes: {
|
||||
docs: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
tabs: {
|
||||
tabsItems: [],
|
||||
},
|
||||
profiles: {
|
||||
profiles: [],
|
||||
organizations: [],
|
||||
selectedProfileId: null,
|
||||
selectedOrganizationId: null,
|
||||
preferencesByProfileId: {},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -13,7 +13,10 @@ export const createMockStore = (initialState?: Partial<RootState>) => {
|
|||
const mockIdeMessenger = {
|
||||
request: vi.fn(),
|
||||
post: vi.fn(),
|
||||
respond: vi.fn(),
|
||||
streamRequest: vi.fn(),
|
||||
llmStreamChat: vi.fn(),
|
||||
ide: {} as any,
|
||||
};
|
||||
|
||||
const store = configureStore({
|
||||
|
|
@ -76,7 +79,12 @@ export const createMockStore = (initialState?: Partial<RootState>) => {
|
|||
...initialState?.config,
|
||||
},
|
||||
indexing: {
|
||||
indexingState: "disabled",
|
||||
indexing: {
|
||||
statuses: {},
|
||||
hiddenChatPeekTypes: {
|
||||
docs: false,
|
||||
},
|
||||
},
|
||||
...initialState?.indexing,
|
||||
},
|
||||
tabs: {
|
||||
|
|
@ -84,7 +92,10 @@ export const createMockStore = (initialState?: Partial<RootState>) => {
|
|||
...initialState?.tabs,
|
||||
},
|
||||
profiles: {
|
||||
profiles: [],
|
||||
organizations: [],
|
||||
selectedProfileId: null,
|
||||
selectedOrganizationId: null,
|
||||
preferencesByProfileId: {},
|
||||
...initialState?.profiles,
|
||||
},
|
||||
} as RootState,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue