Best JavaScript code snippet using cypress
line.js
Source:line.js
1(function(){2 var LINE_OBJECT = {3 'type': 'line',4 'originX': 'left',5 'originY': 'top',6 'left': 11,7 'top': 12,8 'width': 2,9 'height': 2,10 'fill': 'rgb(0,0,0)',11 'stroke': null,12 'strokeWidth': 1,13 'strokeDashArray': null,14 'strokeLineCap': 'butt',15 'strokeLineJoin': 'miter',16 'strokeMiterLimit': 10,17 'scaleX': 1,18 'scaleY': 1,19 'angle': 0,20 'flipX': false,21 'flipY': false,22 'opacity': 1,23 'x1': -1,24 'y1': -1,25 'x2': 1,26 'y2': 1,27 'shadow': null,28 'visible': true,29 'clipTo': null,30 'backgroundColor': '',31 'fillRule': 'nonzero',32 'globalCompositeOperation': 'source-over',33 'skewX': 0,34 'skewY': 0,35 'transformMatrix': null36 };37 QUnit.module('fabric.Line');38 test('constructor', function() {39 ok(fabric.Line);40 var line = new fabric.Line([10, 11, 20, 21]);41 ok(line instanceof fabric.Line);42 ok(line instanceof fabric.Object);43 equal(line.type, 'line');44 equal(line.get('x1'), 10);45 equal(line.get('y1'), 11);46 equal(line.get('x2'), 20);47 equal(line.get('y2'), 21);48 var lineWithoutPoints = new fabric.Line();49 equal(lineWithoutPoints.get('x1'), 0);50 equal(lineWithoutPoints.get('y1'), 0);51 equal(lineWithoutPoints.get('x2'), 0);52 equal(lineWithoutPoints.get('y2'), 0);53 });54 test('complexity', function() {55 var line = new fabric.Line();56 ok(typeof line.complexity == 'function');57 });58 test('toObject', function() {59 var line = new fabric.Line([11, 12, 13, 14]);60 ok(typeof line.toObject == 'function');61 deepEqual(LINE_OBJECT, line.toObject());62 });63 test('fromObject', function() {64 ok(typeof fabric.Line.fromObject == 'function');65 var line = fabric.Line.fromObject(LINE_OBJECT);66 ok(line instanceof fabric.Line);67 deepEqual(LINE_OBJECT, line.toObject());68 });69 test('fromElement', function() {70 ok(typeof fabric.Line.fromElement == 'function');71 var lineEl = fabric.document.createElement('line'),72 x1 = 11,73 y1 = 23,74 x2 = 34,75 y2 = 7,76 stroke = 'ff5555',77 strokeWidth = 2,78 strokeDashArray = [5, 2],79 strokeLineCap = 'round',80 strokeLineJoin = 'bevil',81 strokeMiterLimit = 5;82 lineEl.setAttribute('x1', x1);83 lineEl.setAttribute('x2', x2);84 lineEl.setAttribute('y1', y1);85 lineEl.setAttribute('y2', y2);86 lineEl.setAttribute('stroke', stroke);87 lineEl.setAttribute('stroke-width', strokeWidth);88 lineEl.setAttribute('stroke-dasharray', '5, 2');89 lineEl.setAttribute('stroke-linecap', strokeLineCap);90 lineEl.setAttribute('stroke-linejoin', strokeLineJoin);91 lineEl.setAttribute('stroke-miterlimit', strokeMiterLimit);92 var oLine = fabric.Line.fromElement(lineEl);93 ok(oLine instanceof fabric.Line);94 equal(oLine.get('x1'), x1);95 equal(oLine.get('y1'), y1);96 equal(oLine.get('x2'), x2);97 equal(oLine.get('y2'), y2);98 equal(oLine.get('stroke'), stroke);99 equal(oLine.get('strokeWidth'), strokeWidth);100 deepEqual(oLine.get('strokeDashArray'), strokeDashArray);101 equal(oLine.get('strokeLineCap'), strokeLineCap);102 equal(oLine.get('strokeLineJoin'), strokeLineJoin);103 equal(oLine.get('strokeMiterLimit'), strokeMiterLimit);104 var lineElWithMissingAttributes = fabric.document.createElement('line');105 lineElWithMissingAttributes.setAttribute('x1', 10);106 lineElWithMissingAttributes.setAttribute('y1', 20);107 oLine = fabric.Line.fromElement(lineElWithMissingAttributes);108 equal(oLine.get('x2'), 0, 'missing attributes count as 0 values');109 equal(oLine.get('y2'), 0, 'missing attributes count as 0 values');110 });111 test('straight lines may have 0 width or heigth', function() {112 var line1 = new fabric.Line([10,10,100,10]),113 line2 = new fabric.Line([10,10,10,100]);114 equal(line1.get('height'), 0);115 equal(line2.get('width'), 0);116 });117 test('changing x/y coords should update width/height', function() {118 var line = new fabric.Line([ 50, 50, 100, 100]);119 equal(50, line.width);120 line.set({ x1: 75, y1: 75, x2: 175, y2: 175 });121 equal(100, line.width);122 equal(100, line.height);123 });124 test('stroke-width in a style', function() {125 var lineEl = fabric.document.createElement('line');126 lineEl.setAttribute('style', 'stroke-width:4');127 var oLine = fabric.Line.fromElement(lineEl);128 ok(4, oLine.strokeWidth);129 });130 // this isn't implemented yet, so disabling for now131 // test('x1,y1 less than x2,y2 should work', function() {132 // var line = new fabric.Line([ 400, 200, 300, 400]);133 // equal(100, line.width);134 // equal(200, line.height);135 // });136 var lineCoordsCases = [137 { description: 'default to 0 left and 0 top',138 givenLineArgs: {},139 expectedCoords: {140 left: 0,141 top: 0,142 }143 },144 { description: 'origin defaults to left-top',145 givenLineArgs: {146 points: [0, 0, 11, 22],147 },148 expectedCoords: {149 left: 0,150 top: 0,151 }152 },153 { description: 'equal smallest points when origin is left-top and line not offset',154 givenLineArgs: {155 points: [0, 0, 12.3, 34.5],156 options: {157 originX: 'left',158 originY: 'top',159 },160 },161 expectedCoords: {162 left: 0,163 top: 0,164 }165 },166 { description: 'include offsets for left-top origin',167 givenLineArgs: {168 points: [0+33, 0+44, 11+33, 22+44],169 options: {170 originX: 'left',171 originY: 'top',172 },173 },174 expectedCoords: {175 left: 33,176 top: 44,177 }178 },179 { description: 'equal half-dimensions when origin is center and line not offset',180 givenLineArgs: {181 points: [0, 0, 12.3, 34.5],182 options: {183 originX: 'center',184 originY: 'center',185 },186 },187 expectedCoords: {188 left: 0.5 * 12.3,189 top: 0.5 * 34.5,190 }191 },192 { description: 'include offsets for center-center origin',193 givenLineArgs: {194 points: [0+9.87, 0-4.32, 12.3+9.87, 34.5-4.32],195 options: {196 originX: 'center',197 originY: 'center',198 },199 },200 expectedCoords: {201 left: (0.5 * 12.3) + 9.87,202 top: (0.5 * 34.5) - 4.32,203 }204 },205 { description: 'equal full dimensions when origin is right-bottom and line not offset',206 givenLineArgs: {207 points: [0, 0, 55, 18],208 options: {209 originX: 'right',210 originY: 'bottom',211 },212 },213 expectedCoords: {214 left: 55,215 top: 18,216 }217 },218 { description: 'include offsets for right-bottom origin',219 givenLineArgs: {220 points: [0-3.14, 0-1.41, 55-3.14, 18-1.41],221 options: {222 originX: 'right',223 originY: 'bottom',224 },225 },226 expectedCoords: {227 left: 55 - 3.14,228 top: 18 - 1.41,229 }230 },231 { description: 'arent changed by rotation for left-top origin',232 givenLineArgs: {233 points: [1, 2, 30, 40],234 options: {235 originX: 'left',236 originY: 'top',237 angle: 67,238 }239 },240 expectedCoords: {241 left: 1,242 top: 2,243 }244 },245 { description: 'arent changed by rotation for right-bottom origin',246 givenLineArgs: {247 points: [1, 2, 30, 40],248 options: {249 originX: 'right',250 originY: 'bottom',251 angle: 67,252 }253 },254 expectedCoords: {255 left: 30,256 top: 40,257 }258 },259 { description: 'arent changed by scaling for left-top origin',260 givenLineArgs: {261 points: [1, 2, 30, 40],262 options: {263 originX: 'left',264 originY: 'top',265 scale: 2.1,266 }267 },268 expectedCoords: {269 left: 1,270 top: 2,271 }272 },273 { description: 'arent changed by scaling for right-bottom origin',274 givenLineArgs: {275 points: [1, 2, 30, 40],276 options: {277 originX: 'right',278 originY: 'bottom',279 scale: 1.2,280 }281 },282 expectedCoords: {283 left: 30,284 top: 40,285 }286 },287 { description: 'arent changed by strokeWidth for left-top origin',288 givenLineArgs: {289 points: [31, 41, 59, 26],290 options: {291 originX: 'left',292 originY: 'top',293 stroke: 'black',294 strokeWidth: '53'295 }296 },297 expectedCoords: {298 left: 31,299 top: 26,300 }301 },302 { description: 'arent changed by strokeWidth for center-center origin',303 givenLineArgs: {304 points: [0+31, 15+26, 28+31, 0+26],305 options: {306 originX: 'center',307 originY: 'center',308 stroke: 'black',309 strokeWidth: '53'310 }311 },312 expectedCoords: {313 left: (0.5 * 28) + 31,314 top: (0.5 * 15) + 26,315 }316 },317 { description: 'arent changed by strokeWidth for right-bottom origin',318 givenLineArgs: {319 points: [1, 2, 30, 40],320 options: {321 originX: 'right',322 originY: 'bottom',323 stroke: 'black',324 strokeWidth: '53'325 }326 },327 expectedCoords: {328 left: 30,329 top: 40,330 }331 },332 { description: 'left and top options override points',333 givenLineArgs: {334 points: [12, 34, 56, 78],335 options: {336 left: 98,337 top: 76,338 }339 },340 expectedCoords: {341 left: 98,342 top: 76,343 }344 },345 { description: '0 left and 0 top options override points',346 givenLineArgs: {347 points: [12, 34, 56, 78],348 options: {349 left: 0,350 top: 0,351 }352 },353 expectedCoords: {354 left: 0,355 top: 0,356 }357 },358 { description: 'equal x2 and y2 for left-top origin when x1 and y1 are largest and line not offset',359 givenLineArgs: {360 points: [100, 200, 30, 40],361 options: {362 originX: 'left',363 originY: 'top',364 }365 },366 expectedCoords: {367 left: 30,368 top: 40,369 }370 },371 { description: 'equal half-dimensions for center-center origin when x1 and y1 are largest and line not offset',372 givenLineArgs: {373 points: [100, 200, 0, 0],374 options: {375 originX: 'center',376 originY: 'center',377 }378 },379 expectedCoords: {380 left: 0.5 * 100,381 top: 0.5 * 200,382 }383 },384 { description: 'equal x1 and y1 for right-bottom origin when x1 and y1 are largest and line not offset',385 givenLineArgs: {386 points: [100, 200, 0, 0],387 options: {388 originX: 'right',389 originY: 'bottom',390 }391 },392 expectedCoords: {393 left: 100,394 top: 200,395 }396 },397 ];398 lineCoordsCases.forEach(function (c_) {399 test('stroke-less line coords ' + c_.description, function() {400 var points = c_.givenLineArgs.points;401 var options = c_.givenLineArgs.options;402 var givenLine = new fabric.Line(403 points,404 options405 );406 equal(givenLine.left, c_.expectedCoords.left);407 equal(givenLine.top, c_.expectedCoords.top);408 });409 });410 var getLeftToOriginXCases = [411 { description: 'is x1 for left origin and x1 lesser than x2',412 givenOrigin: 'left',413 givenPoints: [0, 0, 1, 0],414 expectedLeft: 0,415 },416 { description: 'is x2 for left origin and x1 greater than x2',417 givenOrigin: 'left',418 givenPoints: [1, 0, 0, 0],419 expectedLeft: 0,420 },421 { description: 'includes positive offset for left origin',422 givenOrigin: 'left',423 givenPoints: [0+20, 0, 1+20, 0],424 expectedLeft: 0+20,425 },426 { description: 'includes negative offset for left origin',427 givenOrigin: 'left',428 givenPoints: [0-11, 0, 1-11, 0],429 expectedLeft: 0-11,430 },431 { description: 'is half of x1 for center origin and x1 > x2',432 givenOrigin: 'center',433 givenPoints: [4, 0, 0, 0],434 expectedLeft: 0.5 * 4,435 },436 { description: 'is half of x2 for center origin and x1 < x2',437 givenOrigin: 'center',438 givenPoints: [0, 0, 7, 0],439 expectedLeft: 0.5 * 7,440 },441 { description: 'includes positive offset for center origin',442 givenOrigin: 'center',443 givenPoints: [0+39, 0, 7+39, 0],444 expectedLeft: (0.5 * 7) + 39,445 },446 { description: 'includes negative offset for center origin',447 givenOrigin: 'center',448 givenPoints: [4-13, 0, 0-13, 0],449 expectedLeft: (0.5 * 4) - 13,450 },451 { description: 'is x1 for right origin and x1 > x2',452 givenOrigin: 'right',453 givenPoints: [9, 0, 0, 0],454 expectedLeft: 9,455 },456 { description: 'is x2 for right origin and x1 < x2',457 givenOrigin: 'right',458 givenPoints: [0, 0, 6, 0],459 expectedLeft: 6,460 },461 { description: 'includes positive offset for right origin',462 givenOrigin: 'right',463 givenPoints: [0+47, 0, 6+47, 0],464 expectedLeft: 6 + 47,465 },466 { description: 'includes negative offset for right origin',467 givenOrigin: 'right',468 givenPoints: [9-17, 0, 0-17, 0],469 expectedLeft: 9 - 17,470 },471 ];472 getLeftToOriginXCases.forEach(function (c_) {473 test('Line.getLeftToOriginX() ' + c_.description, function () {474 var line = new fabric.Line(475 c_.givenPoints,476 { originX: c_.givenOrigin }477 );478 equal(line._getLeftToOriginX(), c_.expectedLeft);479 });480 });481 var getTopToOriginYCases = [482 { description: 'is y1 for top origin and y1 lesser than y2',483 givenOrigin: 'top',484 givenPoints: [0, 0, 0, 1],485 expectedTop: 0,486 },487 { description: 'is y2 for top origin and y1 greater than y2',488 givenOrigin: 'top',489 givenPoints: [0, 1, 0, 0],490 expectedTop: 0,491 },492 { description: 'includes positive offset for top origin',493 givenOrigin: 'top',494 givenPoints: [0, 0+20, 0, 1+20],495 expectedTop: 0+20,496 },497 { description: 'includes negative offset for top origin',498 givenOrigin: 'top',499 givenPoints: [0, 0-11, 0, 1-11],500 expectedTop: 0-11,501 },502 { description: 'is half of y1 for center origin and y1 > y2',503 givenOrigin: 'center',504 givenPoints: [0, 4, 0, 0],505 expectedTop: 0.5 * 4,506 },507 { description: 'is half of y2 for center origin and y1 < y2',508 givenOrigin: 'center',509 givenPoints: [0, 0, 0, 7],510 expectedTop: 0.5 * 7,511 },512 { description: 'includes positive offset for center origin',513 givenOrigin: 'center',514 givenPoints: [0, 0+39, 0, 7+39],515 expectedTop: (0.5 * 7) + 39,516 },517 { description: 'includes negative offset for center origin',518 givenOrigin: 'center',519 givenPoints: [0, 4-13, 0, 0-13],520 expectedTop: (0.5 * 4) - 13,521 },522 { description: 'is y1 for bottom origin and y1 > y2',523 givenOrigin: 'bottom',524 givenPoints: [0, 9, 0, 0],525 expectedTop: 9,526 },527 { description: 'is y2 for bottom origin and y1 < y2',528 givenOrigin: 'bottom',529 givenPoints: [0, 0, 0, 6],530 expectedTop: 6,531 },532 { description: 'includes positive offset for bottom origin',533 givenOrigin: 'bottom',534 givenPoints: [0, 0+47, 0, 6+47],535 expectedTop: 6 + 47,536 },537 { description: 'includes negative offset for bottom origin',538 givenOrigin: 'bottom',539 givenPoints: [0, 9-17, 0, 0-17],540 expectedTop: 9 - 17,541 },542 ];543 getTopToOriginYCases.forEach(function (c_) {544 test('Line._getTopToOriginY() ' + c_.description, function () {545 var line = new fabric.Line(546 c_.givenPoints,547 { originY: c_.givenOrigin }548 );549 equal(line._getTopToOriginY(), c_.expectedTop);550 });551 });...
dropdown.js
Source:dropdown.js
1(function ($) {2 // Add posibility to scroll to selected option3 // usefull for select for example4 $.fn.scrollTo = function(elem) {5 $(this).scrollTop($(this).scrollTop() - $(this).offset().top + $(elem).offset().top);6 return this;7 };8 $.fn.dropdown = function (option) {9 var defaults = {10 inDuration: 300,11 outDuration: 225,12 constrain_width: true, // Constrains width of dropdown to the activator13 hover: false,14 gutter: 0, // Spacing from edge15 belowOrigin: false,16 alignment: 'left'17 };18 this.each(function(){19 var origin = $(this);20 var options = $.extend({}, defaults, option);21 var isFocused = false;22 // Dropdown menu23 var activates = $("#"+ origin.attr('data-activates'));24 function updateOptions() {25 if (origin.data('induration') !== undefined)26 options.inDuration = origin.data('inDuration');27 if (origin.data('outduration') !== undefined)28 options.outDuration = origin.data('outDuration');29 if (origin.data('constrainwidth') !== undefined)30 options.constrain_width = origin.data('constrainwidth');31 if (origin.data('hover') !== undefined)32 options.hover = origin.data('hover');33 if (origin.data('gutter') !== undefined)34 options.gutter = origin.data('gutter');35 if (origin.data('beloworigin') !== undefined)36 options.belowOrigin = origin.data('beloworigin');37 if (origin.data('alignment') !== undefined)38 options.alignment = origin.data('alignment');39 }40 updateOptions();41 // Attach dropdown to its activator42 origin.after(activates);43 /*44 Helper function to position and resize dropdown.45 Used in hover and click handler.46 */47 function placeDropdown(eventType) {48 // Check for simultaneous focus and click events.49 if (eventType === 'focus') {50 isFocused = true;51 }52 // Check html data attributes53 updateOptions();54 // Set Dropdown state55 activates.addClass('active');56 origin.addClass('active');57 // Constrain width58 if (options.constrain_width === true) {59 activates.css('width', origin.outerWidth());60 } else {61 activates.css('white-space', 'nowrap');62 }63 // Offscreen detection64 var windowHeight = window.innerHeight;65 var originHeight = origin.innerHeight();66 var offsetLeft = origin.offset().left;67 var offsetTop = origin.offset().top - $(window).scrollTop();68 var currAlignment = options.alignment;69 var activatesLeft, gutterSpacing;70 // Below Origin71 var verticalOffset = 0;72 if (options.belowOrigin === true) {73 verticalOffset = originHeight;74 }75 if (offsetLeft + activates.innerWidth() > $(window).width()) {76 // Dropdown goes past screen on right, force right alignment77 currAlignment = 'right';78 } else if (offsetLeft - activates.innerWidth() + origin.innerWidth() < 0) {79 // Dropdown goes past screen on left, force left alignment80 currAlignment = 'left';81 }82 // Vertical bottom offscreen detection83 if (offsetTop + activates.innerHeight() > windowHeight) {84 // If going upwards still goes offscreen, just crop height of dropdown.85 if (offsetTop + originHeight - activates.innerHeight() < 0) {86 var adjustedHeight = windowHeight - offsetTop - verticalOffset;87 activates.css('max-height', adjustedHeight);88 } else {89 // Flow upwards.90 if (!verticalOffset) {91 verticalOffset += originHeight;92 }93 verticalOffset -= activates.innerHeight();94 }95 }96 // Handle edge alignment97 if (currAlignment === 'left') {98 gutterSpacing = options.gutter;99 leftPosition = origin.position().left + gutterSpacing;100 }101 else if (currAlignment === 'right') {102 var offsetRight = origin.position().left + origin.outerWidth() - activates.outerWidth();103 gutterSpacing = -options.gutter;104 leftPosition = offsetRight + gutterSpacing;105 }106 // Position dropdown107 activates.css({108 position: 'absolute',109 top: origin.position().top + verticalOffset,110 left: leftPosition111 });112 // Show dropdown113 activates.stop(true, true).css('opacity', 0)114 .slideDown({115 queue: false,116 duration: options.inDuration,117 easing: 'easeOutCubic',118 complete: function() {119 $(this).css('height', '');120 }121 })122 .animate( {opacity: 1}, {queue: false, duration: options.inDuration, easing: 'easeOutSine'});123 }124 function hideDropdown() {125 // Check for simultaneous focus and click events.126 isFocused = false;127 activates.fadeOut(options.outDuration);128 activates.removeClass('active');129 origin.removeClass('active');130 setTimeout(function() { activates.css('max-height', ''); }, options.outDuration);131 }132 // Hover133 if (options.hover) {134 var open = false;135 origin.unbind('click.' + origin.attr('id'));136 // Hover handler to show dropdown137 origin.on('mouseenter', function(e){ // Mouse over138 if (open === false) {139 placeDropdown();140 open = true;141 }142 });143 origin.on('mouseleave', function(e){144 // If hover on origin then to something other than dropdown content, then close145 var toEl = e.toElement || e.relatedTarget; // added browser compatibility for target element146 if(!$(toEl).closest('.dropdown-content').is(activates)) {147 activates.stop(true, true);148 hideDropdown();149 open = false;150 }151 });152 activates.on('mouseleave', function(e){ // Mouse out153 var toEl = e.toElement || e.relatedTarget;154 if(!$(toEl).closest('.dropdown-button').is(origin)) {155 activates.stop(true, true);156 hideDropdown();157 open = false;158 }159 });160 // Click161 } else {162 // Click handler to show dropdown163 origin.unbind('click.' + origin.attr('id'));164 origin.bind('click.'+origin.attr('id'), function(e){165 if (!isFocused) {166 if ( origin[0] == e.currentTarget &&167 !origin.hasClass('active') &&168 ($(e.target).closest('.dropdown-content').length === 0)) {169 e.preventDefault(); // Prevents button click from moving window170 placeDropdown('click');171 }172 // If origin is clicked and menu is open, close menu173 else if (origin.hasClass('active')) {174 hideDropdown();175 $(document).unbind('click.'+ activates.attr('id') + ' touchstart.' + activates.attr('id'));176 }177 // If menu open, add click close handler to document178 if (activates.hasClass('active')) {179 $(document).bind('click.'+ activates.attr('id') + ' touchstart.' + activates.attr('id'), function (e) {180 if (!activates.is(e.target) && !origin.is(e.target) && (!origin.find(e.target).length) ) {181 hideDropdown();182 $(document).unbind('click.'+ activates.attr('id') + ' touchstart.' + activates.attr('id'));183 }184 });185 }186 }187 });188 } // End else189 // Listen to open and close event - useful for select component190 origin.on('open', function(e, eventType) {191 placeDropdown(eventType);192 });193 origin.on('close', hideDropdown);194 });195 }; // End dropdown plugin196 $(document).ready(function(){197 $('.dropdown-button').dropdown();198 });...
object_origin.mixin.js
Source:object_origin.mixin.js
1(function() {2 var degreesToRadians = fabric.util.degreesToRadians,3 originXOffset = {4 left: -0.5,5 center: 0,6 right: 0.57 },8 originYOffset = {9 top: -0.5,10 center: 0,11 bottom: 0.512 };13 fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prototype */ {14 /**15 * Translates the coordinates from origin to center coordinates (based on the object's dimensions)16 * @param {fabric.Point} point The point which corresponds to the originX and originY params17 * @param {String} fromOriginX Horizontal origin: 'left', 'center' or 'right'18 * @param {String} fromOriginY Vertical origin: 'top', 'center' or 'bottom'19 * @param {String} toOriginX Horizontal origin: 'left', 'center' or 'right'20 * @param {String} toOriginY Vertical origin: 'top', 'center' or 'bottom'21 * @return {fabric.Point}22 */23 translateToGivenOrigin: function(point, fromOriginX, fromOriginY, toOriginX, toOriginY) {24 var x = point.x,25 y = point.y,26 offsetX = originXOffset[toOriginX] - originXOffset[fromOriginX],27 offsetY = originYOffset[toOriginY] - originYOffset[fromOriginY],28 dim;29 if (offsetX || offsetY) {30 dim = this._getTransformedDimensions();31 x = point.x + offsetX * dim.x;32 y = point.y + offsetY * dim.y;33 }34 return new fabric.Point(x, y);35 },36 /**37 * Translates the coordinates from origin to center coordinates (based on the object's dimensions)38 * @param {fabric.Point} point The point which corresponds to the originX and originY params39 * @param {String} originX Horizontal origin: 'left', 'center' or 'right'40 * @param {String} originY Vertical origin: 'top', 'center' or 'bottom'41 * @return {fabric.Point}42 */43 translateToCenterPoint: function(point, originX, originY) {44 var p = this.translateToGivenOrigin(point, originX, originY, 'center', 'center');45 if (this.angle) {46 return fabric.util.rotatePoint(p, point, degreesToRadians(this.angle));47 }48 return p;49 },50 /**51 * Translates the coordinates from center to origin coordinates (based on the object's dimensions)52 * @param {fabric.Point} center The point which corresponds to center of the object53 * @param {String} originX Horizontal origin: 'left', 'center' or 'right'54 * @param {String} originY Vertical origin: 'top', 'center' or 'bottom'55 * @return {fabric.Point}56 */57 translateToOriginPoint: function(center, originX, originY) {58 var p = this.translateToGivenOrigin(center, 'center', 'center', originX, originY);59 if (this.angle) {60 return fabric.util.rotatePoint(p, center, degreesToRadians(this.angle));61 }62 return p;63 },64 /**65 * Returns the real center coordinates of the object66 * @return {fabric.Point}67 */68 getCenterPoint: function() {69 var leftTop = new fabric.Point(this.left, this.top);70 return this.translateToCenterPoint(leftTop, this.originX, this.originY);71 },72 /**73 * Returns the coordinates of the object based on center coordinates74 * @param {fabric.Point} point The point which corresponds to the originX and originY params75 * @return {fabric.Point}76 */77 // getOriginPoint: function(center) {78 // return this.translateToOriginPoint(center, this.originX, this.originY);79 // },80 /**81 * Returns the coordinates of the object as if it has a different origin82 * @param {String} originX Horizontal origin: 'left', 'center' or 'right'83 * @param {String} originY Vertical origin: 'top', 'center' or 'bottom'84 * @return {fabric.Point}85 */86 getPointByOrigin: function(originX, originY) {87 var center = this.getCenterPoint();88 return this.translateToOriginPoint(center, originX, originY);89 },90 /**91 * Returns the point in local coordinates92 * @param {fabric.Point} point The point relative to the global coordinate system93 * @param {String} originX Horizontal origin: 'left', 'center' or 'right'94 * @param {String} originY Vertical origin: 'top', 'center' or 'bottom'95 * @return {fabric.Point}96 */97 toLocalPoint: function(point, originX, originY) {98 var center = this.getCenterPoint(),99 p, p2;100 if (originX && originY) {101 p = this.translateToGivenOrigin(center, 'center', 'center', originX, originY);102 }103 else {104 p = new fabric.Point(this.left, this.top);105 }106 p2 = new fabric.Point(point.x, point.y);107 if (this.angle) {108 p2 = fabric.util.rotatePoint(p2, center, -degreesToRadians(this.angle));109 }110 return p2.subtractEquals(p);111 },112 /**113 * Returns the point in global coordinates114 * @param {fabric.Point} The point relative to the local coordinate system115 * @return {fabric.Point}116 */117 // toGlobalPoint: function(point) {118 // return fabric.util.rotatePoint(point, this.getCenterPoint(), degreesToRadians(this.angle)).addEquals(new fabric.Point(this.left, this.top));119 // },120 /**121 * Sets the position of the object taking into consideration the object's origin122 * @param {fabric.Point} pos The new position of the object123 * @param {String} originX Horizontal origin: 'left', 'center' or 'right'124 * @param {String} originY Vertical origin: 'top', 'center' or 'bottom'125 * @return {void}126 */127 setPositionByOrigin: function(pos, originX, originY) {128 var center = this.translateToCenterPoint(pos, originX, originY),129 position = this.translateToOriginPoint(center, this.originX, this.originY);130 this.set('left', position.x);131 this.set('top', position.y);132 },133 /**134 * @param {String} to One of 'left', 'center', 'right'135 */136 adjustPosition: function(to) {137 var angle = degreesToRadians(this.angle),138 hypotFull = this.getWidth(),139 xFull = Math.cos(angle) * hypotFull,140 yFull = Math.sin(angle) * hypotFull;141 //TODO: this function does not consider mixed situation like top, center.142 this.left += xFull * (originXOffset[to] - originXOffset[this.originX]);143 this.top += yFull * (originXOffset[to] - originXOffset[this.originX]);144 this.setCoords();145 this.originX = to;146 },147 /**148 * Sets the origin/position of the object to it's center point149 * @private150 * @return {void}151 */152 _setOriginToCenter: function() {153 this._originalOriginX = this.originX;154 this._originalOriginY = this.originY;155 var center = this.getCenterPoint();156 this.originX = 'center';157 this.originY = 'center';158 this.left = center.x;159 this.top = center.y;160 },161 /**162 * Resets the origin/position of the object to it's original origin163 * @private164 * @return {void}165 */166 _resetOrigin: function() {167 var originPoint = this.translateToOriginPoint(168 this.getCenterPoint(),169 this._originalOriginX,170 this._originalOriginY);171 this.originX = this._originalOriginX;172 this.originY = this._originalOriginY;173 this.left = originPoint.x;174 this.top = originPoint.y;175 this._originalOriginX = null;176 this._originalOriginY = null;177 },178 /**179 * @private180 */181 _getLeftTopCoords: function() {182 return this.translateToOriginPoint(this.getCenterPoint(), 'left', 'top');183 }184 });...
Origin.js
Source:Origin.js
1/**2 * @author Richard Davey <rich@photonstorm.com>3 * @copyright 2018 Photon Storm Ltd.4 * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}5 */6/**7 * Provides methods used for getting and setting the origin of a Game Object.8 * Values are normalized, given in the range 0 to 1.9 * Display values contain the calculated pixel values.10 * Should be applied as a mixin and not used directly.11 *12 * @name Phaser.GameObjects.Components.Origin13 * @since 3.0.014 */15var Origin = {16 /**17 * A property indicating that a Game Object has this component.18 *19 * @name Phaser.GameObjects.Components.Origin#_originComponent20 * @type {boolean}21 * @private22 * @default true23 * @since 3.2.024 */25 _originComponent: true,26 /**27 * The horizontal origin of this Game Object.28 * The origin maps the relationship between the size and position of the Game Object.29 * The default value is 0.5, meaning all Game Objects are positioned based on their center.30 * Setting the value to 0 means the position now relates to the left of the Game Object.31 *32 * @name Phaser.GameObjects.Components.Origin#originX33 * @type {float}34 * @default 0.535 * @since 3.0.036 */37 originX: 0.5,38 /**39 * The vertical origin of this Game Object.40 * The origin maps the relationship between the size and position of the Game Object.41 * The default value is 0.5, meaning all Game Objects are positioned based on their center.42 * Setting the value to 0 means the position now relates to the top of the Game Object.43 *44 * @name Phaser.GameObjects.Components.Origin#originY45 * @type {float}46 * @default 0.547 * @since 3.0.048 */49 originY: 0.5,50 // private + read only51 _displayOriginX: 0,52 _displayOriginY: 0,53 /**54 * The horizontal display origin of this Game Object.55 * The origin is a normalized value between 0 and 1.56 * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin.57 *58 * @name Phaser.GameObjects.Components.Origin#displayOriginX59 * @type {float}60 * @since 3.0.061 */62 displayOriginX: {63 get: function ()64 {65 return this._displayOriginX;66 },67 set: function (value)68 {69 this._displayOriginX = value;70 this.originX = value / this.width;71 }72 },73 /**74 * The vertical display origin of this Game Object.75 * The origin is a normalized value between 0 and 1.76 * The displayOrigin is a pixel value, based on the size of the Game Object combined with the origin.77 *78 * @name Phaser.GameObjects.Components.Origin#displayOriginY79 * @type {float}80 * @since 3.0.081 */82 displayOriginY: {83 get: function ()84 {85 return this._displayOriginY;86 },87 set: function (value)88 {89 this._displayOriginY = value;90 this.originY = value / this.height;91 }92 },93 /**94 * Sets the origin of this Game Object.95 *96 * The values are given in the range 0 to 1.97 *98 * @method Phaser.GameObjects.Components.Origin#setOrigin99 * @since 3.0.0100 *101 * @param {number} [x=0.5] - The horizontal origin value.102 * @param {number} [y=x] - The vertical origin value. If not defined it will be set to the value of `x`.103 *104 * @return {Phaser.GameObjects.GameObject} This Game Object instance.105 */106 setOrigin: function (x, y)107 {108 if (x === undefined) { x = 0.5; }109 if (y === undefined) { y = x; }110 this.originX = x;111 this.originY = y;112 return this.updateDisplayOrigin();113 },114 /**115 * Sets the origin of this Game Object based on the Pivot values in its Frame.116 *117 * @method Phaser.GameObjects.Components.Origin#setOriginFromFrame118 * @since 3.0.0119 *120 * @return {Phaser.GameObjects.GameObject} This Game Object instance.121 */122 setOriginFromFrame: function ()123 {124 if (!this.frame || !this.frame.customPivot)125 {126 return this.setOrigin();127 }128 else129 {130 this.originX = this.frame.pivotX;131 this.originY = this.frame.pivotY;132 }133 return this.updateDisplayOrigin();134 },135 /**136 * Sets the display origin of this Game Object.137 * The difference between this and setting the origin is that you can use pixel values for setting the display origin.138 *139 * @method Phaser.GameObjects.Components.Origin#setDisplayOrigin140 * @since 3.0.0141 *142 * @param {number} [x=0] - The horizontal display origin value.143 * @param {number} [y=x] - The vertical display origin value. If not defined it will be set to the value of `x`.144 *145 * @return {Phaser.GameObjects.GameObject} This Game Object instance.146 */147 setDisplayOrigin: function (x, y)148 {149 if (x === undefined) { x = 0; }150 if (y === undefined) { y = x; }151 this.displayOriginX = x;152 this.displayOriginY = y;153 return this;154 },155 /**156 * Updates the Display Origin cached values internally stored on this Game Object.157 * You don't usually call this directly, but it is exposed for edge-cases where you may.158 *159 * @method Phaser.GameObjects.Components.Origin#updateDisplayOrigin160 * @since 3.0.0161 *162 * @return {Phaser.GameObjects.GameObject} This Game Object instance.163 */164 updateDisplayOrigin: function ()165 {166 this._displayOriginX = Math.round(this.originX * this.width);167 this._displayOriginY = Math.round(this.originY * this.height);168 return this;169 }170};...
cors_spec.js
Source:cors_spec.js
1var sinon = require('sinon'),2 should = require('should'),3 rewire = require('rewire'),4 configUtils = require('../../utils/configUtils'),5 cors = rewire('../../../server/middleware/cors');6describe('cors', function () {7 var res, req, next, sandbox;8 beforeEach(function () {9 sandbox = sinon.sandbox.create();10 req = {11 headers: {12 origin: null13 },14 client: {15 trustedDomains: []16 }17 };18 res = {19 headers: {},20 getHeader: function () {},21 setHeader: function (h, v) {22 this.headers[h] = v;23 }24 };25 next = sandbox.spy();26 });27 afterEach(function () {28 sandbox.restore();29 configUtils.restore();30 cors = rewire('../../../server/middleware/cors');31 });32 it('should not be enabled without a request origin header', function (done) {33 req.get = sinon.stub().withArgs('origin').returns(null);34 cors(req, res, next);35 next.called.should.be.true();36 should.not.exist(res.headers['Access-Control-Allow-Origin']);37 done();38 });39 it('should be enabled when origin is 127.0.0.1', function (done) {40 var origin = 'http://127.0.0.1:2368';41 req.get = sinon.stub().withArgs('origin').returns(origin);42 res.get = sinon.stub().withArgs('origin').returns(origin);43 req.headers.origin = origin;44 cors(req, res, next);45 next.called.should.be.true();46 res.headers['Access-Control-Allow-Origin'].should.equal(origin);47 done();48 });49 it('should be enabled when origin is localhost', function (done) {50 var origin = 'http://localhost:2368';51 req.get = sinon.stub().withArgs('origin').returns(origin);52 res.get = sinon.stub().withArgs('origin').returns(origin);53 req.headers.origin = origin;54 cors(req, res, next);55 next.called.should.be.true();56 res.headers['Access-Control-Allow-Origin'].should.equal(origin);57 done();58 });59 it('should be enabled when origin is a client_trusted_domain', function (done) {60 var origin = 'http://my-trusted-domain.com';61 req.client.trustedDomains.push({trusted_domain: origin});62 req.get = sinon.stub().withArgs('origin').returns(origin);63 res.get = sinon.stub().withArgs('origin').returns(origin);64 req.headers.origin = origin;65 cors(req, res, next);66 next.called.should.be.true();67 res.headers['Access-Control-Allow-Origin'].should.equal(origin);68 done();69 });70 it('should be enabled when there are multiple trusted domains', function (done) {71 var origin = 'http://my-other-trusted-domain.com';72 req.client.trustedDomains.push({trusted_domain: origin});73 req.client.trustedDomains.push({trusted_domain: 'http://my-trusted-domain.com'});74 req.get = sinon.stub().withArgs('origin').returns(origin);75 res.get = sinon.stub().withArgs('origin').returns(origin);76 req.headers.origin = origin;77 cors(req, res, next);78 next.called.should.be.true();79 res.headers['Access-Control-Allow-Origin'].should.equal(origin);80 done();81 });82 it('should not be enabled the origin is not trusted or whitelisted', function (done) {83 var origin = 'http://not-trusted.com';84 req.client.trustedDomains.push({trusted_domain: 'http://example.com'});85 req.get = sinon.stub().withArgs('origin').returns(origin);86 res.get = sinon.stub().withArgs('origin').returns(origin);87 req.headers.origin = origin;88 cors(req, res, next);89 next.called.should.be.true();90 should.not.exist(res.headers['Access-Control-Allow-Origin']);91 done();92 });93 it('should not be enabled the origin client_trusted_domains is empty', function (done) {94 var origin = 'http://example.com';95 req.get = sinon.stub().withArgs('origin').returns(origin);96 res.get = sinon.stub().withArgs('origin').returns(origin);97 req.headers.origin = origin;98 cors(req, res, next);99 next.called.should.be.true();100 should.not.exist(res.headers['Access-Control-Allow-Origin']);101 done();102 });103 it('should be enabled if the origin matches config.url', function (done) {104 var origin = 'http://my.blog';105 configUtils.set({106 url: origin107 });108 req.get = sinon.stub().withArgs('origin').returns(origin);109 res.get = sinon.stub().withArgs('origin').returns(origin);110 req.headers.origin = origin;111 cors(req, res, next);112 next.called.should.be.true();113 res.headers['Access-Control-Allow-Origin'].should.equal(origin);114 done();115 });116 it('should be enabled if the origin matches config.urlSSL', function (done) {117 var origin = 'https://secure.blog';118 configUtils.set({119 url: 'http://my.blog',120 urlSSL: origin121 });122 req.get = sinon.stub().withArgs('origin').returns(origin);123 res.get = sinon.stub().withArgs('origin').returns(origin);124 req.headers.origin = origin;125 cors(req, res, next);126 next.called.should.be.true();127 res.headers['Access-Control-Allow-Origin'].should.equal(origin);128 done();129 });...
SecurityOriginManager.js
Source:SecurityOriginManager.js
1// Copyright 2016 The Chromium Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4/**5 * @constructor6 * @extends {WebInspector.SDKModel}7 * @param {!WebInspector.Target} target8 */9WebInspector.SecurityOriginManager = function(target)10{11 WebInspector.SDKModel.call(this, WebInspector.SecurityOriginManager, target);12 this._securityOriginCounter = new Map();13 this._mainSecurityOrigin = "";14}15/** @enum {symbol} */16WebInspector.SecurityOriginManager.Events = {17 SecurityOriginAdded: Symbol("SecurityOriginAdded"),18 SecurityOriginRemoved: Symbol("SecurityOriginRemoved"),19 MainSecurityOriginChanged: Symbol("MainSecurityOriginChanged")20}21/**22 * @param {!WebInspector.Target} target23 * @return {!WebInspector.SecurityOriginManager}24 */25WebInspector.SecurityOriginManager.fromTarget = function(target)26{27 var securityOriginManager = /** @type {?WebInspector.SecurityOriginManager} */ (target.model(WebInspector.SecurityOriginManager));28 if (!securityOriginManager)29 securityOriginManager = new WebInspector.SecurityOriginManager(target);30 return securityOriginManager;31}32WebInspector.SecurityOriginManager.prototype = {33 /**34 * @param {string} securityOrigin35 */36 addSecurityOrigin: function(securityOrigin)37 {38 var currentCount = this._securityOriginCounter.get(securityOrigin);39 if (!currentCount) {40 this._securityOriginCounter.set(securityOrigin, 1);41 this.dispatchEventToListeners(WebInspector.SecurityOriginManager.Events.SecurityOriginAdded, securityOrigin);42 return;43 }44 this._securityOriginCounter.set(securityOrigin, currentCount + 1);45 },46 /**47 * @param {string} securityOrigin48 */49 removeSecurityOrigin: function(securityOrigin)50 {51 var currentCount = this._securityOriginCounter.get(securityOrigin);52 if (currentCount === 1) {53 this._securityOriginCounter.delete(securityOrigin);54 this.dispatchEventToListeners(WebInspector.SecurityOriginManager.Events.SecurityOriginRemoved, securityOrigin);55 return;56 }57 this._securityOriginCounter.set(securityOrigin, currentCount - 1);58 },59 /**60 * @return {!Array<string>}61 */62 securityOrigins: function()63 {64 return this._securityOriginCounter.keysArray();65 },66 /**67 * @return {string}68 */69 mainSecurityOrigin: function()70 {71 return this._mainSecurityOrigin;72 },73 /**74 * @param {string} securityOrigin75 */76 setMainSecurityOrigin: function(securityOrigin)77 {78 this._mainSecurityOrigin = securityOrigin;79 this.dispatchEventToListeners(WebInspector.SecurityOriginManager.Events.MainSecurityOriginChanged, securityOrigin);80 },81 __proto__: WebInspector.SDKModel.prototype...
auto-test-perspective-origin-checks.js
Source:auto-test-perspective-origin-checks.js
1timing_test(function() {2 at(0 * 1000, function() {3 assert_styles(".test",{'perspectiveOrigin':'50px 50px'});4 });5 at(0.5 * 1000, function() {6 assert_styles(".test", [7 {'perspectiveOrigin':'37.5px 37.5px'},8 {'perspectiveOrigin':'37.5px 50px'},9 {'perspectiveOrigin':'62.5px 50px'},10 {'perspectiveOrigin':'50px 37.5px'},11 {'perspectiveOrigin':'50px 62.5px'},12 {'perspectiveOrigin':'50px 50px'},13 {'perspectiveOrigin':'37.5px 37.5px'},14 {'perspectiveOrigin':'57.5px 57.5px'},15 {'perspectiveOrigin':'42.5px 52.5px'},16 {'perspectiveOrigin':'37.5px 62.5px'},17 ]);18 });19 at(1 * 1000, function() {20 assert_styles(".test", [21 {'perspectiveOrigin':'25px 25px'},22 {'perspectiveOrigin':'25px 50px'},23 {'perspectiveOrigin':'75px 50px'},24 {'perspectiveOrigin':'50px 25px'},25 {'perspectiveOrigin':'50px 75px'},26 {'perspectiveOrigin':'50px 50px'},27 {'perspectiveOrigin':'25px 25px'},28 {'perspectiveOrigin':'65px 65px'},29 {'perspectiveOrigin':'35px 55px'},30 {'perspectiveOrigin':'25px 75px'},31 ]);32 });33 at(1.5 * 1000, function() {34 assert_styles(".test", [35 {'perspectiveOrigin':'12.5px 12.5px'},36 {'perspectiveOrigin':'12.5px 50px'},37 {'perspectiveOrigin':'87.5px 50px'},38 {'perspectiveOrigin':'50px 12.5px'},39 {'perspectiveOrigin':'50px 87.5px'},40 {'perspectiveOrigin':'50px 50px'},41 {'perspectiveOrigin':'12.5px 12.5px'},42 {'perspectiveOrigin':'72.5px 72.5px'},43 {'perspectiveOrigin':'27.5px 57.5px'},44 {'perspectiveOrigin':'12.5px 87.5px'},45 ]);46 });47 at(2 * 1000, function() {48 assert_styles(".test", [49 {'perspectiveOrigin':'0px 0px'},50 {'perspectiveOrigin':'0px 50px'},51 {'perspectiveOrigin':'100px 50px'},52 {'perspectiveOrigin':'50px 0px'},53 {'perspectiveOrigin':'50px 100px'},54 {'perspectiveOrigin':'50px 50px'},55 {'perspectiveOrigin':'0px 0px'},56 {'perspectiveOrigin':'80px 80px'},57 {'perspectiveOrigin':'20px 60px'},58 {'perspectiveOrigin':'0px 100px'},59 ]);60 });...
UserSearchService.js
Source:UserSearchService.js
1module.exports = {2 newUserMapSearch(user, origin, destination) {3 sails.log.debug('Creating new user map search: ')4 return UserSearch.create({5 user: user.id,6 originAirportName: origin.airportName,7 originAirportCity: origin.name,8 originAirportCityId: origin.airportCityId,9 originAirportCountry: origin.countryName,10 originAirportCountryCode: origin.countryId,11 originAirportCurrency: origin.currency,12 originAirportId: origin.airportId,13 originAirportIataOrFaaCode: origin.iataCode,14 originAirportIcaoCode: origin.IcaoCode,15 originAirportLatitude: origin.airportPos.lat,16 originAirportLongitude: origin.airportPos.lng,17 originAirportContinent: origin.continentName,18 originAirportContinentId: origin.continentId,19 destinationAirportName: destination.airportName,20 destinationAirportCity: destination.name,21 destinationAirportCityId: destination.airportCityId,22 destinationAirportCountry: destination.countryName,23 destinationAirportCountryCode: destination.countryId,24 destinationAirportCurrency: destination.currency,25 destinationAirportId: destination.airportId,26 destinationAirportIataOrFaaCode: destination.iataCode,27 destinationAirportIcaoCode: destination.IcaoCode,28 destinationAirportLatitude: destination.airportPos.lat,29 destinationAirportLongitude: destination.airportPos.lng,30 destinationAirportContinent: destination.continentName,31 destinationAirportContinentId: destination.continentId32 }).then(function (result) {33 return Promise.resolve(result)34 }).catch(function (err) {35 sails.log.error(err)36 return Promise.reject(err)37 })38 }...
Using AI Code Generation
1describe('My First Test', () => {2 it('Does not do much!', () => {3 cy.contains('type').click()4 cy.url().should('include', '/commands/actions')5 cy.get('.action-email')6 .type('
Using AI Code Generation
1Cypress.on('uncaught:exception', (err, runnable) => {2})3Cypress.on('uncaught:exception', (err, runnable) => {4})5Cypress.on('uncaught:exception', (err, runnable) => {6})7Cypress.on('uncaught:exception', (err, runnable) => {8})9Cypress.on('uncaught:exception', (err, runnable) => {10})11Cypress.on('uncaught:exception', (err, runnable) => {12})13Cypress.on('uncaught:exception', (err, runnable) => {14})15Cypress.on('uncaught:exception', (err, runnable) => {16})17Cypress.on('uncaught:exception', (err, runnable) => {18})19Cypress.on('uncaught:exception', (err, runnable) => {20})21Cypress.on('uncaught:exception', (err, runnable) => {22})23Cypress.on('
Using AI Code Generation
1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.contains('type').click()4 })5})6describe('My First Test', function() {7 it('Does not do much!', function() {8 cy.contains('type').click()9 })10})11describe('My First Test', function() {12 it('Does not do much!', function() {13 cy.contains('type').click()14 })15})16describe('My First Test', function() {17 it('Does not do much!', function() {18 cy.contains('type').click()19 })20})21describe('My First Test', function() {22 it('Does not do much!', function() {23 cy.contains('type').click()24 })25})26describe('My First Test', function() {27 it('Does not do much!', function() {28 cy.contains('type').click()29 })30})31describe('My First Test', function() {32 it('Does not do much!', function() {33 cy.contains('type').click()34 })35})36describe('My First Test', function() {37 it('Does not do much!', function() {38 cy.contains('type').click()39 })40})41describe('My First Test', function() {
Using AI Code Generation
1const webpack = require('@cypress/webpack-preprocessor')2module.exports = (on, config) => {3 const options = {4 webpackOptions: require('../../webpack.config'),5 }6 on('file:preprocessor', webpack(options))7}8const webpack = require('@cypress/webpack-preprocessor')9module.exports = (on, config) => {10 const options = {11 webpackOptions: require('../../webpack.config'),12 }13 on('file:preprocessor', webpack(options))14}15const webpack = require('@cypress/webpack-preprocessor')16module.exports = (on, config) => {17 const options = {18 webpackOptions: require('../../webpack.config'),19 }20 on('file:preprocessor', webpack(options))21}22const webpack = require('@cypress/webpack-preprocessor')23module.exports = (on, config) => {24 const options = {25 webpackOptions: require('../../webpack.config'),26 }27 on('file:preprocessor', webpack(options))28}29const webpack = require('@cypress/webpack-preprocessor')30module.exports = (on, config) => {31 const options = {32 webpackOptions: require('../../webpack.config'),33 }34 on('file:preprocessor', webpack(options))35}36const webpack = require('@cypress/webpack-preprocessor')37module.exports = (on, config) => {38 const options = {39 webpackOptions: require('../../webpack.config'),40 }41 on('file:preprocessor', webpack(options))42}43const webpack = require('@cypress/webpack-preprocessor')44module.exports = (on, config) => {45 const options = {46 webpackOptions: require('../../webpack.config'),
Using AI Code Generation
1 onBeforeLoad (win) {2 },3})4{5}6describe('My First Test', function() {7 it('Does not do much!', function() {8 cy.visit('/')9 })10})11module.exports = (on, config) => {12}13import './commands'
Using AI Code Generation
1cy.get('input[name="q"]').type('cypress{enter}')2cy.get('h3').should('be.visible')3})4{5}6"scripts": {7}8describe('My First Test', () => {9 it('Does not do much!', () => {10 expect(true).to.equal(true)11 })12})13describe('My First Test', () => {14 it('Does not do much!', () => {15 expect(true).to.equal(true)16 })17 it('Visits the Kitchen Sink', () => {18 cy.contains('type').click()19 cy.url().should('include', '/commands/actions')20 cy.get('.action-email')21 .type('
Using AI Code Generation
1cy.get("input#username").type("username");2cy.get("input#password").type("password");3cy.get("button#login").click();4cy.get("div#login").contains("Welcome username!");5cy.get("button#logout").click();6cy.get("div#login").contains("Please login");7});8describe("Login", () => {9it("Should login and logout correctly", () => {10cy.get("input#username").type("username");11cy.get("input#password").type("password");12cy.get("button#login").click();13cy.get("div#login").contains("Welcome username!");14cy.get("button#logout").click();15cy.get("div#login").contains("Please login");16});17});
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!!