Elffuss BraidHub

kikocis/continue public

9d8db5fc402e · 4.7 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, "toggle-div-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 getNthHistoryTableRow(view: WebView, index: number) {
93 return SelectorUtils.getElementByDataTestId(view, `history-row-${index}`);
94 }
95
96 public static getNthMessageDeleteButton(view: WebView, index: number) {
97 const adjustedIndex = 1 + index * 2;
98
99 return SelectorUtils.getElementByDataTestId(
100 view,
101 `delete-button-${adjustedIndex}`,
102 );
103 }
104
105 public static getModelDropdownOption(view: WebView, option: string) {
106 return view.findWebElement(
107 By.xpath(`//*[@role="listbox"]//*[contains(text(), "${option}")]`),
108 );
109 }
110
111 public static getModeDropdownOption(view: WebView, option: string) {
112 return view.findWebElement(
113 By.xpath(`//*[@role="listbox"]//*[contains(text(), "${option}")]`),
114 );
115 }
116
117 public static getOnboardingTabButton(view: WebView, title: string) {
118 return SelectorUtils.getElementByDataTestId(
119 view,
120 `onboarding-tab-${title}`,
121 );
122 }
123
124 public static getBestChatApiKeyInput(view: WebView) {
125 return SelectorUtils.getElementByDataTestId(
126 view,
127 "best-chat-api-key-input",
128 );
129 }
130
131 public static getBestAutocompleteApiKeyInput(view: WebView) {
132 return SelectorUtils.getElementByDataTestId(
133 view,
134 "best-autocomplete-api-key-input",
135 );
136 }
137
138 public static getTutorialCard(view: WebView) {
139 return SelectorUtils.getElementByDataTestId(view, "tutorial-card");
140 }
141
142 public static getThreadMessageByText(view: WebView, text: string) {
143 return view.findWebElement(
144 By.xpath(`//*[@class="thread-message"]//*[contains(text(), "${text}")]`),
145 );
146 }
147
148 public static getHistoryNavButton(view: WebView) {
149 return SelectorUtils.getElementByAriaLabel(view, "View History");
150 }
151
152 public static getNewSessionNavButton(view: WebView) {
153 return SelectorUtils.getElementByAriaLabel(view, "New Session");
154 }
155
156 public static async getInputBoxCodeBlockAtIndex(
157 view: WebView,
158 index: number,
159 ) {
160 const firstInputField = await this.getMessageInputFieldAtIndex(view, index);
161
162 const codeBlockElement = await firstInputField.findElement(
163 By.xpath(".//code"),
164 );
165
166 return codeBlockElement;
167 }
168
169 public static getContinueExtensionBadge(view: WebView) {
170 return SelectorUtils.getElementByAriaLabel(view, "Continue");
171 }
172}