Elffuss BraidHub

kikocis/continue public

move chat utils
Changesetfacdfa77975838b3382163ff66bc3392c17fde1721d270a112c772e4ac4962fe
AuthorDallin Romney <dallinromney@gmail.com> · 2025-06-26 13:59 -07:00
CommitterDallin Romney <dallinromney@gmail.com> · 2025-06-26 13:59 -07:00
Parents9bd927d445bd

Browse the files at this changeset

8 files changed

modified core/config/sharedConfig.ts +1 −1
@@ -167,10 +167,10 @@
167167 if (sharedConfig.readResponseTTS !== undefined) {
168168 configCopy.experimental.readResponseTTS = sharedConfig.readResponseTTS;
169169 }
170-
171170 if (sharedConfig.useCurrentFileAsContext !== undefined) {
172171 configCopy.experimental.useCurrentFileAsContext =
173172 sharedConfig.useCurrentFileAsContext;
174173 }
174+
175175 return configCopy;
176176 }
modified extensions/intellij/rules.md +0 −4
@@ -1,7 +1,3 @@
1----
2-globs: "**/intellij**"
3----
4-
51 # Continue JetBrains Extension
62
73 ## Project Purpose
modified gui/src/pages/gui/chat-tests/ApplyScenarios.test.tsx +2 −2
@@ -1,11 +1,11 @@
11 import { act } from "@testing-library/react";
22 import { renderWithProviders } from "../../../util/test/render";
3-import { Chat } from "../Chat";
43 import {
54 getElementByTestId,
65 verifyNotPresentByTestId,
76 verifyNotPresentByText,
8-} from "./utils";
7+} from "../../../util/test/utils";
8+import { Chat } from "../Chat";
99
1010 test("Chat apply scenarios: handle apply updates and display the accept / reject all buttons", async () => {
1111 const { ideMessenger } = await renderWithProviders(<Chat />);
modified gui/src/pages/gui/chat-tests/Chat.test.tsx +2 −2
@@ -1,12 +1,12 @@
11 import { act } from "@testing-library/react";
22 import { addAndSelectMockLlm } from "../../../util/test/config";
33 import { renderWithProviders } from "../../../util/test/render";
4-import { Chat } from "../Chat";
54 import {
65 getElementByTestId,
76 getElementByText,
87 sendInputWithMockedResponse,
9-} from "./utils";
8+} from "../../../util/test/utils";
9+import { Chat } from "../Chat";
1010
1111 test("should render input box", async () => {
1212 await renderWithProviders(<Chat />);
modified gui/src/pages/gui/chat-tests/EditToolScenarios.test.tsx +1 −1
@@ -14,7 +14,7 @@
1414 getElementByText,
1515 sendInputWithMockedResponse,
1616 verifyNotPresentByTestId,
17-} from "./utils";
17+} from "../../../util/test/utils";
1818
1919 const EDIT_WORKSPACE_DIR = "file:///workspace";
2020 const EDIT_FILEPATH = "test.txt";
deleted gui/src/pages/gui/chat-tests/utils.ts +0 −102
@@ -1,102 +0,0 @@
1-import { screen, waitFor } from "@testing-library/dom";
2-import { act } from "@testing-library/react";
3-import { Editor } from "@tiptap/core";
4-import { ChatMessage } from "core";
5-import { MockIdeMessenger } from "../../../context/MockIdeMessenger";
6-
7-function logDomText() {
8- const bodyText = document.body.innerHTML;
9- const parser = new DOMParser();
10- const doc = parser.parseFromString(bodyText, "text/html");
11- let cleaned = doc.body.textContent ?? "";
12- cleaned = cleaned?.replace(
13- "No resultsAaModelsRulesDocsPromptsToolsMCPCreate your first assistant",
14- "",
15- );
16- cleaned = cleaned?.replace(
17- "Alt⏎ Active file⏎ Enter⏎Log in to access a free trial of theModels Add-OnLog in to Continue HubOr, configure your own models",
18- "",
19- );
20- cleaned = cleaned.replaceAll("Select model", "");
21- cleaned = cleaned.replaceAll("Mock LLM", "");
22- cleaned = cleaned.replaceAll(/^Chat|Chat$/g, "");
23- console.log(cleaned || "No body content");
24-}
25-
26-export function logAllTestIds() {
27- const elements = document.querySelectorAll("*");
28-
29- const testIds = Array.from(elements)
30- .map((el) => Array.from(el.attributes))
31- .flat()
32- .filter((a) => a.name === "data-testid")
33- .map((a) => a.value);
34- console.log("Available test ids", testIds);
35-}
36-export async function getElementByTestId(testId: string): Promise<HTMLElement> {
37- try {
38- const testIdElement = await waitFor(() => screen.findByTestId(testId));
39- expect(testIdElement).toBeInTheDocument();
40- return testIdElement;
41- } catch (e) {
42- logAllTestIds();
43- throw new Error(`Element with testId "${testId}" not found`);
44- }
45-}
46-
47-export async function verifyNotPresentByTestId(testId: string): Promise<void> {
48- const element = await waitFor(() => screen.queryByTestId(testId));
49- expect(element).not.toBeInTheDocument();
50-}
51-
52-export async function verifyNotPresentByText(text: string): Promise<void> {
53- const element = screen.queryByText(text);
54- expect(element).not.toBeInTheDocument();
55-}
56-
57-export async function getElementByText(text: string): Promise<HTMLElement> {
58- try {
59- const textElement = await waitFor(() => screen.findByText(text));
60- expect(textElement).toBeInTheDocument();
61- return textElement;
62- } catch (e) {
63- logDomText();
64- throw new Error(`Element with text "${text}" not found.`);
65- }
66-}
67-
68-export async function getMainEditor(): Promise<Editor> {
69- const editorElement = await getElementByTestId("editor-input-main");
70- if ("editor" in editorElement) {
71- return editorElement.editor as Editor;
72- } else {
73- throw new Error("Main editor not found within editor container");
74- }
75-}
76-
77-export async function sendInputWithMockedResponse(
78- ideMessenger: MockIdeMessenger,
79- input: string,
80- response: ChatMessage[],
81-): Promise<void> {
82- // Setup the mock response before any actions
83- ideMessenger.chatResponse = response;
84-
85- // Wait for the editor to be in the document
86- const editor = await getMainEditor();
87-
88- // Find the submit button
89- const sendButton = await getElementByTestId("submit-input-button");
90-
91- // Insert content into the editor
92- await act(async () => {
93- editor.commands.insertContent(input);
94- });
95-
96- await getElementByText(input);
97-
98- // Click the send button
99- await act(async () => {
100- sendButton.click();
101- });
102-}
modified gui/src/redux/slices/profilesSlice.ts +2 −2
@@ -19,7 +19,7 @@
1919 preferencesByProfileId: Record<string, PreferencesState>;
2020 }
2121
22-export const defaultProfilesState: ProfilesState = {
22+const initialState: ProfilesState = {
2323 preferencesByProfileId: {},
2424 selectedProfileId: null,
2525 selectedOrganizationId: null,
@@ -51,7 +51,7 @@
5151
5252 export const profilesSlice = createSlice({
5353 name: "profiles",
54- initialState: defaultProfilesState,
54+ initialState,
5555 reducers: {
5656 setSelectedProfile: (state, { payload }: PayloadAction<string | null>) => {
5757 state.selectedProfileId = payload;
added gui/src/util/test/utils.ts +102 −0
@@ -0,0 +1,102 @@
1+import { screen, waitFor } from "@testing-library/dom";
2+import { act } from "@testing-library/react";
3+import { Editor } from "@tiptap/core";
4+import { ChatMessage } from "core";
5+import { MockIdeMessenger } from "../../context/MockIdeMessenger";
6+
7+function logDomText() {
8+ const bodyText = document.body.innerHTML;
9+ const parser = new DOMParser();
10+ const doc = parser.parseFromString(bodyText, "text/html");
11+ let cleaned = doc.body.textContent ?? "";
12+ cleaned = cleaned?.replace(
13+ "No resultsAaModelsRulesDocsPromptsToolsMCPCreate your first assistant",
14+ "",
15+ );
16+ cleaned = cleaned?.replace(
17+ "Alt⏎ Active file⏎ Enter⏎Log in to access a free trial of theModels Add-OnLog in to Continue HubOr, configure your own models",
18+ "",
19+ );
20+ cleaned = cleaned.replaceAll("Select model", "");
21+ cleaned = cleaned.replaceAll("Mock LLM", "");
22+ cleaned = cleaned.replaceAll(/^Chat|Chat$/g, "");
23+ console.log(cleaned || "No body content");
24+}
25+
26+export function logAllTestIds() {
27+ const elements = document.querySelectorAll("*");
28+
29+ const testIds = Array.from(elements)
30+ .map((el) => Array.from(el.attributes))
31+ .flat()
32+ .filter((a) => a.name === "data-testid")
33+ .map((a) => a.value);
34+ console.log("Available test ids", testIds);
35+}
36+export async function getElementByTestId(testId: string): Promise<HTMLElement> {
37+ try {
38+ const testIdElement = await waitFor(() => screen.findByTestId(testId));
39+ expect(testIdElement).toBeInTheDocument();
40+ return testIdElement;
41+ } catch (e) {
42+ logAllTestIds();
43+ throw new Error(`Element with testId "${testId}" not found`);
44+ }
45+}
46+
47+export async function verifyNotPresentByTestId(testId: string): Promise<void> {
48+ const element = await waitFor(() => screen.queryByTestId(testId));
49+ expect(element).not.toBeInTheDocument();
50+}
51+
52+export async function verifyNotPresentByText(text: string): Promise<void> {
53+ const element = screen.queryByText(text);
54+ expect(element).not.toBeInTheDocument();
55+}
56+
57+export async function getElementByText(text: string): Promise<HTMLElement> {
58+ try {
59+ const textElement = await waitFor(() => screen.findByText(text));
60+ expect(textElement).toBeInTheDocument();
61+ return textElement;
62+ } catch (e) {
63+ logDomText();
64+ throw new Error(`Element with text "${text}" not found.`);
65+ }
66+}
67+
68+export async function getMainEditor(): Promise<Editor> {
69+ const editorElement = await getElementByTestId("editor-input-main");
70+ if ("editor" in editorElement) {
71+ return editorElement.editor as Editor;
72+ } else {
73+ throw new Error("Main editor not found within editor container");
74+ }
75+}
76+
77+export async function sendInputWithMockedResponse(
78+ ideMessenger: MockIdeMessenger,
79+ input: string,
80+ response: ChatMessage[],
81+): Promise<void> {
82+ // Setup the mock response before any actions
83+ ideMessenger.chatResponse = response;
84+
85+ // Wait for the editor to be in the document
86+ const editor = await getMainEditor();
87+
88+ // Find the submit button
89+ const sendButton = await getElementByTestId("submit-input-button");
90+
91+ // Insert content into the editor
92+ await act(async () => {
93+ editor.commands.insertContent(input);
94+ });
95+
96+ await getElementByText(input);
97+
98+ // Click the send button
99+ await act(async () => {
100+ sendButton.click();
101+ });
102+}