Best JavaScript code snippet using testcafe
bootstrap-tagautocomplete.js
Source:bootstrap-tagautocomplete.js
...35 source: ['@aa', '@ab', '@ac']36 })37 , tagautocomplete = $div.data('tagautocomplete')38 $div.text('@a')39 setCaretPosition($div[0], 2)40 tagautocomplete.lookup()41 ok(tagautocomplete.$menu.is(":visible"), 'tagautocomplete is visible')42 equals(tagautocomplete.$menu.find('li').length, 3, 'has 3 items in menu')43 equals(tagautocomplete.$menu.find('.active').length, 1, 'one item is active')44 $div.remove()45 tagautocomplete.$menu.remove()46 })47 test("should place menu in body and positioned absolute with left and top", function () {48 var $div = $('<div contenteditable="true" />')49 .appendTo("#qunit-fixture") //inside qunit fixture to test that the menu will still be outside.50 .tagautocomplete({51 source: ['@aa', '@ab', '@ac']52 })53 , tagautocomplete = $div.data('tagautocomplete')54 $div.text('@a')55 setCaretPosition($div[0], 2)56 tagautocomplete.lookup()57 ok(tagautocomplete.$menu.is(":visible"), 'tagautocomplete is visible')58 ok($("body > .typeahead.dropdown-menu").length, 'inside the body')59 ok(!$("#qunit-fixture > .typeahead.dropdown-menu").length, 'not found in parent')60 equals(tagautocomplete.$menu[0].style.position, 'absolute', 'absolute position')61 ok(tagautocomplete.$menu[0].style.left, 'has left set')62 ok(tagautocomplete.$menu[0].style.top, 'has top set')63 64 $div.remove()65 tagautocomplete.$menu.remove()66 })67 test("should accept data source via synchronous function", function () {68 var $div = $('<div contenteditable="true" />').tagautocomplete({69 source: function () {70 return ['@aa', '@ab', '@ac']71 }72 }).appendTo('body')73 , tagautocomplete = $div.data('tagautocomplete')74 $div.text('@a')75 setCaretPosition($div[0], 2)76 tagautocomplete.lookup()77 ok(tagautocomplete.$menu.is(":visible"), 'tagautocomplete is visible')78 equals(tagautocomplete.$menu.find('li').length, 3, 'has 3 items in menu')79 equals(tagautocomplete.$menu.find('.active').length, 1, 'one item is active')80 $div.remove()81 tagautocomplete.$menu.remove()82 })83 test("should accept data source via asynchronous function", function () {84 var $div = $('<div contenteditable="true" />').tagautocomplete({85 source: function (query, process) {86 process(['@aa', '@ab', '@ac'])87 }88 }).appendTo('body')89 , tagautocomplete = $div.data('tagautocomplete')90 $div.text('@a')91 setCaretPosition($div[0], 2)92 tagautocomplete.lookup()93 ok(tagautocomplete.$menu.is(":visible"), 'tagautocomplete is visible')94 equals(tagautocomplete.$menu.find('li').length, 3, 'has 3 items in menu')95 equals(tagautocomplete.$menu.find('.active').length, 1, 'one item is active')96 $div.remove()97 tagautocomplete.$menu.remove()98 })99 test("should hide menu when query entered", function () {100 stop()101 var $div = $('<div contenteditable="true" />').tagautocomplete({102 source: ['@aa', '@ab', '@ac']103 }).appendTo('body')104 , tagautocomplete = $div.data('tagautocomplete')105 $div.text('@a')106 setCaretPosition($div[0], 2)107 tagautocomplete.lookup()108 ok(tagautocomplete.$menu.is(":visible"), 'tagautocomplete is visible')109 equals(tagautocomplete.$menu.find('li').length, 3, 'has 3 items in menu')110 equals(tagautocomplete.$menu.find('.active').length, 1, 'one item is active')111 $div.blur()112 setTimeout(function () {113 ok(!tagautocomplete.$menu.is(":visible"), "tagautocomplete is no longer visible")114 start()115 }, 200)116 $div.remove()117 tagautocomplete.$menu.remove()118 })119 test("should set next item when down arrow is pressed", function () {120 var $div = $('<div contenteditable="true" />').tagautocomplete({121 source: ['@aa', '@ab', '@ac']122 }).appendTo('body')123 , tagautocomplete = $div.data('tagautocomplete')124 $div.text('@a')125 setCaretPosition($div[0], 2)126 tagautocomplete.lookup()127 ok(tagautocomplete.$menu.is(":visible"), 'tagautocomplete is visible')128 equals(tagautocomplete.$menu.find('li').length, 3, 'has 3 items in menu')129 equals(tagautocomplete.$menu.find('.active').length, 1, 'one item is active')130 ok(tagautocomplete.$menu.find('li').first().hasClass('active'), "first item is active")131 // simulate entire key pressing event132 $div.trigger({133 type: 'keydown'134 , keyCode: 40135 })136 .trigger({137 type: 'keypress'138 , keyCode: 40139 })140 .trigger({141 type: 'keyup'142 , keyCode: 40143 })144 ok(tagautocomplete.$menu.find('li').first().next().hasClass('active'), "second item is active")145 $div.trigger({146 type: 'keydown'147 , keyCode: 38148 })149 .trigger({150 type: 'keypress'151 , keyCode: 38152 })153 .trigger({154 type: 'keyup'155 , keyCode: 38156 })157 ok(tagautocomplete.$menu.find('li').first().hasClass('active'), "first item is active")158 $div.remove()159 tagautocomplete.$menu.remove()160 })161 test("should set div text to selected item", function () {162 var $div = $('<div contenteditable="true" />').tagautocomplete({163 source: ['@aa', '@ab', '@ac']164 }).appendTo('body')165 , tagautocomplete = $div.data('tagautocomplete')166 , changed = false167 , focus = false168 , blur = false169 $div.text('@a')170 setCaretPosition($div[0], 2)171 tagautocomplete.lookup()172 $div.change(function() { changed = true });173 $div.focus(function() { focus = true; blur = false });174 $div.blur(function() { blur = true; focus = false });175 $(tagautocomplete.$menu.find('li')[2]).mouseover().click()176 equals($div.text(), '@ac ', 'div text was correctly set')177 ok(!tagautocomplete.$menu.is(':visible'), 'the menu was hidden')178 ok(changed, 'a change event was fired')179 ok(focus && !blur, 'focus is still set')180 $div.remove()181 tagautocomplete.$menu.remove()182 })183 test("should start querying when minLength is met", function () {184 var $div = $('<div contenteditable="true" />').tagautocomplete({185 source: ['@aaaa', '@aaab', '@aaac'],186 minLength: 3187 }).appendTo('body')188 , tagautocomplete = $div.data('tagautocomplete')189 $div.text('@a')190 setCaretPosition($div[0], 2)191 tagautocomplete.lookup()192 equals(tagautocomplete.$menu.find('li').length, 0, 'has 0 items in menu')193 $div.text('@aa')194 setCaretPosition($div[0], 3)195 tagautocomplete.lookup()196 equals(tagautocomplete.$menu.find('li').length, 3, 'has 3 items in menu')197 $div.remove()198 tagautocomplete.$menu.remove()199 })200 test("should match the words after the characters ' @'", function () {201 var $div = $('<div contenteditable="true" />').tagautocomplete({202 source: ['@aa', '@bb', '@cc']203 }).appendTo('body')204 , tagautocomplete = $div.data('tagautocomplete')205 206 $div.text('s a')207 setCaretPosition($div[0], 3)208 tagautocomplete.lookup()209 equals(tagautocomplete.extractor(), '', 'has no characters to match')210 $div.text('s @a')211 setCaretPosition($div[0], 4)212 tagautocomplete.lookup()213 equals(tagautocomplete.extractor(), '@a', 'has characters to match')214 $div.remove()215 tagautocomplete.$menu.remove()216 })217 test("should match the words just before the cursor position", function () {218 var $div = $('<div contenteditable="true" />').tagautocomplete({219 source: ['@aa', '@bb', '@cc']220 }).appendTo('body')221 , tagautocomplete = $div.data('tagautocomplete')222 223 $div.text('s @b @a')224 setCaretPosition($div[0], 4)225 tagautocomplete.lookup()226 equals(tagautocomplete.extractor(), '@b', 'compared with where the caret is')227 $div.remove()228 tagautocomplete.$menu.remove()229 })230 test("should match when it starts with @", function () {231 var $div = $('<div contenteditable="true" />').tagautocomplete({232 source: ['@aaa', '@bbb', '@ccc']233 }).appendTo('body')234 , tagautocomplete = $div.data('tagautocomplete')235 236 $div.text('@bb a')237 setCaretPosition($div[0], 3)238 tagautocomplete.lookup()239 equals(tagautocomplete.extractor(), '@bb', '@bb returned')240 $div.remove()241 tagautocomplete.$menu.remove()242 })243 test("should accept matches for letters, numbers, underscore and dashes", function () {244 var $div = $('<div contenteditable="true" />').tagautocomplete({245 source: ['@aaa', '@b_-9', '@ccc']246 }).appendTo('body')247 , tagautocomplete = $div.data('tagautocomplete')248 249 $div.text('@b_-9 a')250 setCaretPosition($div[0], 5)251 tagautocomplete.lookup()252 equals(tagautocomplete.extractor(), '@b_-9', '@b_-9 returned')253 $div.remove()254 tagautocomplete.$menu.remove()255 })256 test("should be case insensitive and downcase for matching", function () {257 var $div = $('<div contenteditable="true" />').tagautocomplete({258 source: ['@aaa', '@bbb', '@ccc']259 }).appendTo('body')260 , tagautocomplete = $div.data('tagautocomplete')261 262 $div.text('ss @A')263 setCaretPosition($div[0], 5)264 tagautocomplete.lookup()265 equals(tagautocomplete.extractor(), '@a', '@a returned')266 $div.remove()267 tagautocomplete.$menu.remove()268 })269 test("can override @ with another character", function () {270 var $div = $('<div contenteditable="true" />').tagautocomplete({271 source: ['#aaa', '#bbb', '#ccc'],272 character: '#'273 }).appendTo('body')274 , tagautocomplete = $div.data('tagautocomplete')275 276 $div.text('#bb a')277 setCaretPosition($div[0], 3)278 tagautocomplete.lookup()279 equals(tagautocomplete.extractor(), '#bb', 'matched characters after #')280 $div.remove()281 tagautocomplete.$menu.remove()282 })283 test("can characters to @", function () {284 var $div = $('<div contenteditable="true" />').tagautocomplete({285 source: ['#aaa', '#bbb', '#ccc', '@abc'],286 character: '@#'287 }).appendTo('body')288 , tagautocomplete = $div.data('tagautocomplete')289 290 $div.text('#bb a')291 setCaretPosition($div[0], 3)292 tagautocomplete.lookup()293 equals(tagautocomplete.extractor(), '#bb', 'matched characters after #')294 $div.text('#bb @a')295 setCaretPosition($div[0], 6)296 tagautocomplete.lookup()297 equals(tagautocomplete.extractor(), '@a', 'matched characters after @')298 $div.remove()299 tagautocomplete.$menu.remove()300 })301 test("should highlight the matching characters", function () {302 var $div = $('<div contenteditable="true" />').tagautocomplete({303 source: ['@bbc', '@bbb', '@ccc']304 }).appendTo('body')305 , tagautocomplete = $div.data('tagautocomplete')306 307 $div.text('s @b a')308 setCaretPosition($div[0], 4)309 tagautocomplete.lookup()310 311 ok(tagautocomplete.$menu.is(":visible"), 'tagautocomplete is visible')312 equals(tagautocomplete.$menu.find('li').length, 2, 'has 2 items in menu')313 equals(tagautocomplete.$menu.find('.active').length, 1, 'one item is active')314 equals(tagautocomplete.$menu.find('.active strong').text(), '@b', '@b is highlighted')315 $div.remove()316 tagautocomplete.$menu.remove()317 })318 test("should replace only the one node (with mouse click)", function () {319 var $div = $('<div contenteditable="true" />').tagautocomplete({320 source: ['@bbc', '@bbb', '@ccc'],321 after: function(){322 passed_after = true323 }324 }).appendTo('body')325 , tagautocomplete = $div.data('tagautocomplete')326 327 $div.text('s @b a @b')328 setCaretPosition($div[0], 4)329 tagautocomplete.lookup()330 331 $div.change(function() { changed = true });332 $div.focus(function() { focused = true; blured = false });333 $div.blur(function() { blured = true; focused = false });334 $(tagautocomplete.$menu.find('li')[1]).mouseover().click()335 equals($div.text(), 's @bbb a @b', 'div text was correctly set')336 ok(!tagautocomplete.$menu.is(':visible'), 'the menu was hidden')337 ok(changed, 'a change event was fired')338 ok(focused && !blured, 'focus is still set')339 ok(passed_after, 'the passed after method was fired')340 equals(getCaretPosition($div[0]), 7, 'caret position correctly set')341 $div.remove()342 tagautocomplete.$menu.remove()343 })344 test("should replace only the one node (with keypress)", function () {345 var $div = $('<div contenteditable="true" />').tagautocomplete({346 source: ['@bbcd', '@bbb', '@ccc'],347 after: function(){348 passed_after = true349 }350 }).appendTo('body')351 , tagautocomplete = $div.data('tagautocomplete')352 353 $div.text('s @b a @b')354 setCaretPosition($div[0], 4)355 tagautocomplete.lookup()356 357 // simulate entire key pressing event of ENTER358 $div.trigger({359 type: 'keydown'360 , keyCode: 13361 })362 .trigger({363 type: 'keypress'364 , keyCode: 13365 })366 .trigger({367 type: 'keyup'368 , keyCode: 13...
simple.js
Source:simple.js
...108 textDom.focus();109 }110 this.$set(this, 'currentValue', textDom.value);111 },112 setCaretPosition(position) {113 // 设置å
æ ä½ç½®114 const textDom = this.$refs.textarea;115 if (textDom.setSelectionRange) {116 textDom.focus();117 textDom.setSelectionRange(position, position);118 } else if (textDom.createTextRange) {119 let range = textDom.createTextRange();120 range.collapse(true);121 range.moveEnd('character', position);122 range.moveStart('character', position);123 range.select();124 }125 },126 insertQuote() {127 // å¼ç¨128 this.insertContent('\n> ');129 },130 insertUl() {131 // æ éå表132 this.insertContent('- ');133 },134 insertOl() {135 // æåºå表136 this.insertContent('1. ');137 },138 insertFinished() {139 // å·²å®æå表140 this.insertContent('- [x] ');141 },142 insertNotFinished() {143 // æªå®æå表144 this.insertContent('- [ ] ');145 },146 insertCode() {147 // æå
¥code148 const point = this.getCursortPosition();149 const lastChart = this.currentValue.substring(point - 1, point);150 this.insertContent('\n```\n\n```');151 if (lastChart !== '\n' && this.currentValue !== '') {152 this.setCaretPosition(point + 5);153 } else {154 this.setCaretPosition(point + 5);155 }156 },157 insertStrong() {158 // ç²ä½159 const point = this.getCursortPosition();160 const lastChart = this.currentValue.substring(point - 1, point);161 this.insertContent('****');162 if (lastChart !== '\n' && this.currentValue !== '') {163 this.setCaretPosition(point + 2);164 } else {165 this.setCaretPosition(point + 2);166 }167 },168 insertItalic() {169 // æä½170 const point = this.getCursortPosition();171 const lastChart = this.currentValue.substring(point - 1, point);172 this.insertContent('**');173 if (lastChart !== '\n' && this.currentValue !== '') {174 this.setCaretPosition(point + 1);175 } else {176 this.setCaretPosition(point + 1);177 }178 },179 insertBg() {180 // èæ¯è²181 const point = this.getCursortPosition();182 const lastChart = this.currentValue.substring(point - 1, point);183 this.insertContent('====');184 if (lastChart !== '\n' && this.currentValue !== '') {185 this.setCaretPosition(point + 5);186 } else {187 this.setCaretPosition(point + 5);188 }189 },190 insertUnderline() {191 // ä¸å线192 const point = this.getCursortPosition();193 const lastChart = this.currentValue.substring(point - 1, point);194 this.insertContent('<u></u>');195 if (lastChart !== '\n' && this.currentValue !== '') {196 this.setCaretPosition(point + 3);197 } else {198 this.setCaretPosition(point + 5);199 }200 },201 insertOverline() {202 // overline203 const point = this.getCursortPosition();204 const lastChart = this.currentValue.substring(point - 1, point);205 this.insertContent('~~~~');206 if (lastChart !== '\n' && this.currentValue !== '') {207 this.setCaretPosition(point + 2);208 } else {209 this.setCaretPosition(point + 2);210 }211 },212 insertTitle(level) {213 // æå
¥æ é¢214 const titleLevel = {215 1: '# ',216 2: '## ',217 3: '### ',218 4: '#### ',219 5: '##### ',220 6: '###### '221 };222 this.insertContent(titleLevel[level]);223 },...
browser_dbg_conditional-breakpoints-02.js
Source:browser_dbg_conditional-breakpoints-02.js
...30 return actions.addBreakpoint({ actor: gSources.selectedValue, line: 18 });31 }32 function addBreakpoint2() {33 let finished = waitForDispatch(gPanel, constants.ADD_BREAKPOINT);34 setCaretPosition(19);35 gSources._onCmdAddBreakpoint();36 return finished;37 }38 function modBreakpoint2() {39 setCaretPosition(19);40 let popupShown = waitForDebuggerEvents(gPanel, CONDITIONAL_POPUP_SHOWN);41 gSources._onCmdAddConditionalBreakpoint();42 return popupShown;43 }44 function* addBreakpoint3() {45 let finished = waitForDispatch(gPanel, constants.ADD_BREAKPOINT);46 let popupShown = waitForDebuggerEvents(gPanel, CONDITIONAL_POPUP_SHOWN);47 setCaretPosition(20);48 gSources._onCmdAddConditionalBreakpoint();49 yield finished;50 yield popupShown;51 }52 function* modBreakpoint3() {53 setCaretPosition(20);54 let popupShown = waitForDebuggerEvents(gPanel, CONDITIONAL_POPUP_SHOWN);55 gSources._onCmdAddConditionalBreakpoint();56 yield popupShown;57 typeText(gSources._cbTextbox, "bamboocha");58 let finished = waitForDispatch(gPanel, constants.SET_BREAKPOINT_CONDITION);59 EventUtils.sendKey("RETURN", gDebugger);60 yield finished;61 }62 function addBreakpoint4() {63 let finished = waitForDispatch(gPanel, constants.ADD_BREAKPOINT);64 setCaretPosition(21);65 gSources._onCmdAddBreakpoint();66 return finished;67 }68 function delBreakpoint4() {69 let finished = waitForDispatch(gPanel, constants.REMOVE_BREAKPOINT);70 setCaretPosition(21);71 gSources._onCmdAddBreakpoint();72 return finished;73 }74 function testBreakpoint(aLine, aPopupVisible, aConditionalExpression) {75 const source = queries.getSelectedSource(getState());76 ok(source,77 "There should be a selected item in the sources pane.");78 const bp = queries.getBreakpoint(getState(), {79 actor: source.actor,80 line: aLine81 });82 const bpItem = gSources._getBreakpoint(bp);83 ok(bp, "There should be a breakpoint.");84 ok(bpItem, "There should be a breakpoint in the sources pane.");85 is(bp.location.actor, source.actor,86 "The breakpoint on line " + aLine + " wasn't added on the correct source.");87 is(bp.location.line, aLine,88 "The breakpoint on line " + aLine + " wasn't found.");89 is(!!bp.disabled, false,90 "The breakpoint on line " + aLine + " should be enabled.");91 is(gSources._conditionalPopupVisible, aPopupVisible,92 "The breakpoint on line " + aLine + " should have a correct popup state (2).");93 is(bp.condition, aConditionalExpression,94 "The breakpoint on line " + aLine + " should have a correct conditional expression.");95 }96 function testNoBreakpoint(aLine) {97 let selectedActor = gSources.selectedValue;98 let selectedBreakpoint = gSources._selectedBreakpoint;99 ok(selectedActor,100 "There should be a selected item in the sources pane for line " + aLine + ".");101 ok(!selectedBreakpoint,102 "There should be no selected brekapoint in the sources pane for line " + aLine + ".");103 ok(isCaretPos(gPanel, aLine),104 "The editor caret position is not properly set.");105 }106 function setCaretPosition(aLine) {107 gEditor.setCursor({ line: aLine - 1, ch: 0 });108 }109 function clickOnBreakpoint(aIndex) {110 EventUtils.sendMouseEvent({ type: "click" },111 gDebugger.document.querySelectorAll(".dbg-breakpoint")[aIndex],112 gDebugger);113 }114 function waitForConditionUpdate() {115 // This will close the popup and send another request to update116 // the condition117 gSources._hideConditionalPopup();118 return waitForDispatch(gPanel, constants.SET_BREAKPOINT_CONDITION);119 }120 Task.spawn(function* () {121 let onCaretUpdated = waitForCaretAndScopes(gPanel, 17);122 callInTab(gTab, "ermahgerd");123 yield onCaretUpdated;124 is(gDebugger.gThreadClient.state, "paused",125 "Should only be getting stack frames while paused.");126 is(queries.getSourceCount(getState()), 1,127 "Found the expected number of sources.");128 is(gEditor.getText().indexOf("ermahgerd"), 253,129 "The correct source was loaded initially.");130 is(gSources.selectedValue, gSources.values[0],131 "The correct source is selected.");132 is(queries.getBreakpoints(getState()).length, 0,133 "No breakpoints currently added.");134 yield addBreakpoint1();135 testBreakpoint(18, false, undefined);136 yield addBreakpoint2();137 testBreakpoint(19, false, undefined);138 yield modBreakpoint2();139 testBreakpoint(19, true, undefined);140 yield waitForConditionUpdate();141 yield addBreakpoint3();142 testBreakpoint(20, true, "");143 yield waitForConditionUpdate();144 yield modBreakpoint3();145 testBreakpoint(20, false, "bamboocha");146 yield addBreakpoint4();147 testBreakpoint(21, false, undefined);148 yield delBreakpoint4();149 setCaretPosition(18);150 is(gSources._selectedBreakpoint.location.line, 18,151 "The selected breakpoint is line 18");152 yield testBreakpoint(18, false, undefined);153 setCaretPosition(19);154 is(gSources._selectedBreakpoint.location.line, 19,155 "The selected breakpoint is line 19");156 yield testBreakpoint(19, false, "");157 setCaretPosition(20);158 is(gSources._selectedBreakpoint.location.line, 20,159 "The selected breakpoint is line 20");160 yield testBreakpoint(20, false, "bamboocha");161 setCaretPosition(17);162 yield testNoBreakpoint(17);163 setCaretPosition(21);164 yield testNoBreakpoint(21);165 clickOnBreakpoint(0);166 is(gSources._selectedBreakpoint.location.line, 18,167 "The selected breakpoint is line 18");168 yield testBreakpoint(18, false, undefined);169 clickOnBreakpoint(1);170 is(gSources._selectedBreakpoint.location.line, 19,171 "The selected breakpoint is line 19");172 yield testBreakpoint(19, false, "");173 clickOnBreakpoint(2);174 is(gSources._selectedBreakpoint.location.line, 20,175 "The selected breakpoint is line 20");176 testBreakpoint(20, true, "bamboocha");177 // Reset traits back to default value...
browser_dbg_server-conditional-bp-02.js
Source:browser_dbg_server-conditional-bp-02.js
...26 return actions.addBreakpoint({ actor: gSources.selectedValue, line: 18 });27 }28 function addBreakpoint2() {29 let finished = waitForDispatch(gPanel, constants.ADD_BREAKPOINT);30 setCaretPosition(19);31 gSources._onCmdAddBreakpoint();32 return finished;33 }34 function modBreakpoint2() {35 setCaretPosition(19);36 let popupShown = waitForDebuggerEvents(gPanel, CONDITIONAL_POPUP_SHOWN);37 gSources._onCmdAddConditionalBreakpoint();38 return popupShown;39 }40 function* addBreakpoint3() {41 let finished = waitForDispatch(gPanel, constants.ADD_BREAKPOINT);42 let popupShown = waitForDebuggerEvents(gPanel, CONDITIONAL_POPUP_SHOWN);43 setCaretPosition(20);44 gSources._onCmdAddConditionalBreakpoint();45 yield finished;46 yield popupShown;47 }48 function* modBreakpoint3() {49 setCaretPosition(20);50 let popupShown = waitForDebuggerEvents(gPanel, CONDITIONAL_POPUP_SHOWN);51 gSources._onCmdAddConditionalBreakpoint();52 yield popupShown;53 typeText(gSources._cbTextbox, "bamboocha");54 let finished = waitForDispatch(gPanel, constants.SET_BREAKPOINT_CONDITION);55 EventUtils.sendKey("RETURN", gDebugger);56 yield finished;57 }58 function addBreakpoint4() {59 let finished = waitForDispatch(gPanel, constants.ADD_BREAKPOINT);60 setCaretPosition(21);61 gSources._onCmdAddBreakpoint();62 return finished;63 }64 function delBreakpoint4() {65 let finished = waitForDispatch(gPanel, constants.REMOVE_BREAKPOINT);66 setCaretPosition(21);67 gSources._onCmdAddBreakpoint();68 return finished;69 }70 function testBreakpoint(aLine, aPopupVisible, aConditionalExpression) {71 const source = queries.getSelectedSource(getState());72 ok(source,73 "There should be a selected item in the sources pane.");74 const bp = queries.getBreakpoint(getState(), {75 actor: source.actor,76 line: aLine77 });78 const bpItem = gSources._getBreakpoint(bp);79 ok(bp, "There should be a breakpoint.");80 ok(bpItem, "There should be a breakpoint in the sources pane.");81 is(bp.location.actor, source.actor,82 "The breakpoint on line " + aLine + " wasn't added on the correct source.");83 is(bp.location.line, aLine,84 "The breakpoint on line " + aLine + " wasn't found.");85 is(!!bp.disabled, false,86 "The breakpoint on line " + aLine + " should be enabled.");87 is(gSources._conditionalPopupVisible, aPopupVisible,88 "The breakpoint on line " + aLine + " should have a correct popup state (2).");89 is(bp.condition, aConditionalExpression,90 "The breakpoint on line " + aLine + " should have a correct conditional expression.");91 }92 function testNoBreakpoint(aLine) {93 let selectedActor = gSources.selectedValue;94 let selectedBreakpoint = gSources._selectedBreakpoint;95 ok(selectedActor,96 "There should be a selected item in the sources pane for line " + aLine + ".");97 ok(!selectedBreakpoint,98 "There should be no selected brekapoint in the sources pane for line " + aLine + ".");99 ok(isCaretPos(gPanel, aLine),100 "The editor caret position is not properly set.");101 }102 function setCaretPosition(aLine) {103 gEditor.setCursor({ line: aLine - 1, ch: 0 });104 }105 function clickOnBreakpoint(aIndex) {106 EventUtils.sendMouseEvent({ type: "click" },107 gDebugger.document.querySelectorAll(".dbg-breakpoint")[aIndex],108 gDebugger);109 }110 function waitForConditionUpdate() {111 // This will close the popup and send another request to update112 // the condition113 gSources._hideConditionalPopup();114 return waitForDispatch(gPanel, constants.SET_BREAKPOINT_CONDITION);115 }116 Task.spawn(function* () {117 let onCaretUpdated = waitForCaretAndScopes(gPanel, 17);118 callInTab(gTab, "ermahgerd");119 yield onCaretUpdated;120 is(gDebugger.gThreadClient.state, "paused",121 "Should only be getting stack frames while paused.");122 is(queries.getSourceCount(getState()), 1,123 "Found the expected number of sources.");124 is(gEditor.getText().indexOf("ermahgerd"), 253,125 "The correct source was loaded initially.");126 is(gSources.selectedValue, gSources.values[0],127 "The correct source is selected.");128 is(queries.getBreakpoints(getState()).length, 0,129 "No breakpoints currently added.");130 yield addBreakpoint1();131 testBreakpoint(18, false, undefined);132 yield addBreakpoint2();133 testBreakpoint(19, false, undefined);134 yield modBreakpoint2();135 testBreakpoint(19, true, undefined);136 yield waitForConditionUpdate();137 yield addBreakpoint3();138 testBreakpoint(20, true, "");139 yield waitForConditionUpdate();140 yield modBreakpoint3();141 testBreakpoint(20, false, "bamboocha");142 yield addBreakpoint4();143 testBreakpoint(21, false, undefined);144 yield delBreakpoint4();145 setCaretPosition(18);146 is(gSources._selectedBreakpoint.location.line, 18,147 "The selected breakpoint is line 18");148 yield testBreakpoint(18, false, undefined);149 setCaretPosition(19);150 is(gSources._selectedBreakpoint.location.line, 19,151 "The selected breakpoint is line 19");152 yield testBreakpoint(19, false, "");153 setCaretPosition(20);154 is(gSources._selectedBreakpoint.location.line, 20,155 "The selected breakpoint is line 20");156 yield testBreakpoint(20, false, "bamboocha");157 setCaretPosition(17);158 yield testNoBreakpoint(17);159 setCaretPosition(21);160 yield testNoBreakpoint(21);161 clickOnBreakpoint(0);162 is(gSources._selectedBreakpoint.location.line, 18,163 "The selected breakpoint is line 18");164 yield testBreakpoint(18, false, undefined);165 clickOnBreakpoint(1);166 is(gSources._selectedBreakpoint.location.line, 19,167 "The selected breakpoint is line 19");168 yield testBreakpoint(19, false, "");169 clickOnBreakpoint(2);170 is(gSources._selectedBreakpoint.location.line, 20,171 "The selected breakpoint is line 20");172 testBreakpoint(20, true, "bamboocha");173 resumeDebuggerThenCloseAndFinish(gPanel);...
jquery.maskedinput.js
Source:jquery.maskedinput.js
...39 res.end = res.begin + range.text.length;40 }41 return res;42 };43 function setCaretPosition(ctl, pos){44 if(ctl.setSelectionRange){45 ctl.focus();46 ctl.setSelectionRange(pos,pos);47 }else if (ctl.createTextRange){48 var range = ctl.createTextRange();49 range.collapse(true);50 range.moveEnd('character', pos);51 range.moveStart('character', pos);52 range.select();53 }54 };55 56 //Predefined character definitions57 var charMap={58 '9':"[0-9]",59 'a':"[A-Za-z]",60 '*':"[A-Za-z0-9]"61 };62 63 //Helper method to inject character definitions64 $.mask={65 addPlaceholder : function(c,r){66 charMap[c]=r;67 }68 };69 70 //Main Method71 $.fn.mask = function(mask,settings) { 72 settings = $.extend({73 placeholder: "_",74 completed: null75 }, settings);76 77 //Build Regex for format validation78 var reString="^"; 79 for(var i=0;i<mask.length;i++)80 reString+=(charMap[mask.charAt(i)] || ("\\"+mask.charAt(i))); 81 reString+="$";82 var re = new RegExp(reString);83 return this.each(function(){ 84 var input=$(this);85 var buffer=new Array(mask.length);86 var locked=new Array(mask.length); 87 //Build buffer layout from mask88 for(var i=0;i<mask.length;i++){89 locked[i]=charMap[mask.charAt(i)]==null;90 buffer[i]=locked[i]?mask.charAt(i):settings.placeholder; 91 }92 93 /*Event Bindings*/94 input.focus(function(){ 95 checkVal();96 writeBuffer();97 setCaretPosition(this,0); 98 });99 input.blur(checkVal);100 101 //Paste events for IE and Mozilla thanks to Kristinn Sigmundsson102 if ($.browser.msie) 103 this.onpaste= function(){setTimeout(checkVal,0);}; 104 else if ($.browser.mozilla)105 this.addEventListener('input',checkVal,false);106 107 var ignore=false; //Variable for ignoring control keys108 109 input.keydown(function(e){110 var pos=getCaretPosition(this); 111 var k = e.keyCode;112 ignore=(k < 16 || (k > 16 && k < 32 ) || (k > 32 && k < 41));113 114 //delete selection before proceeding115 if((pos.begin-pos.end)!=0 && (!ignore || k==8 || k==46)){116 clearBuffer(pos.begin,pos.end);117 } 118 //backspace and delete get special treatment119 if(k==8){//backspace 120 while(pos.begin-->=0){121 if(!locked[pos.begin]){ 122 buffer[pos.begin]=settings.placeholder;123 if($.browser.opera){124 //Opera won't let you cancel the backspace, so we'll let it backspace over a dummy character. 125 writeBuffer(pos.begin);126 setCaretPosition(this,pos.begin+1);127 }else{128 writeBuffer();129 setCaretPosition(this,pos.begin);130 } 131 return false; 132 }133 } 134 }else if(k==46){//delete135 clearBuffer(pos.begin,pos.begin+1);136 writeBuffer();137 setCaretPosition(this,pos.begin);138 return false;139 }else if (k==27){140 clearBuffer(0,mask.length);141 writeBuffer();142 setCaretPosition(this,0);143 return false;144 }145 146 });147 input.keypress(function(e){ 148 if(ignore){149 ignore=false;150 return;151 }152 e=e||window.event;153 var k=e.charCode||e.keyCode||e.which;154 var pos=getCaretPosition(this); 155 var caretPos=pos.begin; 156 157 if(e.ctrlKey || e.altKey){//Ignore158 return true;159 }else if ((k>=41 && k<=122) ||k==32 || k>186){//typeable characters160 while(pos.begin<mask.length){ 161 var reString=charMap[mask.charAt(pos.begin)];162 var match;163 if(reString){164 var reChar=new RegExp(reString);165 match=String.fromCharCode(k).match(reChar);166 }else{//we're on a mask char, go forward and try again167 pos.begin+=1;168 pos.end=pos.begin;169 caretPos+=1;170 continue;171 }172 if(match)173 buffer[pos.begin]=String.fromCharCode(k);174 else175 return false;//reject char176 while(++caretPos<mask.length){//seek forward to next typable position177 if(!locked[caretPos]) 178 break; 179 }180 break;181 }182 }else183 return false; 184 writeBuffer();185 if(settings.completed && caretPos>=buffer.length)186 settings.completed.call(input);187 else188 setCaretPosition(this,caretPos);189 190 return false; 191 });192 /*Helper Methods*/193 function clearBuffer(start,end){194 for(var i=start;i<end;i++){195 if(!locked[i])196 buffer[i]=settings.placeholder;197 } 198 };199 200 function writeBuffer(pos){201 var s="";202 for(var i=0;i<mask.length;i++){...
inputCheck.js
Source:inputCheck.js
...10 obj.value=obj.value.replace(/\s/g,"");11 12 var s2=obj.value.length;13 if(s1 != s2){14 setCaretPosition(obj, pos-1);15 }else{16 setCaretPosition(obj, pos);17 }18 }19 20}21//åªè½å¡«å 1-9 å -çæ´æ°22function checkPhoneNum(obj,e){23 var pos=getCursortPosition (obj);24 var t=e.keyCode;25 if(t !=37 && t !=39){26 27 var s1=obj.value.length;28 obj.value=obj.value.replace(/[^0-9-]+/,'');29 obj.value=obj.value.trim();30 obj.value=obj.value.replace(/\s/g,"");31 32 var s2=obj.value.length;33 if(s1 != s2){34 setCaretPosition(obj, pos-1);35 }else{36 setCaretPosition(obj, pos);37 }38 }39}40//åªè½è¾å
¥æ£æ°åå°æ°41function checkPosiDeci(obj,e){42 var pos=getCursortPosition (obj);43 var t=e.keyCode;44 if(t !=37 && t !=39){45 var s1=obj.value.length;46 obj.value = obj.value.replace(/[^\d.]/g,""); //å
æéæ°åçé½æ¿æ¢æï¼é¤äºæ°åå. 47 obj.value = obj.value.replace(/^\./g,""); //å¿
é¡»ä¿è¯ç¬¬ä¸ä¸ªä¸ºæ°åèä¸æ¯. 48 obj.value = obj.value.replace(/\.{2,}/g,"."); //ä¿è¯åªæåºç°ä¸ä¸ª.è没æå¤ä¸ª. 49 obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$","."); //ä¿è¯.åªåºç°ä¸æ¬¡ï¼èä¸è½åºç°ä¸¤æ¬¡ä»¥ä¸ 50 51 var s2=obj.value.length;52 if(s1 != s2){53 setCaretPosition(obj, pos-1);54 }else{55 setCaretPosition(obj, pos);56 }57 }58}59//æ£éªç¨æ·è´¦å·60function checkAccountNum(obj,e){61 var pos=getCursortPosition (obj);62 var t=e.keyCode;63 if(t !=37 && t !=39){64 var s1=obj.value.length;65 obj.value=obj.value.replace(/[^\w\-\/]/ig,'');66 obj.value=obj.value.replace(/^ +| +$/g,'');67 obj.value=obj.value.replace(/\s/g,"");68 69 var s2=obj.value.length;70 if(s1 != s2){71 setCaretPosition(obj, pos-1);72 }else{73 setCaretPosition(obj, pos);74 }75 }76}77//è·åå
æ ä½ç½®78function getCursortPosition (ctrl) {79 var CaretPos = 0; // IE Support80 if (document.selection) {81 ctrl.focus ();82 var Sel = document.selection.createRange ();83 Sel.moveStart ('character', -ctrl.value.length);84 CaretPos = Sel.text.length;85 }86 else if (ctrl.selectionStart || ctrl.selectionStart == '0')87 CaretPos = ctrl.selectionStart;88 return CaretPos;89}90//设置å
æ ä½ç½®91function setCaretPosition(ctrl, pos){92 if(ctrl.setSelectionRange)93 {94 ctrl.focus();95 ctrl.setSelectionRange(pos,pos);96 }97 else if (ctrl.createTextRange) {98 var range = ctrl.createTextRange();99 range.collapse(true);100 range.moveEnd('character', pos);101 range.moveStart('character', pos);102 range.select();103 }104}105//å¤æé空...
browser_bug687160_line_api.js
Source:browser_bug687160_line_api.js
...33 editor.setText("line1\nline2\nline3");34 if (component != "textarea") {35 is(editor.getLineCount(), 3, "getLineCount() works");36 }37 editor.setCaretPosition(1);38 is(editor.getCaretOffset(), 6, "setCaretPosition(line) works");39 let pos;40 if (component != "textarea") {41 pos = editor.getCaretPosition();42 ok(pos.line == 1 && pos.col == 0, "getCaretPosition() works");43 }44 editor.setCaretPosition(1, 3);45 is(editor.getCaretOffset(), 9, "setCaretPosition(line, column) works");46 if (component != "textarea") {47 pos = editor.getCaretPosition();48 ok(pos.line == 1 && pos.col == 3, "getCaretPosition() works");49 }50 editor.setCaretPosition(2);51 is(editor.getCaretOffset(), 12, "setCaretLine() works, confirmed");52 if (component != "textarea") {53 pos = editor.getCaretPosition();54 ok(pos.line == 2 && pos.col == 0, "setCaretPosition(line) works, again");55 }56 editor.destroy();57 testWin.close();58 testWin = editor = null;59 waitForFocus(finish, window);...
Using AI Code Generation
1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'Peter Parker')4 .click('#tried-test-cafe')5 .typeText('#comments', 'I like TestCafe!')6 .setCaretPosition('#comments', 5)7 .pressKey('backspace')8 .typeText('#comments', 'dislike')9 .click('#submit-button');10});
Using AI Code Generation
1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'Peter')4 .click('#windows')5 .click('#submit-button');6});7test('My second test', async t => {8 const developerName = Selector('#developer-name');9 const windowsCheckBox = Selector('#windows');10 const submitButton = Selector('#submit-button');11 .typeText(developerName, 'Peter')12 .click(windowsCheckBox)13 .click(submitButton);14});15test('My third test', async t => {16 const developerName = Selector('#developer-name');17 const windowsCheckBox = Selector('#windows');18 const submitButton = Selector('#submit-button');19 .typeText(developerName, 'Peter')20 .click(windowsCheckBox)21 .click(submitButton)22 .setCaretPosition(developerName, 2);23});24 .typeText(developerName, 'Peter')25 .click(windowsCheckBox)26 .click(submitButton)27 .setCaretPosition(developerName, 2);28 .typeText(developerName, 'Peter')29 .click(windowsCheckBox)30 .click(submitButton)31 .setCaretPosition(developerName, 2);32test('My third test', async t =>
Using AI Code Generation
1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button');5});6const setCaretPosition = (selector, pos) => {7 return Selector(selector).addCustomDOMProperties({8 setCaretPosition: (el, pos) => {9 el.setSelectionRange(pos, pos);10 return el;11 }12 }).setCaretPosition(pos);13};14test('My second test', async t => {15 .typeText('#developer-n
Using AI Code Generation
1test('My first test', async t => {2 .typeText('#developer-name', 'John Smith')3 .click('#submit-button');4 await t.expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');5});6test('My first test', async t => {7 .typeText('#developer-name', 'John Smith')8 .click('#submit-button');9 await t.expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');10 const input = await Selector('#developer-name').value;11 const caretPosition = input.length;12 await t.setCaretPosition('#developer-name', caretPosition);13});
Using AI Code Generation
1import { Selector, t } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button');5});6test('My second test', async t => {7 .typeText('#developer-name', 'John Smith')8 .click('#submit-button');9});10test('My third test', async t => {11 .typeText('#developer-name', 'John Smith')12 .click('#submit-button');13});
Using AI Code Generation
1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'Peter Parker')4 .click('#tried-test-cafe')5 .click(Selector('label').withText('MacOS'))6 .click('#submit-button');7});8export default class TestCafe {9 constructor() {10 this.nameInput = Selector('#developer-name');11 }12 async setCaretPosition(pos) {13 await this.nameInput.setSelectionRange(pos, pos);14 }15}16test('My second test', async t => {17 const testCafe = new TestCafe();18 .typeText(testCafe.nameInput, 'John Smith')19 .click(testCafe.nameInput)20 .pressKey('ctrl+a delete')21 .typeText(testCafe.nameInput, 'Peter Parker')22 .click(testCafe.nameInput)23 .pressKey('home right . delete delete delete')24 .expect(testCafe.nameInput.value).eql('P. Parker');25 await testCafe.setCaretPosition(2);26 .pressKey('backspace')27 .expect(testCafe.nameInput.value).eql('P Parker');28});29test('My third test', async t => {30 const testCafe = new TestCafe();31 .typeText(testCafe.nameInput, 'John Smith')32 .click(testCafe.nameInput)33 .pressKey('ctrl+a delete')34 .typeText(testCafe.nameInput, 'Peter Parker')35 .click(testCafe.nameInput)36 .pressKey('home right . delete delete delete')37 .expect(testCafe.nameInput.value).eql('P. Parker');38 .click(testCafe.nameInput, { caretPos: 2 })39 .pressKey('backspace')40 .expect(testCafe.nameInput.value).eql('P Parker');41});42test('My fourth test', async t => {
Using AI Code Generation
1import { Selector } from 'testcafe';2test('My Test', async t => {3 .typeText('#developer-name', 'Peter Parker')4 .click('#tried-test-cafe')5 .click('#submit-button');6});7export async function setCaretPosition (selector, pos) {8 .click(selector, { caretPos: pos });9}10export async function setCaretPosition (selector, pos) {11 .click(selector, { caretPos: pos });12}13export async function setCaretPosition (selector, pos) {14 .click(selector, { caretPos: pos });15}16export async function setCaretPosition (selector, pos) {17 .click(selector, { caretPos: pos });18}19export async function setCaretPosition (selector, pos) {20 .click(selector, { caretPos: pos });21}22export async function setCaretPosition (selector, pos) {23 .click(selector, { caretPos: pos });24}25export async function setCaretPosition (selector, pos) {26 .click(selector, { caretPos: pos });27}28export async function setCaretPosition (selector, pos) {29 .click(selector, { caretPos: pos });30}31export async function setCaretPosition (selector, pos) {32 .click(selector, { caretPos: pos });33}34export async function setCaretPosition (selector, pos) {35 .click(selector, { caretPos: pos });36}
Using AI Code Generation
1import { Selector } from 'testcafe';2import { setCaretPosition } from './utils';3test('My first test', async t => {4 .typeText('#developer-name', 'Peter Parker')5 .click('#tried-test-cafe');6 const input = Selector('#comments');7 await t.typeText(input, 'Spiderman');8 await setCaretPosition(input, 2);9});10export async function setCaretPosition(selector, position) {11 .addCustomDOMProperties({12 })13 .with({ caretPosition: position });14}
Using AI Code Generation
1import { Selector } from 'testcafe';2import { setCaretPosition } from 'testcafe-caret-pos-selector';3test('My first test', async t => {4 const nameInput = Selector('#developer-name');5 .typeText(nameInput, 'Peter')6 .click(Selector('#windows'))7 .click(Selector('#submit-button'))8 .expect(Selector('#article-header').innerText).eql('Thank you, Peter!');9});10test('My second test', async t => {11 const nameInput = Selector('#developer-name');12 .typeText(nameInput, 'Peter')13 .click(Selector('#windows'))14 .click(Selector('#submit-button'))15 .expect(Selector('#article-header').innerText).eql('Thank you, Peter!');16 await setCaretPosition(nameInput, 2);17 .typeText(nameInput, 'e', { replace: true })18 .expect(Selector('#developer-name').value).eql('Peeter');19});
Using AI Code Generation
1import { Selector } from 'testcafe';2const testControllerHolder = require('./testControllerHolder');3const testController = testControllerHolder.get();4const input = Selector('input');5const setCaretPosition = require('set-caret-position');6 .click(input)7 .typeText(input, '1234567890')8 .wait(2000)9 .click(input)10 .wait(2000)11 .typeText(input, 'abcd')12 .wait(2000)13 .click(input)14 .wait(2000)15 .typeText(input, 'efgh')16 .wait(2000)17 .click(input)18 .wait(2000)19 .typeText(input, 'ijkl')20 .wait(2000)21 .click(input)22 .wait(2000)23 .typeText(input, 'mnop')24 .wait(2000)25 .click(input)26 .wait(2000)27 .typeText(input, 'qrst')28 .wait(2000)29 .click(input)30 .wait(2000)31 .typeText(input, 'uvwx')32 .wait(2000)33 .click(input)34 .wait(2000)35 .typeText(input, 'yz')36 .wait(2000)37 .click(input)38 .wait(2000)39 .typeText(input, 'ABCD')40 .wait(2000)41 .click(input)42 .wait(2000)43 .typeText(input, 'EFGH')44 .wait(2000)45 .click(input)46 .wait(2000)47 .typeText(input, 'IJKL')48 .wait(2000)49 .click(input)50 .wait(2000)51 .typeText(input, 'MNOP')52 .wait(2000)53 .click(input)54 .wait(2000)55 .typeText(input, 'QRST')56 .wait(2000)57 .click(input)58 .wait(2000)59 .typeText(input, 'UVWX')60 .wait(2000)61 .click(input)62 .wait(2000)63 .typeText(input, 'YZ')64 .wait(2000)65 .click(input)66 .wait(2000)67 .typeText(input, '1234')
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!