Elffuss BraidHub

kikocis/continue public

35c0ed0a3308 · 4.9 KiBRawPermalink
1import { By, WebDriver, WebView } from "vscode-extension-tester";
2
3import { SelectorUtils } from "./SelectorUtils";
4
5export class GUISelectors {
6 public static getDescription(view: WebView) {
7 return view.findWebElement(By.xpath("//*[contains(text(), 'quickly')]"));
8 }
9
10 public static getMessageInputFields(view: WebView) {
11 return view.findWebElements(By.className("tiptap"));
12 }
13
14 public static async getMessageInputFieldAtIndex(
15 view: WebView,
16 index: number,
17 ) {
18 const elements = await this.getMessageInputFields(view);
19 return elements[index];
20 }
21
22 public static getAllIframes(driver: WebDriver) {
23 return driver.findElements(By.css("iframe"));
24 }
25
26 public static getReactIframe(driver: WebDriver) {
27 return driver.findElement(By.css("iframe"));
28 }
29
30 public static getSubmitInputButton(view: WebView) {
31 return SelectorUtils.getElementByDataTestId(view, "submit-input-button");
32 }
33
34 public static getAcceptToolCallButton(view: WebView) {
35 return SelectorUtils.getElementByDataTestId(
36 view,
37 "accept-tool-call-button",
38 );
39 }
40
41 public static getRejectToolCallButton(view: WebView) {
42 return SelectorUtils.getElementByDataTestId(
43 view,
44 "reject-tool-call-button",
45 );
46 }
47
48 public static getToolCallStatusMessage(view: WebView) {
49 return SelectorUtils.getElementByDataTestId(view, "tool-call-title");
50 }
51
52 public static getToolButton(view: WebView) {
53 return SelectorUtils.getElementByDataTestId(
54 view,
55 `block-settings-toolbar-icon-tools`,
56 );
57 }
58
59 public static getToolPolicyButton(view: WebView, toolName: string) {
60 return SelectorUtils.getElementByDataTestId(
61 view,
62 `tool-policy-item-${toolName}`,
63 );
64 }
65
66 public static getModelDropdownButton(view: WebView) {
67 return SelectorUtils.getElementByDataTestId(view, "model-select-button");
68 }
69
70 public static getModeDropdownButton(view: WebView) {
71 return SelectorUtils.getElementByDataTestId(view, "mode-select-button");
72 }
73
74 public static getFirstContextProviderDropdownItem(view: WebView) {
75 return SelectorUtils.getElementByDataTestId(
76 view,
77 "context-provider-dropdown-item",
78 );
79 }
80
81 public static getContextItemsPeek(view: WebView) {
82 return SelectorUtils.getElementByDataTestId(view, "context-items-peek");
83 }
84
85 public static getFirstContextItemsPeekItem(view: WebView) {
86 return SelectorUtils.getElementByDataTestId(
87 view,
88 "context-items-peek-item",
89 );
90 }
91
92 public static getRulesPeek(view: WebView) {
93 return SelectorUtils.getElementByDataTestId(view, "rules-peek");
94 }
95
96 public static getFirstRulesPeekItem(view: WebView) {
97 return SelectorUtils.getElementByDataTestId(view, "rules-peek-item");
98 }
99
100 public static getNthHistoryTableRow(view: WebView, index: number) {
101 return SelectorUtils.getElementByDataTestId(view, `history-row-${index}`);
102 }
103
104 public static getNthMessageDeleteButton(view: WebView, index: number) {
105 const adjustedIndex = 1 + index * 2;
106
107 return SelectorUtils.getElementByDataTestId(
108 view,
109 `delete-button-${adjustedIndex}`,
110 );
111 }
112
113 public static getModelDropdownOption(view: WebView, option: string) {
114 return view.findWebElement(
115 By.xpath(`//*[@role="listbox"]//*[contains(text(), "${option}")]`),
116 );
117 }
118
119 public static getModeDropdownOption(view: WebView, option: string) {
120 return view.findWebElement(
121 By.xpath(`//*[@role="listbox"]//*[contains(text(), "${option}")]`),
122 );
123 }
124
125 public static getOnboardingTabButton(view: WebView, title: string) {
126 return SelectorUtils.getElementByDataTestId(
127 view,
128 `onboarding-tab-${title}`,
129 );
130 }
131
132 public static getBestChatApiKeyInput(view: WebView) {
133 return SelectorUtils.getElementByDataTestId(
134 view,
135 "best-chat-api-key-input",
136 );
137 }
138
139 public static getBestAutocompleteApiKeyInput(view: WebView) {
140 return SelectorUtils.getElementByDataTestId(
141 view,
142 "best-autocomplete-api-key-input",
143 );
144 }
145
146 public static getTutorialCard(view: WebView) {
147 return SelectorUtils.getElementByDataTestId(view, "tutorial-card");
148 }
149
150 public static getThreadMessageByText(view: WebView, text: string) {
151 return view.findWebElement(
152 By.xpath(`//*[@class="thread-message"]//*[contains(text(), "${text}")]`),
153 );
154 }
155
156 public static getHistoryNavButton(view: WebView) {
157 return SelectorUtils.getElementByAriaLabel(view, "View History");
158 }
159
160 public static getNewSessionNavButton(view: WebView) {
161 return SelectorUtils.getElementByAriaLabel(view, "New Session");
162 }
163
164 public static async getInputBoxCodeBlockAtIndex(
165 view: WebView,
166 index: number,
167 ) {
168 const firstInputField = await this.getMessageInputFieldAtIndex(view, index);
169
170 const codeBlockElement = await firstInputField.findElement(
171 By.xpath(".//code"),
172 );
173
174 return codeBlockElement;
175 }
176
177 public static getContinueExtensionBadge(view: WebView) {
178 return SelectorUtils.getElementByAriaLabel(view, "Continue");
179 }
180}