How to use hintList method in root

Best JavaScript code snippet using root

unittests.js

Source:unittests.js Github

copy

Full Screen

1/*2 * Copyright (c) 2015 Adobe Systems Incorporated. All rights reserved.3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions:10 * 11 * The above copyright notice and this permission notice shall be included in12 * all copies or substantial portions of the Software.13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 * DEALINGS IN THE SOFTWARE.21 * 22 */23/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */24/*global define, brackets, $, describe, beforeEach, afterEach, it, expect*/25define(function (require, exports, module) {26 "use strict";27 28 // Load dependencies.29 var SpecRunnerUtils = brackets.getModule("spec/SpecRunnerUtils"),30 PrefsCodeHints = require("./main"),31 testPreferences = JSON.parse(require("text!./unittest-files/preferences.json"));32 33 describe("Preferences Code Hints", function () {34 var testContent, testDocument, testEditor, mockEditor;35 36 // A sample preferences file to run tests against.37 testContent = "{\n" +38 " \"closeBrackets\": true,\n" +39 " \"insertHintOnTab\": false,\n" +40 " \"language.fileExtensions\": {\n" +41 " \"txt\": \"markdown\"\n" +42 " },\n" +43 " \"language.fileNames\": {\n" +44 " \"README.txt\": \"markdown\"\n" +45 " },\n" +46 " \"language\": {\n" +47 " \"javascript\": {\n" +48 " \"spaceUnits\": 4,\n" +49 " \"useTabChar\": false\n" +50 " },\n" +51 " \"php\": {\n" +52 " \"tabSize\": 4,\n" +53 " \"useTabChar\":true,\n" +54 " \"closeBrackets\":false\n" +55 " }\n" +56 " },\n" +57 " \"jslint.options\": {\n" +58 " \"devel\": true,\n" +59 " \"regexp\": true\n" +60 " },\n" +61 " \"linting.prefer\": [\"JSHint\",\"JSLint\"],\n" +62 " \n" +63 " \"linting.usePreferredOnly\" false," +64 " \n" +65 "}";66 beforeEach(function () {67 mockEditor = SpecRunnerUtils.createMockEditor(testContent, "json", {68 startLine: 0,69 endLine: 3070 });71 testEditor = mockEditor.editor;72 testDocument = mockEditor.doc;73 74 // Rename the file to preferences file.75 testDocument.file._name = ".brackets.json";76 77 // Setup a test environment by loading minimum preferences required to run unit tests.78 PrefsCodeHints._setupTestEnvironment(testDocument, testPreferences);79 });80 81 afterEach(function () {82 testEditor.destroy();83 testDocument = null;84 });85 86 // Extracts hints out of their DOM nodes.87 function extractHintList(hintList) {88 return $.map(hintList, function ($node) {89 return $node.find(".hint-obj").text();90 });91 }92 93 // Determines the availability of hints.94 function expectHints(provider) {95 expect(provider.hasHints(testEditor, null)).toBe(true);96 var hintObj = provider.getHints();97 expect(hintObj).toBeTruthy();98 return hintObj.hints;99 }100 101 // Determines the non-availability of hints.102 function expectNoHints(provider) {103 var hasHints = provider.hasHints(testEditor, null);104 if (!hasHints) {105 expect(hasHints).toBe(false);106 } else {107 expect(provider.getHints(null)).toBe(null);108 }109 }110 111 // Determines the presence of a hint in the hint list.112 function verifyHints(hintList, expectedHint) {113 var hints = extractHintList(hintList);114 expect(hints[0]).toBe(expectedHint);115 }116 117 // Determines the exclusion of a hint in the hint list.118 function verifyHintsExcluded(hintList, unexpectedHint) {119 var hints = extractHintList(hintList);120 expect(hints.indexOf(unexpectedHint)).toBe(-1);121 }122 123 // Inserts the selected hint.124 function selectHint(provider, expectedHint) {125 var hintList = expectHints(provider),126 hints = extractHintList(hintList),127 index = hints.indexOf(expectedHint);128 expect(index).not.toBe(-1);129 return provider.insertHint(hintList[index]);130 }131 132 // Determines a token at any given position.133 function expectTokenAt(pos, string, type) {134 var token = testEditor._codeMirror.getTokenAt(pos);135 expect(token.string).toBe(string);136 expect(token.type).toBe(type);137 }138 139 // Determines the position of the cursor.140 function expectCursorAt(pos) {141 var selection = testEditor.getSelection();142 expect(selection.start).toEqual(selection.end);143 expect(selection.start).toEqual(pos);144 }145 146 describe("File name based hinting", function () {147 148 it("it should hint in .brackets.json", function () {149 // Between " and closeBrackets"150 testEditor.setCursorPos({line: 1, ch: 5});151 expectHints(PrefsCodeHints.hintProvider);152 153 testEditor.setCursorPos({line: 1, ch: 20});154 expectHints(PrefsCodeHints.hintProvider);155 });156 157 it("it should hint in brackets.json", function () {158 testDocument.file._name = "brackets.json";159 PrefsCodeHints._setupTestEnvironment(testDocument, testPreferences);160 161 // Between " and closeBrackets"162 testEditor.setCursorPos({line: 1, ch: 5});163 expectHints(PrefsCodeHints.hintProvider);164 165 // After "closeBrackets":166 testEditor.setCursorPos({line: 1, ch: 20});167 expectHints(PrefsCodeHints.hintProvider);168 });169 170 it("it should NOT hint in other JSON files", function () {171 testDocument.file._name = "package.json";172 PrefsCodeHints._setupTestEnvironment(testDocument, testPreferences);173 174 // Between " and closeBrackets"175 testEditor.setCursorPos({line: 1, ch: 5});176 expectNoHints(PrefsCodeHints.hintProvider);177 178 // After "closeBrackets":179 testEditor.setCursorPos({line: 1, ch: 20});180 expectNoHints(PrefsCodeHints.hintProvider);181 });182 });183 184 describe("Key Hints", function () {185 it("should hint at the begininng of a key", function () {186 var hintList;187 188 // Between " and language"189 testEditor.setCursorPos({line: 9, ch: 5});190 hintList = expectHints(PrefsCodeHints.hintProvider);191 verifyHints(hintList, "closeOthers.above");192 193 // Between " and javascript"194 testEditor.setCursorPos({line: 10, ch: 9});195 hintList = expectHints(PrefsCodeHints.hintProvider);196 verifyHints(hintList, "audio");197 198 // Between " and spaceUnits"199 testEditor.setCursorPos({line: 11, ch: 13});200 hintList = expectHints(PrefsCodeHints.hintProvider);201 verifyHints(hintList, "closeBrackets");202 });203 it("should hint in the center of a key", function () {204 var hintList;205 206 // In "language"207 testEditor.setCursorPos({line: 9, ch: 9});208 hintList = expectHints(PrefsCodeHints.hintProvider);209 verifyHints(hintList, "language");210 211 // In "javascript"212 testEditor.setCursorPos({line: 10, ch: 14});213 hintList = expectHints(PrefsCodeHints.hintProvider);214 verifyHints(hintList, "javascript");215 216 // In "spaceUnits"217 testEditor.setCursorPos({line: 11, ch: 18});218 hintList = expectHints(PrefsCodeHints.hintProvider);219 verifyHints(hintList, "spaceUnits");220 });221 it("should hint at the end of a key", function () {222 var hintList;223 224 // Between "language and "225 testEditor.setCursorPos({line: 9, ch: 13});226 hintList = expectHints(PrefsCodeHints.hintProvider);227 verifyHints(hintList, "language");228 229 // Between "javascript and "230 testEditor.setCursorPos({line: 10, ch: 19});231 hintList = expectHints(PrefsCodeHints.hintProvider);232 verifyHints(hintList, "javascript");233 234 // Between "spaceUnits and "235 testEditor.setCursorPos({line: 11, ch: 23});236 hintList = expectHints(PrefsCodeHints.hintProvider);237 verifyHints(hintList, "spaceUnits");238 });239 240 it("should NOT hint for blacklisted parent keys", function () {241 // Between " and txt"242 testEditor.setCursorPos({line: 4, ch: 9});243 expectNoHints(PrefsCodeHints.hintProvider);244 245 // In "txt"246 testEditor.setCursorPos({line: 4, ch: 11});247 expectNoHints(PrefsCodeHints.hintProvider);248 249 // Between " and README.txt"250 testEditor.setCursorPos({line: 7, ch: 9});251 expectNoHints(PrefsCodeHints.hintProvider);252 253 // In "README.txt"254 testEditor.setCursorPos({line: 7, ch: 15});255 expectNoHints(PrefsCodeHints.hintProvider);256 });257 258 it("should NOT hint before initial quote of a key", function () {259 // Before "closeBrackets"260 testEditor.setCursorPos({line: 1, ch: 4});261 expectNoHints(PrefsCodeHints.hintProvider);262 263 // Before "language"264 testEditor.setCursorPos({line: 9, ch: 4});265 expectNoHints(PrefsCodeHints.hintProvider);266 267 // Before "javascript"268 testEditor.setCursorPos({line: 10, ch: 8});269 expectNoHints(PrefsCodeHints.hintProvider);270 271 // Before "spaceUnits"272 testEditor.setCursorPos({line: 11, ch: 12});273 expectNoHints(PrefsCodeHints.hintProvider);274 });275 it("should NOT hint after final quote of a key", function () {276 // After "closeBrackets"277 testEditor.setCursorPos({line: 1, ch: 19});278 expectNoHints(PrefsCodeHints.hintProvider);279 280 // After "language"281 testEditor.setCursorPos({line: 9, ch: 14});282 expectNoHints(PrefsCodeHints.hintProvider);283 284 // After "javascript"285 testEditor.setCursorPos({line: 10, ch: 20});286 expectNoHints(PrefsCodeHints.hintProvider);287 288 // After "spaceUnits"289 testEditor.setCursorPos({line: 11, ch: 24});290 expectNoHints(PrefsCodeHints.hintProvider);291 });292 293 it("should NOT include keys already used in the context of current object", function () {294 var hintList;295 296 // Between " and insertHintOnTab"297 testEditor.setCursorPos({line: 2, ch: 5});298 hintList = expectHints(PrefsCodeHints.hintProvider);299 verifyHintsExcluded(hintList, "closeBrackets");300 verifyHintsExcluded(hintList, "language.fileExtensions");301 verifyHintsExcluded(hintList, "language.fileNames");302 verifyHintsExcluded(hintList, "language");303 verifyHintsExcluded(hintList, "jslint.options");304 verifyHintsExcluded(hintList, "linting.prefer");305 verifyHintsExcluded(hintList, "linting.usePreferredOnly");306 307 // Between " and insertHintOnTab"308 testEditor.setCursorPos({line: 15, ch: 13});309 hintList = expectHints(PrefsCodeHints.hintProvider);310 verifyHintsExcluded(hintList, "useTabChar");311 verifyHintsExcluded(hintList, "closeBrackets");312 });313 });314 315 describe("Value Hints", function () {316 it("should hint after a colon", function () {317 var hintList;318 319 // After "closeBrackets":320 testEditor.setCursorPos({line: 1, ch: 20});321 hintList = expectHints(PrefsCodeHints.hintProvider);322 verifyHints(hintList, "false");323 324 // After "insertHintOnTab":325 testEditor.setCursorPos({line: 2, ch: 22});326 hintList = expectHints(PrefsCodeHints.hintProvider);327 verifyHints(hintList, "false");328 329 // After "useTabChar":330 testEditor.setCursorPos({line: 12, ch: 25});331 hintList = expectHints(PrefsCodeHints.hintProvider);332 verifyHints(hintList, "false");333 });334 it("should hint after after a space followed by a colon", function () {335 var hintList;336 337 // After "closeBrackets":+space338 testEditor.setCursorPos({line: 1, ch: 21});339 hintList = expectHints(PrefsCodeHints.hintProvider);340 verifyHints(hintList, "false");341 342 // After "insertHintOnTab":+space343 testEditor.setCursorPos({line: 2, ch: 23});344 hintList = expectHints(PrefsCodeHints.hintProvider);345 verifyHints(hintList, "false");346 347 // After "useTabChar":+space348 testEditor.setCursorPos({line: 12, ch: 26});349 hintList = expectHints(PrefsCodeHints.hintProvider);350 verifyHints(hintList, "false");351 });352 it("should hint even if space is missing after a colon", function () {353 var hintList;354 355 // After "useTabChar":356 testEditor.setCursorPos({line: 16, ch: 25});357 hintList = expectHints(PrefsCodeHints.hintProvider);358 verifyHints(hintList, "false");359 360 // After "closeBrackets":361 testEditor.setCursorPos({line: 17, ch: 28});362 hintList = expectHints(PrefsCodeHints.hintProvider);363 verifyHints(hintList, "false");364 });365 it("should hint at the beginning of value", function () {366 var hintList;367 368 // After "closeBrackets": t369 testEditor.setCursorPos({line: 1, ch: 22});370 hintList = expectHints(PrefsCodeHints.hintProvider);371 verifyHints(hintList, "true");372 373 // After "insertHintOnTab": f374 testEditor.setCursorPos({line: 2, ch: 24});375 hintList = expectHints(PrefsCodeHints.hintProvider);376 verifyHints(hintList, "false");377 378 // After "useTabChar": f379 testEditor.setCursorPos({line: 12, ch: 27});380 hintList = expectHints(PrefsCodeHints.hintProvider);381 verifyHints(hintList, "false");382 });383 it("should hint at the center of value", function () {384 var hintList;385 386 // After "closeBrackets": tru387 testEditor.setCursorPos({line: 1, ch: 24});388 hintList = expectHints(PrefsCodeHints.hintProvider);389 verifyHints(hintList, "true");390 391 // After "insertHintOnTab": fal392 testEditor.setCursorPos({line: 2, ch: 26});393 hintList = expectHints(PrefsCodeHints.hintProvider);394 verifyHints(hintList, "false");395 396 // After "useTabChar": fal397 testEditor.setCursorPos({line: 12, ch: 29});398 hintList = expectHints(PrefsCodeHints.hintProvider);399 verifyHints(hintList, "false");400 });401 it("should hint at the end of the value", function () {402 var hintList;403 404 // After "closeBrackets": true405 testEditor.setCursorPos({line: 1, ch: 25});406 hintList = expectHints(PrefsCodeHints.hintProvider);407 verifyHints(hintList, "true");408 409 // After "insertHintOnTab": false410 testEditor.setCursorPos({line: 2, ch: 28});411 hintList = expectHints(PrefsCodeHints.hintProvider);412 verifyHints(hintList, "false");413 414 // After "useTabChar": false415 testEditor.setCursorPos({line: 12, ch: 31});416 hintList = expectHints(PrefsCodeHints.hintProvider);417 verifyHints(hintList, "false");418 });419 420 it("should NOT hint if the corresponding colon is missing", function () {421 // After "linting.usePreferredOnly"422 testEditor.setCursorPos({line: 26, ch: 30});423 expectNoHints(PrefsCodeHints.hintProvider);424 425 // After "linting.usePreferredOnly"+space426 testEditor.setCursorPos({line: 26, ch: 31});427 expectNoHints(PrefsCodeHints.hintProvider);428 429 // After "linting.usePreferredOnly" f430 testEditor.setCursorPos({line: 26, ch: 32});431 expectNoHints(PrefsCodeHints.hintProvider);432 433 // After "linting.usePreferredOnly" fal434 testEditor.setCursorPos({line: 26, ch: 34});435 expectNoHints(PrefsCodeHints.hintProvider);436 437 // After "linting.usePreferredOnly" false438 testEditor.setCursorPos({line: 26, ch: 36});439 expectNoHints(PrefsCodeHints.hintProvider);440 });441 it("should NOT hint after a comma", function () {442 // After "closeBrackets": true,443 testEditor.setCursorPos({line: 1, ch: 26});444 expectNoHints(PrefsCodeHints.hintProvider);445 446 // After "insertHintOnTab": false,447 testEditor.setCursorPos({line: 2, ch: 29});448 expectNoHints(PrefsCodeHints.hintProvider);449 450 // After "javascript": { [rules] },451 testEditor.setCursorPos({line: 13, ch: 10});452 expectNoHints(PrefsCodeHints.hintProvider);453 454 // After "language": { [languages] },455 testEditor.setCursorPos({line: 19, ch: 6});456 expectNoHints(PrefsCodeHints.hintProvider);457 });458 it("should NOT hint before opening braces", function () {459 // Between "javascript": and {460 testEditor.setCursorPos({line: 10, ch: 22});461 expectNoHints(PrefsCodeHints.hintProvider);462 463 // After "javascript": {464 testEditor.setCursorPos({line: 10, ch: 23});465 expectNoHints(PrefsCodeHints.hintProvider);466 });467 it("should NOT hint after closing braces", function () {468 // After "javascript": { [rules] }469 testEditor.setCursorPos({line: 13, ch: 9});470 expectNoHints(PrefsCodeHints.hintProvider);471 472 // After "language": { [languages] }473 testEditor.setCursorPos({line: 19, ch: 5});474 expectNoHints(PrefsCodeHints.hintProvider);475 });476 it("should NOT hint before opening brackets", function () {477 testEditor.setCursorPos({line: 10, ch: 22});478 expectNoHints(PrefsCodeHints.hintProvider);479 });480 it("should NOT hint after closing brackets", function () {481 testEditor.setCursorPos({line: 10, ch: 22});482 expectNoHints(PrefsCodeHints.hintProvider);483 });484 });485 486 describe("Key Insertion", function () {487 it("should enter entire key after initial quote is typed", function () {488 testDocument.replaceRange("\"", {line: 25, ch: 4});489 testEditor.setCursorPos({line: 25, ch: 5});490 selectHint(PrefsCodeHints.hintProvider, "closeOthers.above");491 expectTokenAt({line: 25, ch: 22}, "\"closeOthers.above\"", "string property");492 expectTokenAt({line: 25, ch: 24}, ":", null);493 expectCursorAt({line: 25, ch: 25});494 });495 it("should enter entire key after first letter of a key is typed", function () {496 testDocument.replaceRange("\"c", {line: 25, ch: 4});497 testEditor.setCursorPos({line: 25, ch: 6});498 selectHint(PrefsCodeHints.hintProvider, "closeOthers.above");499 expectTokenAt({line: 25, ch: 22}, "\"closeOthers.above\"", "string property");500 expectTokenAt({line: 25, ch: 24}, ":", null);501 expectCursorAt({line: 25, ch: 25});502 });503 it("should enter entire key after few initial letters are typed", function () {504 testDocument.replaceRange("\"close", {line: 25, ch: 4});505 testEditor.setCursorPos({line: 25, ch: 10});506 selectHint(PrefsCodeHints.hintProvider, "closeOthers.above");507 expectTokenAt({line: 25, ch: 22}, "\"closeOthers.above\"", "string property");508 expectTokenAt({line: 25, ch: 24}, ":", null);509 expectCursorAt({line: 25, ch: 25});510 });511 it("should replace existing key after few initial letter are typed", function () {512 testDocument.replaceRange("\"closeOthers.above\": true,", {line: 25, ch: 4});513 testEditor.setCursorPos({line: 25, ch: 17});514 selectHint(PrefsCodeHints.hintProvider, "closeOthers.below");515 expectTokenAt({line: 25, ch: 22}, "\"closeOthers.below\"", "string property");516 expectTokenAt({line: 25, ch: 24}, ":", null);517 expectCursorAt({line: 25, ch: 23});518 });519 it("should append braces to a hint in case it is an object", function () {520 testDocument.replaceRange("\"", {line: 25, ch: 4});521 testEditor.setCursorPos({line: 25, ch: 5});522 selectHint(PrefsCodeHints.hintProvider, "closeTags");523 expectTokenAt({line: 25, ch: 14}, "\"closeTags\"", "string property");524 expectTokenAt({line: 25, ch: 16}, ":", null);525 expectTokenAt({line: 25, ch: 18}, "{", null);526 expectTokenAt({line: 25, ch: 19}, "}", null);527 expectCursorAt({line: 25, ch: 18});528 });529 it("should append brackets to a hint in case it in an array", function () {530 testDocument.replaceRange("\"closeTags\": { \"\" }", {line: 25, ch: 4});531 testEditor.setCursorPos({line: 25, ch: 20});532 selectHint(PrefsCodeHints.hintProvider, "indentTags");533 expectTokenAt({line: 25, ch: 30}, "\"indentTags\"", "string property");534 expectTokenAt({line: 25, ch: 32}, ":", null);535 expectTokenAt({line: 25, ch: 34}, "[", null);536 expectTokenAt({line: 25, ch: 35}, "]", null);537 expectCursorAt({line: 25, ch: 34});538 });539 540 it("should NOT replace colon and braces/brackets if they already exists", function () {541 // After close in "closeBrackets": true542 testEditor.setCursorPos({line: 1, ch: 10});543 expectTokenAt({line: 1, ch: 20}, ":", null);544 selectHint(PrefsCodeHints.hintProvider, "closeOthers.above");545 expectTokenAt({line: 1, ch: 24}, ":", null);546 });547 });548 549 describe("Value Insertion", function () {550 it("should insert a value of type Boolean", function () {551 testDocument.replaceRange("\"closeOthers.above\":,", {line: 25, ch: 4});552 testEditor.setCursorPos({line: 25, ch: 24});553 selectHint(PrefsCodeHints.hintProvider, "true");554 expectTokenAt({line: 25, ch: 28}, "true", "atom");555 expectCursorAt({line: 25, ch: 28});556 });557 it("should replace current token when editing", function () {558 testDocument.replaceRange("\"closeOthers.above\": tru", {line: 25, ch: 4});559 testEditor.setCursorPos({line: 25, ch: 28});560 selectHint(PrefsCodeHints.hintProvider, "true");561 expectTokenAt({line: 25, ch: 28}, "true", "atom");562 expectCursorAt({line: 25, ch: 29});563 });564 it("should insert a value of type String", function () {565 testDocument.replaceRange(",\n \"pavement\":", {line: 7, ch: 32});566 testEditor.setCursorPos({line: 8, ch: 19});567 selectHint(PrefsCodeHints.hintProvider, "python");568 expectTokenAt({line: 8, ch: 27}, "\"python\"", "string");569 expectCursorAt({line: 8, ch: 27});570 });571 it("should insert a value if the next token is also a value", function () {572 // Before true573 testEditor.setCursorPos({line: 1, ch: 21});574 selectHint(PrefsCodeHints.hintProvider, "false");575 expectTokenAt({line: 1, ch: 26}, "false", "atom");576 expectCursorAt({line: 1, ch: 26});577 // Before "JSHint"578 testEditor.setCursorPos({line: 24, ch: 23});579 selectHint(PrefsCodeHints.hintProvider, "JSLint");580 expectTokenAt({line: 24, ch: 31}, "\"JSLint\"", "string");581 expectCursorAt({line: 24, ch: 31});582 });583 });584 });...

Full Screen

Full Screen

xmlViewHintsSpec.js

Source:xmlViewHintsSpec.js Github

copy

Full Screen

1define((require, exports) => {2 const editorUtils = require("tests/editorUtils"),3 ui5HintsProvider = require("src/codeHints/ui5HintsProvider"),4 xmlViewContent1 = require("text!tests/fixtures/testView1.txt"),5 xmlViewContent2 = require("text!tests/fixtures/testView2.xml"),6 testUtils = require("tests/testUtils"),7 ui5SchemaService = require("src/core/ui5SchemaService"),8 tagsFixture = require("text!tests/fixtures/xmlViewTags.json");9 exports.getTests = function () {10 const insertPoint = {11 line: 6,12 ch: 013 };14 ui5SchemaService.tags = JSON.parse(tagsFixture);15 function expectHints(provider, editor) {16 expect(provider.hasHints(editor, null)).toBe(true);17 const hintsObj = provider.getHints();18 expect(hintsObj).toBeTruthy();19 return hintsObj.hints;20 }21 function expectNoHints(provider, editor) {22 let result = provider.hasHints(editor, null);23 if (result && provider.getHints().hints.length === 0) {24 result = false;25 }26 expect(result).toBe(false);27 }28 function getTagHintUi5Object(hintObject) {29 return hintObject.contents().first().text();30 }31 function verifyTagHints(hintList, expectedFirstHintObject, expectedPartInObject, excludedObject) {32 expectedFirstHintObject = expectedFirstHintObject || "AbsoluteLayout";33 expect(getTagHintUi5Object(hintList[0])).toBe(expectedFirstHintObject);34 const regex = new RegExp(expectedPartInObject, "i");35 hintList.forEach((hintObject) => {36 expect(getTagHintUi5Object(hintObject).search(regex)).not.toBe(-1);37 });38 if (excludedObject) {39 const excludedRegex = new RegExp(excludedObject, "i");40 hintList.forEach((hintObject) => {41 expect(getTagHintUi5Object(hintObject).search(excludedRegex)).toBe(-1);42 });43 }44 }45 function selectTagHint(objectName, hintList) {46 return hintList.find((hintObject) => {47 return getTagHintUi5Object(hintObject) === objectName;48 });49 }50 function selectAttributeHint(attributeName, hintList) {51 return hintList.find((hintObject) => {52 return hintObject.contents().first().text() === attributeName;53 });54 }55 function insertHint(hintObject, provider) {56 provider.insertHint(hintObject);57 }58 function verifyAttributeHints(hintList, expectedHints) {59 const attributeNames = hintList.map((element) => {60 return element.contents().first().text();61 });62 attributeNames.sort();63 expectedHints.sort();64 expect(attributeNames).toEqual(expectedHints);65 }66 describe("[wozjac.ui5] UI5 xml hints", () => {67 let testEditor;68 beforeEach(() => {69 testUtils.mockUi5Api();70 testUtils.mockPreferences();71 testEditor = testUtils.createTestEditor(xmlViewContent1, "xml");72 });73 afterEach(() => {74 testUtils.destroyTestEditor(testEditor);75 });76 describe("[wozjac.ui5] xmlViewTagHints.js", () => {77 it("Should hint with namespace 'c' for < just before existing tag", () => {78 testEditor.doc.replaceRange("<<", insertPoint);79 testEditor.editor.setCursorPos({80 line: 6,81 ch: 182 }); // cursor between the two <s83 const hintList = expectHints(ui5HintsProvider.getXmlViewTagsHintsProvider(), testEditor.editor);84 verifyTagHints(hintList, "c");85 });86 it("Should hint with namespace 'html'", () => {87 testEditor.doc.replaceRange("<h", insertPoint);88 testEditor.editor.setCursorPos({89 line: 6,90 ch: 291 });92 const hintList = expectHints(ui5HintsProvider.getXmlViewTagsHintsProvider(), testEditor.editor);93 verifyTagHints(hintList, "html");94 });95 it("Should filter hints by part of a tag", () => {96 testEditor.doc.replaceRange("<But", insertPoint);97 testEditor.editor.setCursorPos({98 line: 6,99 ch: 4100 });101 const hintList = expectHints(ui5HintsProvider.getXmlViewTagsHintsProvider(), testEditor.editor);102 verifyTagHints(hintList, "Button", "But");103 });104 it("Should hint for a tag with a namespace", () => {105 testEditor.doc.replaceRange("<c:inplac", insertPoint);106 testEditor.editor.setCursorPos({107 line: 6,108 ch: 9109 });110 const hintList = expectHints(ui5HintsProvider.getXmlViewTagsHintsProvider(), testEditor.editor);111 verifyTagHints(hintList, "InPlaceEdit", "inplac");112 });113 it("Should hint tags only from a namespace", () => {114 testEditor.doc.replaceRange("<c:", insertPoint);115 testEditor.editor.setCursorPos({116 line: 6,117 ch: 3118 });119 const hintList = expectHints(ui5HintsProvider.getXmlViewTagsHintsProvider(), testEditor.editor);120 verifyTagHints(hintList, "AbsoluteLayout", "", "ActionBar");121 });122 it("Should hint all namespaces for a tag with a non-exiting namespace", () => {123 testEditor.doc.replaceRange("<namespace:Ico", insertPoint);124 testEditor.editor.setCursorPos({125 line: 6,126 ch: 14127 });128 const hintList = expectHints(ui5HintsProvider.getXmlViewTagsHintsProvider(), testEditor.editor);129 verifyTagHints(hintList, "IconTabBar", "Ico");130 });131 it("Should return no hints", () => {132 testEditor.doc.replaceRange("<dfrtg", insertPoint);133 testEditor.editor.setCursorPos({134 line: 6,135 ch: 6136 });137 expectNoHints(ui5HintsProvider.getXmlViewTagsHintsProvider(), testEditor.editor);138 });139 it("Should hint for a cluttered tags", () => {140 testEditor.doc.replaceRange("<But<Other", insertPoint);141 testEditor.editor.setCursorPos({142 line: 6,143 ch: 4144 });145 const hintList = expectHints(ui5HintsProvider.getXmlViewTagsHintsProvider(), testEditor.editor);146 verifyTagHints(hintList, "Button", "But");147 });148 it("Should insert a hint after a bracket", () => {149 const provider = ui5HintsProvider.getXmlViewTagsHintsProvider();150 testEditor.doc.replaceRange("<", insertPoint);151 testEditor.editor.setCursorPos({152 line: 6,153 ch: 1154 });155 const hintList = expectHints(provider, testEditor.editor);156 const hint = selectTagHint("Button", hintList);157 insertHint(hint, provider);158 expect(testEditor.doc.getLine(6)).toBe("<Button");159 });160 it("Should insert a hint at the beginning", () => {161 const provider = ui5HintsProvider.getXmlViewTagsHintsProvider();162 testEditor.doc.replaceRange("<Butt", insertPoint);163 testEditor.editor.setCursorPos({164 line: 6,165 ch: 1166 });167 const hintList = expectHints(provider, testEditor.editor);168 const hint = selectTagHint("Bar", hintList);169 insertHint(hint, provider);170 expect(testEditor.doc.getLine(6)).toBe("<Barutt");171 });172 it("Should insert a hint for a part", () => {173 const provider = ui5HintsProvider.getXmlViewTagsHintsProvider();174 testEditor.doc.replaceRange("<Butt<Other>", insertPoint);175 testEditor.editor.setCursorPos({176 line: 6,177 ch: 5178 });179 const hintList = expectHints(provider, testEditor.editor);180 const hint = selectTagHint("Button", hintList);181 insertHint(hint, provider);182 expect(testEditor.doc.getLine(6)).toBe("<Button<Other>");183 });184 it("Should insert a hint for a partial tag with namespace", () => {185 const provider = ui5HintsProvider.getXmlViewTagsHintsProvider();186 testEditor.doc.replaceRange("<name:Ic ", insertPoint);187 testEditor.editor.setCursorPos({188 line: 6,189 ch: 8190 });191 const hintList = expectHints(provider, testEditor.editor);192 const hint = selectTagHint("IconTabBar", hintList);193 insertHint(hint, provider);194 expect(testEditor.doc.getLine(6)).toBe("<name:IconTabBar ");195 });196 it("Should insert a hint for a cluttered partial tag with namespace", () => {197 const provider = ui5HintsProvider.getXmlViewTagsHintsProvider();198 testEditor.doc.replaceRange("<name:Ic<Other> ", insertPoint);199 testEditor.editor.setCursorPos({200 line: 6,201 ch: 8202 });203 const hintList = expectHints(provider, testEditor.editor);204 const hint = selectTagHint("IconTabBar", hintList);205 insertHint(hint, provider);206 expect(testEditor.doc.getLine(6)).toBe("<name:IconTabBar<Other> ");207 });208 it("Should insert a hint a in the middle of a line", () => {209 const provider = ui5HintsProvider.getXmlViewTagsHintsProvider();210 testEditor.doc.replaceRange("<tag> </tag> <But <Other>", insertPoint);211 testEditor.editor.setCursorPos({212 line: 6,213 ch: 20214 });215 const hintList = expectHints(provider, testEditor.editor);216 const hint = selectTagHint("Button", hintList);217 insertHint(hint, provider);218 expect(testEditor.doc.getLine(6)).toBe("<tag> </tag> <Button <Other>");219 });220 it("Should insert a hint in the middle of the tag", () => {221 const provider = ui5HintsProvider.getXmlViewTagsHintsProvider();222 testEditor.doc.replaceRange("<Buttadasdasda> <Other>", insertPoint);223 testEditor.editor.setCursorPos({224 line: 6,225 ch: 5226 });227 const hintList = expectHints(provider, testEditor.editor);228 const hint = selectTagHint("Button", hintList);229 insertHint(hint, provider);230 expect(testEditor.doc.getLine(6)).toBe("<Button> <Other>");231 });232 it("Should hint attributes for a tag", () => {233 testEditor.doc.replaceRange("<CancelAction ", insertPoint);234 testEditor.editor.setCursorPos({235 line: 6,236 ch: 19237 });238 const hintList = expectHints(ui5HintsProvider.getXmlViewAttributesHintsProvider(), testEditor.editor);239 verifyAttributeHints(hintList, ["enabled", "press", "visible"]);240 });241 it("Should hint attributes for a tag with a namespace", () => {242 testEditor.doc.replaceRange("<c:Area ", insertPoint);243 testEditor.editor.setCursorPos({244 line: 6,245 ch: 8246 });247 const hintList = expectHints(ui5HintsProvider.getXmlViewAttributesHintsProvider(), testEditor.editor);248 verifyAttributeHints(hintList, ["shape", "coords", "href", "alt"].sort());249 });250 it("Should not hint for a tag", () => {251 testEditor.doc.replaceRange("<namespace:ComboBoxTextField ", insertPoint);252 testEditor.editor.setCursorPos({253 line: 6,254 ch: 13255 });256 expectNoHints(ui5HintsProvider.getXmlViewAttributesHintsProvider(), testEditor.editor);257 });258 it("Should hint filtered attributes for a tag", () => {259 testEditor.doc.replaceRange("<c:Button e", insertPoint);260 testEditor.editor.setCursorPos({261 line: 6,262 ch: 19263 });264 const hintList = expectHints(ui5HintsProvider.getXmlViewAttributesHintsProvider(), testEditor.editor);265 verifyAttributeHints(hintList, ["enabled"]);266 });267 it("Should not hint for an attribute", () => {268 testEditor.doc.replaceRange("<Button enabled=\"true\">", insertPoint);269 testEditor.editor.setCursorPos({270 line: 6,271 ch: 16272 });273 expectNoHints(ui5HintsProvider.getXmlViewAttributesHintsProvider(), testEditor.editor);274 testEditor.editor.setCursorPos({275 line: 6,276 ch: 17277 });278 expectNoHints(ui5HintsProvider.getXmlViewAttributesHintsProvider(), testEditor.editor);279 testEditor.editor.setCursorPos({280 line: 6,281 ch: 18282 });283 expectNoHints(ui5HintsProvider.getXmlViewAttributesHintsProvider(), testEditor.editor);284 testEditor.editor.setCursorPos({285 line: 6,286 ch: 20287 });288 expectNoHints(ui5HintsProvider.getXmlViewAttributesHintsProvider(), testEditor.editor);289 });290 it("Should hint for a namespaced attributes only", () => {291 testEditor.doc.replaceRange("<c:Dialog ", insertPoint);292 testEditor.editor.setCursorPos({293 line: 6,294 ch: 10295 });296 const hintList = expectHints(ui5HintsProvider.getXmlViewAttributesHintsProvider(), testEditor.editor);297 verifyAttributeHints(hintList, ["width", "height", "scrollLeft", "scrollTop", "title", "applyContentPadding", "showCloseButton", "resizable", "minWidth", "minHeight", "maxWidth", "maxHeight", "contentBorderDesign", "modal", "accessibleRole", "keepInWindow", "autoClose", "defaultButton", "initialFocus", "closed", "busy", "busyIndicatorDelay", "busyIndicatorSize", "visible", "fieldGroupIds", "validateFieldGroup"]);298 });299 it("Should insert an attribute hint", () => {300 const provider = ui5HintsProvider.getXmlViewAttributesHintsProvider();301 testEditor.doc.replaceRange("<Button ", insertPoint);302 testEditor.editor.setCursorPos({303 line: 6,304 ch: 8305 });306 const hintList = expectHints(provider, testEditor.editor);307 const hint = selectAttributeHint("enabled", hintList);308 insertHint(hint, provider);309 expect(testEditor.doc.getLine(6)).toBe("<Button enabled=\"\"");310 });311 it("Should insert an attribute hint after a partial attribute", () => {312 const provider = ui5HintsProvider.getXmlViewAttributesHintsProvider();313 testEditor.doc.replaceRange("<Button ena", insertPoint);314 testEditor.editor.setCursorPos({315 line: 6,316 ch: 11317 });318 const hintList = expectHints(provider, testEditor.editor);319 const hint = selectAttributeHint("enabled", hintList);320 insertHint(hint, provider);321 expect(testEditor.doc.getLine(6)).toBe("<Button enabled=\"\"");322 });323 it("Should insert an attribute hint leaving existing value", () => {324 const provider = ui5HintsProvider.getXmlViewAttributesHintsProvider();325 testEditor.doc.replaceRange("<Button enab=\"value\"", insertPoint);326 testEditor.editor.setCursorPos({327 line: 6,328 ch: 12329 });330 const hintList = expectHints(provider, testEditor.editor);331 const hint = selectAttributeHint("enabled", hintList);332 insertHint(hint, provider);333 expect(testEditor.doc.getLine(6)).toBe("<Button enabled=\"value\"");334 });335 });336 describe("[wozjac.ui5] UI5 xml hints - no namespaces in the XML", () => {337 let testEditor;338 beforeEach(() => {339 $("body").append("<div id='editor'/>");340 testEditor = editorUtils.createMockEditor(xmlViewContent2, "xml");341 });342 afterEach(() => {343 testEditor.editor.destroy();344 testEditor = null;345 $("#editor").remove();346 });347 it("Should hint all tags from all namespaces", () => {348 const provider = ui5HintsProvider.getXmlViewTagsHintsProvider();349 testEditor.editor.setCursorPos({350 line: 3,351 ch: 5352 });353 const hintList = expectHints(provider, testEditor.editor);354 verifyTagHints(hintList);355 expect(hintList.length).toBe(485);356 });357 it("Should hint attributes for a tag", () => {358 const provider = ui5HintsProvider.getXmlViewAttributesHintsProvider();359 spyOn(provider, "_searchAllAttributes").andCallThrough();360 testEditor.doc.replaceRange("Button", {361 line: 3,362 ch: 5363 });364 testEditor.editor.setCursorPos({365 line: 3,366 ch: 12367 });368 const hintList = expectHints(provider, testEditor.editor);369 expect(hintList.length).toBe(19);370 expect(provider._searchAllAttributes).toHaveBeenCalled();371 });372 });373 });374 };...

Full Screen

Full Screen

jsHintsExpect.js

Source:jsHintsExpect.js Github

copy

Full Screen

1define((require, exports) => {2 "use strict";3 const SAP_LIBRARY_API_OBJECT_NAMES = [4 "sap.ui.base.Object",5 "sap.ui.base.EventProvider",6 "sap.m.Tree",7 "sap.m.ColumnListItem",8 "jQuery.Event",9 "sap.ui"10 ];11 function waitForHints(hintObj, callback) {12 let complete = false,13 hintList = null;14 if (hintObj.hasOwnProperty("hints")) {15 complete = true;16 hintList = hintObj.hints;17 } else {18 hintObj.done((obj) => {19 complete = true;20 hintList = obj.hints;21 });22 }23 waitsFor(() => {24 return complete;25 }, "Expected hints did not resolve", 3000);26 runs(() => {27 callback(hintList);28 });29 }30 function expectNoHints(hintsObject) {31 let rejectedHints = false;32 hintsObject.fail(() => {33 rejectedHints = true;34 });35 waitsFor(() => {36 return rejectedHints;37 }, "Expected hints did not resolve", 3000);38 runs(() => {39 expect(rejectedHints).toEqual(true);40 });41 }42 function expectHintsEntries(hintList, expectedEntries) {43 const hints = hintList.map((element) => {44 return element.find("span.brackets-ui5-hint-name").text();45 });46 expect(hints).toEqual(expectedEntries);47 }48 function selectHint(hintText, hintList) {49 return hintList.find((hintObject) => {50 return hintObject.find("span.brackets-ui5-hint-name").text() === hintText;51 });52 }53 function expectAllLibraryObjectsHintsEntries(hintList) {54 const hints = hintList.map((element) => {55 return element.find("span.brackets-ui5-hint-name").text();56 });57 expect(hints).toEqual(SAP_LIBRARY_API_OBJECT_NAMES);58 return hints;59 }60 function expectHints(provider, sapui5Object, hintsLength, callback) {61 waitForHints(provider.getHints(), (hintList) => {62 expect(provider.proposedUi5Object.basename).toBe(sapui5Object);63 expect(hintList.length).toBe(hintsLength);64 if (callback) {65 callback(hintList);66 }67 });68 }69 exports.expectHints = expectHints;70 exports.expectAllLibraryObjectsHintsEntries = expectAllLibraryObjectsHintsEntries;71 exports.expectHintsEntries = expectHintsEntries;72 exports.waitForHints = waitForHints;73 exports.selectHint = selectHint;74 exports.expectNoHints = expectNoHints;75 exports.SAP_LIBRARY_API_OBJECT_NAMES = SAP_LIBRARY_API_OBJECT_NAMES;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var hintList = root.hintList;2hintList.addHint("hint 1");3hintList.addHint("hint 2");4hintList.addHint("hint 3");5hintList.addHint("hint 4");6hintList.addHint("hint 5");7var hintList = root.hintList;8hintList.addHint("hint 6");9hintList.addHint("hint 7");10hintList.addHint("hint 8");11hintList.addHint("hint 9");12hintList.addHint("hint 10");13var hintList = root.hintList;14hintList.addHint("hint 11");15hintList.addHint("hint 12");16hintList.addHint("hint 13");17hintList.addHint("hint 14");18hintList.addHint("hint 15");19var hintList = root.hintList;20hintList.addHint("hint 16");21hintList.addHint("hint 17");22hintList.addHint("hint 18");23hintList.addHint("hint 19");24hintList.addHint("hint 20");25var hintList = root.hintList;26hintList.addHint("hint 21");27hintList.addHint("hint 22");28hintList.addHint("hint 23");29hintList.addHint("hint 24");30hintList.addHint("hint 25");31var hintList = root.hintList;32hintList.addHint("hint 26");33hintList.addHint("hint 27");34hintList.addHint("hint 28");35hintList.addHint("hint 29");36hintList.addHint("hint 30");37var hintList = root.hintList;38hintList.addHint("hint 31");39hintList.addHint("hint 32");40hintList.addHint("hint 33");41hintList.addHint("hint 34");42hintList.addHint("hint 35");43var hintList = root.hintList;44hintList.addHint("hint 36");45hintList.addHint("hint 37");46hintList.addHint("hint 38");47hintList.addHint("hint

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = getRoot();2var hintList = root.hintList;3var hintList = root.hintList("test");4var hintList = root.hintList("test", "test");5var hintList = root.hintList("test", "test", "test");6var hintList = root.hintList("test", "test", "test", "test");7var hintList = root.hintList("test", "test", "test", "test", "test");8var root = getRoot();9var hintList = root.hintList;10var hintList = root.hintList("test");11var hintList = root.hintList("test", "test");12var hintList = root.hintList("test", "test", "test");13var hintList = root.hintList("test", "test", "test", "test");14var hintList = root.hintList("test", "test", "test", "test", "test");15var root = getRoot();16var hintList = root.hintList;17var hintList = root.hintList("test");18var hintList = root.hintList("test", "test");19var hintList = root.hintList("test", "test", "test");20var hintList = root.hintList("test", "test", "test", "test");21var hintList = root.hintList("test", "test", "test", "test", "test");22var root = getRoot();23var hintList = root.hintList;24var hintList = root.hintList("test");25var hintList = root.hintList("test", "test");26var hintList = root.hintList("test", "test", "test");27var hintList = root.hintList("test", "test", "test", "test");28var hintList = root.hintList("test", "test", "test", "test", "test");29var root = getRoot();30var hintList = root.hintList;31var hintList = root.hintList("test");

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Root } from "./root.js";2const root = new Root();3root.hintList();4export class Root {5 constructor() {6 this.hintList();7 }8 hintList() {9 console.log("hintList method of root class");10 }11}12export class HintList {13 constructor() {14 this.hintList();15 }16 hintList() {17 console.log("hintList method of hintList class");18 }19}

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = this.getRoot();2var hints = root.hintList("hello");3for (var i = 0; i < hints.length; i++) {4 console.log(hints[i]);5}6>>> root.hintList("hello")

Full Screen

Using AI Code Generation

copy

Full Screen

1var hintList = root.hintList;2var hint = hintList.getHint("testHint");3hint.showHint();4var hint = {5 showHint : function() {6 }7};8var hint = {9 showHint : function() {10 }11};12var hint = {13 showHint : function() {14 }15};16var hint = {17 showHint : function() {18 }19};20var hint = {21 showHint : function() {22 }23};24var hint = {25 showHint : function() {26 }27};28var hint = {29 showHint : function() {30 }31};32var hint = {33 showHint : function() {34 }35};36var hint = {37 showHint : function() {38 }39};40var hint = {41 showHint : function() {42 }43};44var hint = {45 showHint : function() {46 }47};48var hint = {49 showHint : function() {50 }51};

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = this.getRoot();2var hintList = root.hintList;3var hint = hintList.getHint("hint1");4hint.setText("Hello World");5hint.show();6var root = this.getRoot();7var hintList = root.hintList;8var hint1 = hintList.getHint("hint1");9var hint2 = hintList.getHint("hint2");10var hint3 = hintList.getHint("hint3");11hint1.setText("Hello World");12hint2.setText("Hello World");13hint3.setText("Hello World");14hint1.show();15hint2.show();16hint3.show();17var root = this.getRoot();18var hintList = root.hintList;19var hint1 = hintList.getHint("hint1");20var hint2 = hintList.getHint("hint2");21var hint3 = hintList.getHint("hint3");22hint1.setText("Hello World");23hint2.setText("Hello World");24hint3.setText("Hello World");25hint1.show();26hint2.show();27hint3.show();28var root = this.getRoot();29var hintList = root.hintList;30var hint1 = hintList.getHint("hint1");31var hint2 = hintList.getHint("hint2");32var hint3 = hintList.getHint("hint3");33hint1.setText("Hello World");34hint2.setText("Hello World");35hint3.setText("Hello World");36hint1.show();37hint2.show();38hint3.show();39var root = this.getRoot();40var hintList = root.hintList;41var hint1 = hintList.getHint("hint1");42var hint2 = hintList.getHint("hint2");

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful