-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
Autocomplete_JS_spec.ts
279 lines (248 loc) · 8.58 KB
/
Autocomplete_JS_spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
import { WIDGET } from "../../../../locators/WidgetLocators";
import { ObjectsRegistry } from "../../../../support/Objects/Registry";
const {
AggregateHelper: agHelper,
ApiPage,
CommonLocators,
DataSources,
EntityExplorer,
JSEditor: jsEditor,
} = ObjectsRegistry;
const jsObjectBody = `export default {
myVar1: [],
myVar2: {},
myFun1(){
},
myFun2: async () => {
//use async-await or promises
}
}`;
describe("Autocomplete tests", () => {
it("1. Bug #13613 Verify widgets autocomplete: ButtonGroup & Document viewer widget", () => {
EntityExplorer.DragDropWidgetNVerify(WIDGET.BUTTON_GROUP, 200, 200);
EntityExplorer.DragDropWidgetNVerify(WIDGET.DOCUMENT_VIEWER, 200, 500);
// create js object
jsEditor.CreateJSObject(jsObjectBody, {
paste: true,
completeReplace: true,
toRun: false,
shouldCreateNewJSObj: true,
prettify: false,
});
// focus on 5th line
agHelper.GetNClick(jsEditor._lineinJsEditor(5));
// 1. Button group widget autocomplete verification
agHelper.TypeText(CommonLocators._codeMirrorTextArea, "ButtonGroup1.");
agHelper.GetNAssertElementText(CommonLocators._hints, "isVisible");
agHelper.GetNClickByContains(CommonLocators._hints, "isVisible");
agHelper.Sleep();
// 2. Document view widget autocomplete verification
agHelper.SelectNRemoveLineText(CommonLocators._codeMirrorTextArea);
agHelper.GetNClick(jsEditor._lineinJsEditor(5));
agHelper.TypeText(CommonLocators._codeMirrorTextArea, "DocumentViewer1.");
agHelper.GetNAssertElementText(CommonLocators._hints, "docUrl");
agHelper.Sleep();
agHelper.GetNClickByContains(CommonLocators._hints, "docUrl");
});
it("2. Check for bindings not available in other page", () => {
// dependent on above case: 1st page should have DocumentViewer widget
EntityExplorer.AddNewPage();
// create js object
jsEditor.CreateJSObject(jsObjectBody, {
paste: true,
completeReplace: true,
toRun: false,
shouldCreateNewJSObj: true,
prettify: false,
});
// focus on 5th line
agHelper.GetNClick(jsEditor._lineinJsEditor(5));
agHelper.TypeText(CommonLocators._codeMirrorTextArea, "D");
agHelper.GetNAssertElementText(
CommonLocators._hints,
"docUrl",
"not.have.text",
);
agHelper.TypeText(
CommonLocators._codeMirrorTextArea,
"ocumentViewer.docUrl",
);
});
it("3. Bug #15568 Verify browser JavaScript APIs in autocomplete ", () => {
// Using same js object
agHelper.SelectNRemoveLineText(CommonLocators._codeMirrorTextArea);
// focus on 5th line
agHelper.GetNClick(jsEditor._lineinJsEditor(5));
const JSAPIsToTest = [
// console API verification
{
type: "console",
expected: "console",
haveOrNotHave: true,
},
// crypto API verification
{
type: "crypto",
expected: "crypto",
haveOrNotHave: true,
},
// eval function verification
{
type: "eval",
expected: "eval()",
haveOrNotHave: false,
},
{
type: "Blob",
expected: "Blob()",
haveOrNotHave: true,
},
{
type: "FormData",
expected: "FormData()",
haveOrNotHave: true,
},
{
type: "FileReader",
expected: "FileReader()",
haveOrNotHave: true,
},
];
JSAPIsToTest.forEach((test, index) => {
agHelper.TypeText(CommonLocators._codeMirrorTextArea, test.type);
agHelper.GetNAssertElementText(
CommonLocators._hints,
test.expected,
test.haveOrNotHave ? "have.text" : "not.have.text",
);
agHelper.SelectNRemoveLineText(CommonLocators._codeMirrorTextArea);
});
});
it("4. JSObject this. autocomplete", () => {
// Using same js object
// focus on 5th line
agHelper.GetNClick(jsEditor._lineinJsEditor(5));
agHelper.TypeText(CommonLocators._codeMirrorTextArea, "this.");
["myFun2()", "myVar1", "myVar2"].forEach((element, index) => {
agHelper.AssertContains(element);
});
});
it("5. Api data with array of object autocompletion test", () => {
ApiPage.CreateAndFillApi("https://mock-api.appsmith.com/users");
agHelper.Sleep(2000);
ApiPage.RunAPI();
// Using same js object
EntityExplorer.SelectEntityByName("JSObject1", "Queries/JS");
agHelper.GetNClick(jsEditor._lineinJsEditor(5));
agHelper.SelectNRemoveLineText(CommonLocators._codeMirrorTextArea);
//agHelper.GetNClick(jsEditor._lineinJsEditor(5));
agHelper.TypeText(CommonLocators._codeMirrorTextArea, "Api1.data.u");
agHelper.GetNAssertElementText(CommonLocators._hints, "users");
agHelper.Sleep();
agHelper.TypeText(CommonLocators._codeMirrorTextArea, "sers[0].e");
agHelper.GetNAssertElementText(CommonLocators._hints, "email");
agHelper.Sleep();
agHelper.TypeText(CommonLocators._codeMirrorTextArea, "mail");
});
it("6. Local variables & complex data autocompletion test", () => {
// Using same js object
agHelper.SelectNRemoveLineText(CommonLocators._codeMirrorTextArea);
const users = [
{ label: "a", value: "b" },
{ label: "a", value: "b" },
];
const codeToType = `const users = ${JSON.stringify(users)};
const data = { userCollection: [{ users }, { users }] };
users.map(callBack);`;
// component re-render cause DOM element of cy.get to lost
// added wait to finish re-render before cy.get
agHelper.Sleep();
agHelper.GetNClick(jsEditor._lineinJsEditor(5));
agHelper.TypeText(CommonLocators._codeMirrorTextArea, codeToType);
agHelper.GetNClick(jsEditor._lineinJsEditor(7));
agHelper.TypeText(
CommonLocators._codeMirrorTextArea,
"const callBack = (user) => user.l",
);
agHelper.GetNAssertElementText(CommonLocators._hints, "label");
agHelper.TypeText(CommonLocators._codeMirrorTextArea, "abel;");
agHelper.TypeText(CommonLocators._codeMirrorTextArea, "data.");
agHelper.GetNAssertElementText(CommonLocators._hints, "userCollection");
agHelper.Sleep();
agHelper.TypeText(CommonLocators._codeMirrorTextArea, "userCollection[0].");
agHelper.GetNAssertElementText(CommonLocators._hints, "users");
agHelper.Sleep();
agHelper.TypeText(CommonLocators._codeMirrorTextArea, "users[0].");
agHelper.GetNAssertElementText(CommonLocators._hints, "label");
agHelper.GetNAssertElementText(
CommonLocators._hints,
"value",
"have.text",
1,
);
EntityExplorer.ActionContextMenuByEntityName(
"JSObject1",
"Delete",
"Are you sure?",
true,
);
EntityExplorer.ActionContextMenuByEntityName(
"Api1",
"Delete",
"Are you sure?",
);
});
it("7. Autocompletion for bindings inside array and objects", () => {
DataSources.CreateDataSource("Mongo", true, false);
cy.get("@dsName").then(($dsName) => {
DataSources.CreateNewQueryInDS(($dsName as unknown) as string);
DataSources.ValidateNSelectDropdown(
"Commands",
"Find Document(s)",
"Insert Document(s)",
);
cy.xpath(CommonLocators._inputFieldByName("Documents")).then(
($field: any) => {
agHelper.UpdateCodeInput($field, `{\n"_id": "{{appsmith}}"\n}`);
cy.wrap($field)
.find(".CodeMirror")
.find("textarea")
.parents(".CodeMirror")
.first()
.then((ins: any) => {
const input = ins[0].CodeMirror;
input.focus();
cy.wait(200);
cy.get(CommonLocators._codeMirrorTextArea)
.eq(1)
.focus()
.type(
"{downArrow}{downArrow}{leftArrow}{leftArrow}{leftArrow}{leftArrow}",
)
.type(".");
agHelper.GetNAssertElementText(
CommonLocators._hints,
"geolocation",
);
cy.get(".t--close-editor").click();
});
},
);
});
});
it("8. Multiple binding in single line", () => {
DataSources.CreateDataSource("Postgres", true, false);
cy.get("@dsName").then(($dsName) => {
DataSources.CreateNewQueryInDS(
($dsName as unknown) as string,
"SELECT * FROM worldCountryInfo where {{appsmith.store}} {{appsmith}}",
);
cy.get(CommonLocators._codeMirrorTextArea)
.eq(0)
.focus()
.type("{downArrow}{leftArrow}{leftArrow}");
agHelper.TypeText(CommonLocators._codeMirrorTextArea, ".");
agHelper.GetNAssertElementText(CommonLocators._hints, "geolocation");
});
});
});