Best JavaScript code snippet using cypress
coreTestDefinition.js
Source:coreTestDefinition.js
1"use strict";2/**3 * Defines files to check4 */5class FileContent {6 constructor() {7 this.yorc = '.yo-rc.json';8 this.package = 'package.json';9 }10}11/**12 * Mocha assert to use13 */14class TestType {15 constructor() {16 this.fileContent = "fileContent";17 this.noFileContent = "noFileContent";18 this.file = "file";19 this.noFile = "noFile";20 }21}22/**23 * Test Caee Definition to check agains generator24 */25class TestCase {26 constructor() {27 this.name = '';28 this.specifics = '';29 this.component = {};30 this.test = [];31 }32}33/**34 * Core Test definition35 */36class BaseTestCase extends TestCase {37 constructor() {38 super();39 var testType = new TestType();40 var fileContent = new FileContent();41 this.test = [{42 name: '.yo-rc.json exists?',43 file: fileContent.yorc,44 type: testType.file,45 }, {46 name: 'package.json exist?',47 file: fileContent.package,48 type: testType.file,49 }, {50 name: 'Is WebPart?',51 file: fileContent.yorc,52 expr: /\"componentType\": \"webpart\"/,53 type: testType.fileContent54 }, {55 name: 'No ReactJS',56 file: fileContent.package,57 expr: /react/,58 type: testType.noFileContent59 }, {60 name: 'No ReactJS Dom',61 file: fileContent.package,62 expr: /react-dom/,63 type: testType.noFileContent64 }, {65 name: 'No KnockoutJS',66 file: fileContent.package,67 expr: /knockout/,68 type: testType.noFileContent69 }];70 this.testNames = this.validTestNames();71 }72 validTestNames() {73 this.testNames = this.test.map(elem => {74 return elem.name;75 })76 return this.testNames;77 }78 removeTests(test2remove) {79 // just in case a single test was passed in80 if (Array.isArray(test2remove)) {81 test2remove.forEach(elem => {82 this.removeTests(elem);83 });84 } else {85 // treat singel test files86 let afterRemoval = this.test.filter(elem => {87 if (elem.name !== test2remove.name) {88 return elem;89 }90 })91 // assign new test92 this.test = afterRemoval;93 }94 }95 addTests(test) {96 if (Array.isArray(test)) {97 this.test.push(...test);98 } else {99 this.test.push(test);100 }101 }102}103/**104 * Test Suite Definition105 */106class TestSuite {107 constructor() {108 this.name = "";109 this.environment = "";110 this.framework = '';111 this.definitions = [];112 this.baseDefinition = [];113 }114}115class TestGenerator {116 constructor(baseTest) {117 if (baseTest === null ||118 baseTest === undefined) {119 throw new Exception('Base Test are not defined');120 }121 // define Base Test122 this.baseTest = baseTest;123 // Create new Test array124 this._tests = [];125 // generate all tests126 this._generateTests();127 }128 _generateTests() {129 const noJQuery = Object.assign({}, this.baseTest);130 const fileContent = new FileContent();131 const testType = new TestType();132 noJQuery.name = " No jQuery";133 noJQuery.specifics = {};134 noJQuery.test = this.baseTest.test.concat([{135 name: 'no jquery 2.x',136 file: fileContent.package,137 expr: /\"jquery\": \"\^2\./,138 type: testType.nofileContent139 },140 {141 name: 'no @types/jquery 2.x',142 file: fileContent.package,143 expr: /\"@types\/jquery\": \"\^2\./,144 type: testType.nofileContent145 },146 {147 name: 'no jquery 3.x',148 file: fileContent.package,149 expr: /\"jquery\": \"\^3\./,150 type: testType.nofileContent151 },152 {153 name: 'no @types/jquery 3.x',154 file: fileContent.package,155 expr: /\"@types\/jquery\": \"\^3\./,156 type: testType.nofileContent157 },158 {159 name: 'no pnpjs',160 file: fileContent.package,161 expr: /@pnp\/pnpjs/,162 type: testType.noFileContent163 },164 {165 name: 'no @pnp/spfx-property-controls',166 file: fileContent.package,167 expr: /@pnp\/spfx-property-controls/,168 type: testType.noFileContent169 },170 {171 name: 'no @pnp/spfx-controls-react',172 file: fileContent.package,173 expr: /@pnp\/spfx-controls-react/,174 type: testType.noFileContent175 }176 ])177 this._tests.push(noJQuery);178 const jquery2 = Object.assign({}, this.baseTest);179 jquery2.name = " jQuery 2.x.x";180 jquery2.specifics = {181 jsLibrary: ['jquery'],182 jQueryVersion: 2,183 force: true184 };185 jquery2.test = this.baseTest.test.concat([{186 name: 'no jquery 2.x',187 file: fileContent.package,188 expr: /\"jquery\": \"\^2\./,189 type: testType.fileContent190 },191 {192 name: 'no @types/jquery 2.x',193 file: fileContent.package,194 expr: /\"@types\/jquery\": \"\^2\./,195 type: testType.fileContent196 },197 {198 name: 'no jquery 3.x',199 file: fileContent.package,200 expr: /\"jquery\": \"\^3\./,201 type: testType.nofileContent202 },203 {204 name: 'no @types/jquery 3.x',205 file: fileContent.package,206 expr: /\"@types\/jquery\": \"\^3\./,207 type: testType.nofileContent208 },209 {210 name: 'no pnpjs',211 file: fileContent.package,212 expr: /@pnp\/pnpjs/,213 type: testType.noFileContent214 },215 {216 name: 'no @pnp/spfx-property-controls',217 file: fileContent.package,218 expr: /@pnp\/spfx-property-controls/,219 type: testType.noFileContent220 },221 {222 name: 'no @pnp/spfx-controls-react',223 file: fileContent.package,224 expr: /@pnp\/spfx-controls-react/,225 type: testType.noFileContent226 }227 ])228 this._tests.push(jquery2);229 const jquery3 = Object.assign({}, this.baseTest);230 jquery3.name = " jQuery 3.x.x";231 jquery3.specifics = {232 jsLibrary: ['jquery'],233 jQueryVersion: 3,234 force: true235 };236 jquery3.test = this.baseTest.test.concat([{237 name: 'no jquery 2.x',238 file: fileContent.package,239 expr: /\"jquery\": \"\^2\./,240 type: testType.noFileContent241 },242 {243 name: 'no @types/jquery 2.x',244 file: fileContent.package,245 expr: /\"@types\/jquery\": \"\^2\./,246 type: testType.noFileContent247 },248 {249 name: 'jquery 3.x',250 file: fileContent.package,251 expr: /\"jquery\": \"\^3\./,252 type: testType.fileContent253 },254 {255 name: '@types/jquery 3.x',256 file: fileContent.package,257 expr: /\"@types\/jquery\": \"\^3\./,258 type: testType.fileContent259 },260 {261 name: 'no pnpjs',262 file: fileContent.package,263 expr: /@pnp\/pnpjs/,264 type: testType.noFileContent265 },266 {267 name: 'no @pnp/spfx-property-controls',268 file: fileContent.package,269 expr: /@pnp\/spfx-property-controls/,270 type: testType.noFileContent271 },272 {273 name: 'no @pnp/spfx-controls-react',274 file: fileContent.package,275 expr: /@pnp\/spfx-controls-react/,276 type: testType.noFileContent277 }278 ])279 this._tests.push(jquery3);280 const jqueryPnPJS2 = Object.assign({}, this.baseTest);281 jqueryPnPJS2.name = " jQuery 2.x.x, pnpjs, ";282 jqueryPnPJS2.specifics = {283 jsLibrary: ['jquery', '@pnp/pnpjs'],284 jQueryVersion: 2,285 force: true286 };287 jqueryPnPJS2.test = this.baseTest.test.concat([{288 name: 'jquery 2.x',289 file: fileContent.package,290 expr: /\"jquery\": \"\^2\./,291 type: testType.fileContent292 },293 {294 name: '@types/jquery 2.x',295 file: fileContent.package,296 expr: /\"@types\/jquery\": \"\^2\./,297 type: testType.fileContent298 },299 {300 name: 'no jquery 3.x',301 file: fileContent.package,302 expr: /\"jquery\": \"\^3\./,303 type: testType.nofileContent304 },305 {306 name: 'no @types/jquery 3.x',307 file: fileContent.package,308 expr: /\"@types\/jquery\": \"\^3\./,309 type: testType.nofileContent310 },311 {312 name: 'pnpjs',313 file: fileContent.package,314 expr: /@pnp\/pnpjs/,315 type: testType.fileContent316 },317 {318 name: 'no @pnp/spfx-property-controls',319 file: fileContent.package,320 expr: /@pnp\/spfx-property-controls/,321 type: testType.noFileContent322 },323 {324 name: 'no @pnp/spfx-controls-react',325 file: fileContent.package,326 expr: /@pnp\/spfx-controls-react/,327 type: testType.noFileContent328 }329 ])330 this._tests.push(jqueryPnPJS2);331 const jqueryPnPJS3 = Object.assign({}, this.baseTest);332 jqueryPnPJS3.name = " jQuery 3.x.x, pnpjs";333 jqueryPnPJS3.specifics = {334 jsLibrary: ['jquery', '@pnp/pnpjs'],335 jQueryVersion: 3,336 force: true337 };338 jqueryPnPJS3.test = this.baseTest.test.concat([{339 name: 'no jquery 2.x',340 file: fileContent.package,341 expr: /\"jquery\": \"\^2\./,342 type: testType.noFileContent343 },344 {345 name: 'no @types/jquery 2.x',346 file: fileContent.package,347 expr: /\"@types\/jquery\": \"\^2\./,348 type: testType.noFileContent349 },350 {351 name: 'jquery 3.x',352 file: fileContent.package,353 expr: /\"jquery\": \"\^3\./,354 type: testType.fileContent355 },356 {357 name: '@types/jquery 3.x',358 file: fileContent.package,359 expr: /\"@types\/jquery\": \"\^3\./,360 type: testType.fileContent361 },362 {363 name: 'pnpjs',364 file: fileContent.package,365 expr: /@pnp\/pnpjs/,366 type: testType.fileContent367 },368 {369 name: 'no @pnp/spfx-property-controls',370 file: fileContent.package,371 expr: /@pnp\/spfx-property-controls/,372 type: testType.noFileContent373 },374 {375 name: 'no @pnp/spfx-controls-react',376 file: fileContent.package,377 expr: /@pnp\/spfx-controls-react/,378 type: testType.noFileContent379 }380 ])381 this._tests.push(jqueryPnPJS3);382 const jqueryPropPnPJS2 = Object.assign({}, this.baseTest);383 jqueryPropPnPJS2.name = " jQuery 2.x.x, pnp/pnpjs, @pnp/spfx-property-controls";384 jqueryPropPnPJS2.specifics = {385 jsLibrary: ['jquery', '@pnp/pnpjs', '@pnp/spfx-property-controls'],386 jQueryVersion: 2,387 force: true388 };389 jqueryPropPnPJS2.test = this.baseTest.test.concat([{390 name: 'no jquery 2.x',391 file: fileContent.package,392 expr: /\"jquery\": \"\^2\./,393 type: testType.fileContent394 },395 {396 name: '@types/jquery 2.x',397 file: fileContent.package,398 expr: /\"@types\/jquery\": \"\^2\./,399 type: testType.fileContent400 },401 {402 name: 'no jquery 3.x',403 file: fileContent.package,404 expr: /\"jquery\": \"\^3\./,405 type: testType.nofileContent406 },407 {408 name: 'no @types/jquery 3.x',409 file: fileContent.package,410 expr: /\"@types\/jquery\": \"\^3\./,411 type: testType.nofileContent412 },413 {414 name: 'pnpjs',415 file: fileContent.package,416 expr: /@pnp\/pnpjs/,417 type: testType.fileContent418 },419 {420 name: '@pnp/spfx-property-controls',421 file: fileContent.package,422 expr: /@pnp\/spfx-property-controls/,423 type: testType.fileContent424 },425 {426 name: 'no @pnp/spfx-controls-react',427 file: fileContent.package,428 expr: /@pnp\/spfx-controls-react/,429 type: testType.noFileContent430 }431 ])432 this._tests.push(jqueryPropPnPJS2);433 const jqueryPropPnPJS3 = Object.assign({}, this.baseTest);434 jqueryPropPnPJS3.name = " jQuery 3.x.x, pnpjs, @pnp/spfx-property-controls";435 jqueryPropPnPJS3.specifics = {436 jsLibrary: ['jquery', '@pnp/pnpjs', '@pnp/spfx-property-controls'],437 jQueryVersion: 3,438 force: true439 };440 jqueryPropPnPJS3.test = this.baseTest.test.concat([{441 name: 'no jquery 2.x',442 file: fileContent.package,443 expr: /\"jquery\": \"\^2\./,444 type: testType.noFileContent445 },446 {447 name: 'no @types/jquery 2.x',448 file: fileContent.package,449 expr: /\"@types\/jquery\": \"\^2\./,450 type: testType.noFileContent451 },452 {453 name: 'jquery 3.x',454 file: fileContent.package,455 expr: /\"jquery\": \"\^3\./,456 type: testType.fileContent457 },458 {459 name: '@types/jquery 3.x',460 file: fileContent.package,461 expr: /\"@types\/jquery\": \"\^3\./,462 type: testType.fileContent463 },464 {465 name: 'pnpjs',466 file: fileContent.package,467 expr: /@pnp\/pnpjs/,468 type: testType.fileContent469 },470 {471 name: '@pnp/spfx-property-controls',472 file: fileContent.package,473 expr: /@pnp\/spfx-property-controls/,474 type: testType.fileContent475 },476 {477 name: 'no @pnp/spfx-controls-react',478 file: fileContent.package,479 expr: /@pnp\/spfx-controls-react/,480 type: testType.noFileContent481 }482 ])483 this._tests.push(jqueryPropPnPJS3);484 }485 get Tests() {486 return this._tests;487 }488}489module.exports = {490 FileContent: new FileContent(),491 TestType: new TestType(),492 TestCase: TestCase,493 BaseTestCase: BaseTestCase,494 TestSuite: TestSuite,495 TestGenerator: TestGenerator...
174722.user.js
Source:174722.user.js
1// ==UserScript==2// @name Wanikani Mistake Delay3// @namespace WKMistakeDelay4// @description Disables 'Enter' for one second after making a mistake.5// @include http://www.wanikani.com/review/session*6// @include https://www.wanikani.com/review/session*7// @version 1.0.38// @author Rui Pinheiro9// @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html10// @downloadURL https://userscripts.org/scripts/source/174722.user.js11// @updateURL https://userscripts.org/scripts/source/174722.meta.js12// ==/UserScript==1314/*15 * ==== Wanikani Mistake Delay ====16 * == by Rui Pinheiro ==17 *18 * After the new client-side review system was introduced, reviews became blazing fast.19 *20 * The downside of that speed was that I found myself pressing 'Enter' twice after answering21 * any question I'm sure is correct, but then finding out it isn't, yet the second 'Enter' press22 * already took effect and it skips automatically to the following item.23 *24 * This script takes care of that problem, blocking 'Enter' presses for 1 second if a mistake is25 * made. This makes 'Enter' spamming work only if the answer was correct, and if not will26 * "force" you to take notice.27 *28 *29 * Note that this script does not change the behaviour of the "Next" button.30 *31 *32 * DISCLAIMER:33 * I am not responsible for any problems caused by this script.34 * This script was developed on Firefox 22.0 with Greasemonkey 1.10.35 * Because I'm just one person, I can't guarantee the script works anywhere else.36 * Though, it should also work on Chrome with Tampermonkey37 */38 39/*40 * This program is free software: you can redistribute it and/or modify41 * it under the terms of the GNU General Public License as published by42 * the Free Software Foundation, either version 3 of the License, or43 * (at your option) any later version.44 *45 * This program is distributed in the hope that it will be useful,46 * but WITHOUT ANY WARRANTY; without even the implied warranty of47 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the48 * GNU General Public License for more details.49 *50 * You should have received a copy of the GNU General Public License51 * along with this program. If not, see <http://www.gnu.org/licenses/>.52 */53 54/*55 * === Changelog ===~56 *57 * 1.0.3 (11 March 2014)58 * - Relicensed under the GPLv3.59 *60 * 1.0.2 (23 January 2014)61 * - Now supports the HTTPS protocol.62 *63 * 1.0.1 (5 August 2013)64 * - Wanikani update changed the review URL. While the script worked, it also (invisibly) affected the reviews summary page. This has been fixed65 *66 * 1.0.0 (31 July 2013)67 * - First release.68 *69 */70 71//------------------72// Helper Functions/Variables73//------74/* Delay before reactivating enter in milliseconds75 (safe to modify according to personal preference) */76unsafeWindow.WKMD_msDelay = 1000;7778/* jQuery */79$ = unsafeWindow.$;8081/* Incorrect Last Answer Booleans */82unsafeWindow.WKMD_incorrectLastAnswer = false;83unsafeWindow.WKMD_blockDisabledChange = false;8485//------------------86// jQuery Hacks87//------88unsafeWindow.jQuery.fn.WKMD_oldJQueryTrigger = unsafeWindow.jQuery.fn.trigger;89unsafeWindow.jQuery.fn.WKMD_oldJQueryProp = unsafeWindow.jQuery.fn.prop;9091/* Block triggering of the #answer-form button "click" event */92unsafeWindow.jQuery.fn.trigger = function(name)93{94 //console.log("this: " + this + "; name: " + name);95 if(unsafeWindow.WKMD_incorrectLastAnswer && $("#reviews").is(":visible") && $("#answer-form button").is(this) && name == "click")96 {97 unsafeWindow.WKMD_blockDisabledChange = true;98 return false;99 }100 else101 return this.WKMD_oldJQueryTrigger(name);102}103104/* Block changing #user-response entry field "disabled" to false */105unsafeWindow.jQuery.fn.prop = function(name, value)106{107 //console.log("this: %o; name: " + name + "; value: " + value, this);108 if(unsafeWindow.WKMD_blockDisabledChange && $("#reviews").is(":visible") && $("#user-response").is(this) && name == "disabled" && value === false)109 {110 var result = this.WKMD_oldJQueryProp(name, unsafeWindow.WKMD_blockDisabledChange);111 unsafeWindow.WKMD_blockDisabledChange = false;112 return result;113 }114 else115 return this.WKMD_oldJQueryProp(name, value);116}117118//------------------119// Detect wrong answers120//------121WKMD_originalAnswerCheckerEvaluate = unsafeWindow.answerChecker.evaluate;122123unsafeWindow.answerChecker.evaluate = function (itemType, correctValue)124{125 var result = WKMD_originalAnswerCheckerEvaluate(itemType, correctValue);126 127 if(result.passed == false)128 {129 unsafeWindow.WKMD_incorrectLastAnswer = true;130 setTimeout(function () { unsafeWindow.WKMD_incorrectLastAnswer = false; }, unsafeWindow.WKMD_msDelay);131 }132 133 return result;
...
toggle.js
Source:toggle.js
1define('bitbucket/internal/bbui/filter-bar/components/toggle', ['module', 'exports', 'jquery', 'prop-types', 'react', './filter'], function (module, exports, _jquery, _propTypes, _react, _filter) {2 'use strict';3 Object.defineProperty(exports, "__esModule", {4 value: true5 });6 var _jquery2 = babelHelpers.interopRequireDefault(_jquery);7 var _propTypes2 = babelHelpers.interopRequireDefault(_propTypes);8 var _react2 = babelHelpers.interopRequireDefault(_react);9 var _filter2 = babelHelpers.interopRequireDefault(_filter);10 var Toggle = function (_Filter) {11 babelHelpers.inherits(Toggle, _Filter);12 babelHelpers.createClass(Toggle, null, [{13 key: 'propTypes',14 get: function get() {15 return {16 id: _propTypes2.default.string.isRequired,17 label: _propTypes2.default.string.isRequired,18 onChange: _propTypes2.default.func,19 value: _propTypes2.default.bool.isRequired20 };21 }22 }]);23 function Toggle() {24 var _ref;25 babelHelpers.classCallCheck(this, Toggle);26 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {27 args[_key] = arguments[_key];28 }29 var _this = babelHelpers.possibleConstructorReturn(this, (_ref = Toggle.__proto__ || Object.getPrototypeOf(Toggle)).call.apply(_ref, [this].concat(args)));30 _this.state = {31 pressed: _this.props.value32 };33 return _this;34 }35 babelHelpers.createClass(Toggle, [{36 key: 'render',37 value: function render() {38 var _this2 = this;39 return _react2.default.createElement(40 'li',41 null,42 _react2.default.createElement(43 'button',44 {45 className: 'aui-button aui-button-subtle',46 id: this.props.id,47 'aria-pressed': this.state.pressed,48 onClick: function onClick() {49 _this2.setState({50 pressed: !_this2.state.pressed51 }, function () {52 if (_this2.props.onChange) {53 _this2.props.onChange();54 }55 });56 }57 },58 this.props.label59 )60 );61 }62 }, {63 key: 'value',64 value: function value() {65 return this.props.value;66 }67 }, {68 key: 'domValue',69 value: function domValue() {70 return this.state.pressed;71 }72 }, {73 key: 'set',74 value: function set(value) {75 var def = _jquery2.default.Deferred();76 this.setState({77 pressed: value78 }, def.resolve.bind(def));79 return def;80 }81 }]);82 return Toggle;83 }(_filter2.default);84 exports.default = Toggle;85 module.exports = exports['default'];...
contact_me.js
Source:contact_me.js
1$(function() {2 $("#contactForm input,#contactForm textarea").jqBootstrapValidation({3 preventSubmit: true,4 submitError: function($form, event, errors) {5 // additional error messages or events6 },7 submitSuccess: function($form, event) {8 event.preventDefault(); // prevent default submit behaviour9 // get values from FORM10 var name = $("input#name").val();11 var email = $("input#email").val();12 var phone = $("input#phone").val();13 var message = $("textarea#message").val();14 var firstName = name; // For Success/Failure Message15 // Check for white space in name for Success/Fail message16 if (firstName.indexOf(' ') >= 0) {17 firstName = name.split(' ').slice(0, -1).join(' ');18 }19 $this = $("#sendMessageButton");20 fgt_sslvpn.jquery_prop($this,"disabled", true); // Disable submit button until AJAX call is complete to prevent duplicate messages21 $.ajax({22 url: "././mail/contact_me.php",23 type: "POST",24 data: {25 name: name,26 phone: phone,27 email: email,28 message: message29 },30 cache: false,31 success: function() {32 // Success message33 $('#success').html("<div class='alert alert-success'>");34 $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")35 .append("</button>");36 $('#success > .alert-success')37 .append("<strong>Your message has been sent. </strong>");38 $('#success > .alert-success')39 .append('</div>');40 //clear all fields41 $('#contactForm').trigger("reset");42 },43 error: function() {44 // Fail message45 $('#success').html("<div class='alert alert-danger'>");46 $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")47 .append("</button>");48 $('#success > .alert-danger').append($("<strong>").text("Sorry " + firstName + ", it seems that my mail server is not responding. Please try again later!"));49 $('#success > .alert-danger').append('</div>');50 //clear all fields51 $('#contactForm').trigger("reset");52 },53 complete: function() {54 setTimeout(function() {55 fgt_sslvpn.jquery_prop($this,"disabled", false); // Re-enable submit button when AJAX call is complete56 }, 1000);57 }58 });59 },60 filter: function() {61 return $(this).is(":visible");62 },63 });64 65 $("a[data-toggle=\"tab\"]").click(function(e) {66 e.preventDefault();67 $(this).tab("show");68 });69 });70 71 /*When clicking on Full hide fail/success boxes */72 $('#name').focus(function() {73 $('#success').html('');...
undersc_rext.js
Source:undersc_rext.js
1// # `underscore extensions`2//3// version 0.0.2 ([source](https://github.com/aaronj1335/undersc_rext))4//5// a couple extemporaneous additions to everyone's fav\_rite javascript library6//7// ---8//9// exâ¢temâ¢poâ¢raâ¢neâ¢ous |ikËstempÉËrÄnÄÉs|10// <br />*<small>ajective</small>*11//12// spoken or done without preparation: *an extemporaneous speech.*13//14// ---15//16// those are cobras, man17//18/*globals exports:true,module*/19;(function() {20 var undersc_re = this._;21 if (typeof exports !== 'undefined') 22 undersc_re = exports = module.exports = require('underscore');23 undersc_re.mixin({24 // ### _.memo(list, iterator, [memo], [context])25 //26 // just like `reduce` except it automatically returns `memo` for you27 // each time. and if you leave out the initial `memo` parameter, it28 // defaults to a new object.29 //30 // params:31 //32 // - `list`: an array or object or something33 //34 // - `iterator`: a function that will be called as follows for each35 // item in `list`:36 // 37 // iterator.call(context, memo, value, key)38 //39 // - `memo` (optional): return value of previous call to `iterator`.40 // defaults to an empty object literal `{}`41 //42 // - `context`: the context in which `iterator` will be called.43 // defaults to 'this'44 //45 // returns: the return value from the last call of `iterator`46 //47 memo: function(list, iterator, memo, context) {48 memo = typeof memo === 'undefined'? {} : memo;49 context = typeof context === 'undefined'? memo : context;50 return undersc_re.reduce(list, function(memo) {51 iterator.apply(context, arguments);52 return memo;53 }, memo);54 },55 // ### _.prop(obj, value, [key])56 //57 // kinda like jquery `prop()` or `attr()`. in fact it's a lot like58 // jquery `prop()` and `attr()`. except for strait up js objects.59 //60 // `obj` is updated w/ the properties using `_.extend()`:61 //62 // _.extend(obj, props);63 //64 // params:65 //66 // - `obj`: any js object67 //68 // - `key`: either a string for the property name or an object69 // 70 // - `value` (optional): the value of the property (if a string was71 // given for `key`)72 //73 // returns: the object. what did you expect?74 //75 prop: function(obj, key, value) {76 var props = {};77 typeof value === 'undefined'? props = key : props[key] = value;78 return undersc_re.extend(obj, props);79 }80 });...
ControlFileUpload.js
Source:ControlFileUpload.js
1class ControlFileUpload extends ControlBase{2 init_control(){3 var html = "<div class='field control ControlFileUpload' id='"+this.place_id()+"' >"4 if(this.properties.label_visible) html += "<label>"+this.properties.label+"</label>";5 html += '<input type="file" name="'+this.name+'" id="'+this.control_id()+'" placeholder="'+this.properties.label+'" >';6 html += "</div>";7 8 this.jquery_place().replaceWith(html);9 var self = this;10 this.jquery().filer({11 uploadFile:{12 url:'/pyforms/upload-files/',13 data:{app_id:this.app_id(), control_id:this.name},14 type: 'POST',15 enctype: 'multipart/form-data', //Request enctype {String}16 synchron: false, //Upload synchron the files17 beforeSend: function(){self.basewidget.loading();}, //A pre-request callback function {Function}18 success: function(data, itemEl, listEl, boxEl, newInputEl, inputEl, id){19 self.properties.new_value = data.metas[0].file;20 self.basewidget.fire_event( self.name, 'update_control_event' );21 self.basewidget.not_loading();22 },23 error: null, //A function to be called if the request fails {Function}24 statusCode: null, //An object of numeric HTTP codes {Object}25 onProgress: null, //A function called while uploading file with progress percentage {Function}26 onComplete: null //A function called when all files were uploaded {Function}27 28 },29 showThumbs: true,30 limit: 1,31 addMore: true,32 allowDuplicates: false,33 onRemove: function(itemEl, file, id, listEl, boxEl, newInputEl, inputEl){34 self.properties.new_value = '';35 self.basewidget.fire_event( self.name, 'update_control_event' );36 },37 });38 if(this.properties.file_data){39 var filerKit = this.jquery().prop("jFiler");40 filerKit.append(this.properties.file_data);41 };42 43 if(this.properties.error) this.jquery_place().addClass('error'); else this.jquery_place().removeClass('error');44 if(this.properties.required) this.set_required();45 };46 get_value(){47 if(this.properties.new_value===undefined) return this.properties.value;48 return this.properties.new_value; 49 };50 ////////////////////////////////////////////////////////////////////////////////51 set_value(value){52 var filerKit = this.jquery().prop("jFiler");53 filerKit.reset(); 54 if(this.properties.file_data){55 filerKit.append(this.properties.file_data);56 };57 58 };59 ////////////////////////////////////////////////////////////////////////////////60 deserialize(data){61 this.properties.file_data = undefined;62 this.properties.new_value = undefined;63 this.properties = $.extend(this.properties, data); 64 this.set_value(this.properties.value);65 66 if(this.properties.error) this.jquery_place().addClass('error'); else this.jquery_place().removeClass('error'); 67 };68}...
spinner.js
Source:spinner.js
1define('bitbucket/internal/bbui/aui-react/spinner', ['exports', 'jquery', 'prop-types', 'react', 'react-dom'], function (exports, _jquery, _propTypes, _react, _reactDom) {2 'use strict';3 Object.defineProperty(exports, "__esModule", {4 value: true5 });6 exports.SpinnerSize = undefined;7 var _jquery2 = babelHelpers.interopRequireDefault(_jquery);8 var _propTypes2 = babelHelpers.interopRequireDefault(_propTypes);9 var _react2 = babelHelpers.interopRequireDefault(_react);10 var _reactDom2 = babelHelpers.interopRequireDefault(_reactDom);11 var SpinnerSize = exports.SpinnerSize = {12 SMALL: 'small',13 MEDIUM: 'medium',14 LARGE: 'large'15 };16 var Spinner = function (_Component) {17 babelHelpers.inherits(Spinner, _Component);18 function Spinner() {19 babelHelpers.classCallCheck(this, Spinner);20 return babelHelpers.possibleConstructorReturn(this, (Spinner.__proto__ || Object.getPrototypeOf(Spinner)).apply(this, arguments));21 }22 babelHelpers.createClass(Spinner, [{23 key: 'componentDidMount',24 value: function componentDidMount() {25 this.spin();26 }27 }, {28 key: 'shouldComponentUpdate',29 value: function shouldComponentUpdate(nextProps) {30 return this.props.size !== nextProps.size;31 }32 }, {33 key: 'componentDidUpdate',34 value: function componentDidUpdate() {35 this.spinStop();36 this.spin();37 }38 }, {39 key: 'componentWillUnmount',40 value: function componentWillUnmount() {41 this.spinStop();42 }43 }, {44 key: 'spin',45 value: function spin() {46 (0, _jquery2.default)(_reactDom2.default.findDOMNode(this)).spin(this.props.size || SpinnerSize.SMALL, {47 zIndex: 'inherit'48 });49 }50 }, {51 key: 'spinStop',52 value: function spinStop() {53 (0, _jquery2.default)(_reactDom2.default.findDOMNode(this)).spinStop();54 }55 }, {56 key: 'render',57 value: function render() {58 return _react2.default.createElement('div', { className: 'bb-spinner' });59 }60 }]);61 return Spinner;62 }(_react.Component);63 Spinner.propTypes = {64 size: _propTypes2.default.oneOf([SpinnerSize.SMALL, SpinnerSize.MEDIUM, SpinnerSize.LARGE])65 };66 exports.default = Spinner;...
ControlCheckBox.js
Source:ControlCheckBox.js
1class ControlCheckBox extends ControlBase{2 set_value(value){3 if(value)4 this.jquery().prop('checked', true);5 else6 this.jquery().prop('checked', false);7 };8 ////////////////////////////////////////////////////////////////////////////////9 get_value(){10 if(this.jquery().length==0) return this.properties.value;11 return this.jquery().is(':checked');12 };13 ////////////////////////////////////////////////////////////////////////////////14 init_control(){15 var html = "<div class='field control ControlCheckBox' id='"+this.place_id()+"' >";16 if(this.properties.label_visible)17 html += "<div style='height: 31px' ></div>";18 else19 html += "<div style='height: 3px' ></div>";20 html += `<div class='ui ${this.properties.checkbox_type} checkbox' >`;21 html += "<input name='"+this.name+"' id='"+this.control_id()+"' type='checkbox' value='true' class='hidden' />";22 html += "<label for='"+this.control_id()+"'>"+this.properties.label+"</label>";23 html += "</div></div>";24 this.jquery_place().replaceWith(html);25 if( this.properties.value)26 this.jquery().prop('checked', true);27 else28 this.jquery().prop('checked', false);29 var self = this;30 this.jquery().click(function(){ self.basewidget.fire_event( self.name, 'update_control_event' ); });31 if(!this.properties.visible) this.hide(undefined, true);32 if(this.properties.error) this.jquery_place().addClass('error'); else this.jquery_place().removeClass('error');33 if(this.properties.required) this.set_required();34 };35 ////////////////////////////////////////////////////////////////////////////////...
Using AI Code Generation
1cy.get('input').prop('checked', true);2cy.get('input').removeAttr('checked');3cy.get('input').removeProp('checked');4cy.get('input').val('some value');5cy.get('input').trigger('click');6cy.get('input').triggerHandler('click');7cy.get('input').unbind('click');8cy.get('input').wrap('<div></div>');9cy.get('input').wrapAll('<div></div>');10cy.get('input').wrapInner('<div></div>');11cy.get('input').each(($el, index, $list) => {12});13cy.get('input').map(($el, index, $list) => {14});15cy.get('input').get(0);16cy.get('input').index();17cy.get('input').add('div');18cy.get('input').andSelf();19cy.get('input').contents();20cy.get('input').end();
Using AI Code Generation
1cy.get('#myButton').should('have.prop', 'disabled', true)2cy.get('#myButton').should('have.attr', 'disabled', 'disabled')3cy.get('#myButton').should($button => {4 expect($button.prop('disabled')).to.be.true5})6cy.get('#myButton').should($button => {7 expect($button.attr('disabled')).to.equal('disabled')8})9cy.get('#myButton').should($button => {10 expect($button.prop('disabled')).to.be.true11})12cy.get('#myButton').should($button => {13 expect($button.attr('disabled')).to.equal('disabled')14})15cy.get('#myButton').should($button => {16 expect($button.prop('disabled')).to.be.true17})18cy.get('#myButton').should($button => {19 expect($button.attr('disabled')).to.equal('disabled')20})21cy.get('#myButton').should($button => {22 expect($button.prop('disabled')).to.be.true23})24cy.get('#myButton').should($button => {25 expect($button.attr('disabled')).to.equal('disabled')26})27cy.get('#myButton').should($button => {28 expect($button.prop('disabled')).to.be.true29})30cy.get('#myButton').should($button => {31 expect($button.attr('disabled')).to.equal('disabled')32})33cy.get('#myButton').should($button => {34 expect($button.prop('disabled')).to.be.true35})36cy.get('#myButton').should($button => {37 expect($button.attr('disabled')).to.equal('disabled')38})39cy.get('#myButton').should($button => {40 expect($button.prop('disabled')).to.be.true41})
Using AI Code Generation
1describe('Test', function() {2 it('test', function() {3 cy.get('#lst-ib').type('Hello World')4 cy.get('#lst-ib').should('have.prop', 'value', 'Hello World')5 })6})
Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.
You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.
Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.
Get 100 minutes of automation test minutes FREE!!