Best JavaScript code snippet using cypress
Dock.js
Source:Dock.js
1describe('Ext.layout.component.Dock', function(){2 var ct;3 afterEach(function(){4 Ext.destroy(ct);5 ct = null;6 });7 function makeCt(options, layoutOptions) {8 var failedLayouts = Ext.failedLayouts;9 ct = Ext.widget(Ext.apply({10 xtype: 'panel',11 renderTo: Ext.getBody()12 }, options));13 if (failedLayouts != Ext.failedLayouts) {14 expect('failedLayout=true').toBe('false');15 }16 }17 18 describe("shrink wrapping around docked items", function(){19 20 var top = 'top',21 left = 'left',22 u; // u to be used as undefined23 24 var makeDocked = function(dock, w, h, html) {25 var style = {};26 if (w) {27 style.width = w + 'px';28 }29 30 if (h) {31 style.height = h + 'px';32 }33 34 return new Ext.Component({35 dock: dock,36 shrinkWrap: true,37 style: style,38 html: html39 });40 };41 42 describe("width", function(){43 var makeDocker = function(options){44 return makeCt(Ext.apply({45 shrinkWrap: true,46 border: false,47 bodyBorder: false,48 shrinkWrapDock: 249 }, options)); 50 };51 52 it("should stretch the body width if the docked item is larger", function(){53 makeDocker({54 dockedItems: [55 makeDocked(top, 100, u)56 ],57 html: 'a'58 });59 expect(ct.getWidth()).toBe(100);60 expect(ct.body.getWidth()).toBe(100);61 });62 63 it("should stretch the docked width if the body is larger", function(){64 makeDocker({65 dockedItems: [66 makeDocked(top, u, u, 'a')67 ],68 html: '<div style="width: 100px;"></div>'69 });70 expect(ct.getWidth()).toBe(100);71 expect(ct.getDockedItems()[0].getWidth()).toBe(100);72 });73 74 it("should stretch other docked items to the size of the largest docked item if it is bigger than the body", function(){75 makeDocker({76 dockedItems: [77 makeDocked(top, 100, u),78 makeDocked(top, u, u, 'b')79 ],80 html: 'a'81 });82 expect(ct.getDockedItems()[1].getWidth()).toBe(100);83 });84 85 it("should stretch all docked items to the size of the body if the body is largest", function(){86 makeDocker({87 dockedItems: [88 makeDocked(top, u, u, 'a'),89 makeDocked(top, u, u, 'b')90 ],91 html: '<div style="width: 100px;"></div>'92 });93 expect(ct.getDockedItems()[0].getWidth()).toBe(100);94 expect(ct.getDockedItems()[1].getWidth()).toBe(100);95 });96 97 it("should stretch all items if the body and a single docked item are the largest & same size", function(){98 makeDocker({99 dockedItems: [100 makeDocked(top, 50, u, u),101 makeDocked(top, 100, u, u)102 ],103 html: '<div style="width: 100px;"></div>'104 }); 105 expect(ct.getDockedItems()[0].getWidth()).toBe(100);106 expect(ct.getDockedItems()[1].getWidth()).toBe(100); 107 });108 });109 110 describe("height", function(){111 var makeDocker = function(options){112 return makeCt(Ext.apply({113 shrinkWrap: true,114 border: false,115 bodyBorder: false,116 shrinkWrapDock: 1117 }, options)); 118 };119 120 it("should stretch the body height if the docked item is larger", function(){121 makeDocker({122 dockedItems: [123 makeDocked(left, u, 100)124 ],125 html: 'a'126 });127 expect(ct.getHeight()).toBe(100);128 expect(ct.body.getHeight()).toBe(100);129 });130 131 it("should stretch the docked height if the body is larger", function(){132 makeDocker({133 dockedItems: [134 makeDocked(left, u, u, 'a')135 ],136 html: '<div style="height: 100px;"></div>'137 });138 expect(ct.getHeight()).toBe(100);139 expect(ct.getDockedItems()[0].getHeight()).toBe(100);140 });141 142 it("should stretch other docked items to the size of the largest docked item if it is bigger than the body", function(){143 makeDocker({144 dockedItems: [145 makeDocked(left, u, 100),146 makeDocked(left, u, u, 'b')147 ],148 html: 'a'149 });150 expect(ct.getDockedItems()[1].getHeight()).toBe(100);151 });152 153 it("should stretch all docked items to the size of the body if the body is largest", function(){154 makeDocker({155 dockedItems: [156 makeDocked(left, u, u, 'a'),157 makeDocked(left, u, u, 'b')158 ],159 html: '<div style="height: 100px;"></div>'160 });161 expect(ct.getDockedItems()[0].getHeight()).toBe(100);162 expect(ct.getDockedItems()[1].getHeight()).toBe(100);163 });164 165 it("should stretch all items if the body and a single docked item are the largest & same size", function(){166 makeDocker({167 dockedItems: [168 makeDocked(left, u, 50, u),169 makeDocked(left, u, 100, u)170 ],171 html: '<div style="height: 100px;"></div>'172 }); 173 expect(ct.getDockedItems()[0].getHeight()).toBe(100);174 expect(ct.getDockedItems()[1].getHeight()).toBe(100); 175 });176 });177 178 describe("combination", function(){179 var makeDocker = function(options){180 return makeCt(Ext.apply({181 shrinkWrap: true,182 border: false,183 bodyBorder: false,184 shrinkWrapDock: true185 }, options)); 186 };187 188 it("should stretch the body in both dimensions if the docked items are larger", function(){189 makeDocker({190 dockedItems: [191 makeDocked(top, 100, u),192 makeDocked(left, u, 75)193 ],194 html: 'a'195 });196 expect(ct.getWidth()).toBe(100);197 expect(ct.body.getWidth()).toBe(100);198 expect(ct.getHeight()).toBe(75);199 expect(ct.body.getHeight()).toBe(75);200 });201 202 it("should only stretch the width the dimension where the body is smaller", function(){203 makeDocker({204 dockedItems: [205 makeDocked(top, 100, u),206 makeDocked(left, u, 75)207 ],208 html: '<div style="width: 50px; height: 100px;">'209 });210 expect(ct.getWidth()).toBe(100);211 expect(ct.body.getWidth()).toBe(100);212 expect(ct.getHeight()).toBe(100);213 expect(ct.body.getHeight()).toBe(100);214 expect(ct.getDockedItems()[1].getHeight()).toBe(100);215 });216 217 it("should only stretch the height the dimension where the body is smaller", function(){218 makeDocker({219 dockedItems: [220 makeDocked(top, 100, u),221 makeDocked(left, u, 75)222 ],223 html: '<div style="width: 200px; height: 50px;">'224 });225 expect(ct.getHeight()).toBe(75);226 expect(ct.body.getHeight()).toBe(75);227 expect(ct.getWidth()).toBe(200);228 expect(ct.body.getWidth()).toBe(200);229 expect(ct.getDockedItems()[0].getWidth()).toBe(200);230 });231 232 it("should not stretch the body if neither docked item is bigger", function(){233 makeDocker({234 dockedItems: [235 makeDocked(top, 100, u),236 makeDocked(left, u, 75)237 ],238 html: '<div style="width: 200px; height: 100px;">'239 });240 expect(ct.getWidth()).toBe(200);241 expect(ct.body.getWidth()).toBe(200);242 expect(ct.getHeight()).toBe(100);243 expect(ct.body.getHeight()).toBe(100);244 expect(ct.getDockedItems()[0].getWidth()).toBe(200);245 expect(ct.getDockedItems()[1].getHeight()).toBe(100);246 });247 });248 249 describe("min/max constraints", function(){250 describe("width", function(){251 var makeDocker = function(options){252 return makeCt(Ext.apply({253 shrinkWrap: true,254 border: false,255 bodyBorder: false,256 shrinkWrapDock: 2257 }, options)); 258 };259 260 it("should constrain to a minWidth", function(){261 makeDocker({262 minWidth: 200,263 dockedItems: [264 makeDocked(top, 100, u)265 ]266 }); 267 expect(ct.getWidth()).toBe(200);268 expect(ct.getDockedItems()[0].getWidth()).toBe(200);269 });270 271 it("should constrain to a maxWidth", function(){272 makeDocker({273 maxWidth: 100,274 dockedItems: [275 makeDocked(top, 200, u)276 ]277 }); 278 expect(ct.getWidth()).toBe(100);279 expect(ct.getDockedItems()[0].getWidth()).toBe(100);280 });281 });282 283 describe("height", function(){284 var makeDocker = function(options){285 return makeCt(Ext.apply({286 shrinkWrap: true,287 border: false,288 bodyBorder: false,289 shrinkWrapDock: 1290 }, options)); 291 };292 293 it("should constrain to a minHeight", function(){294 makeDocker({295 minHeight: 200,296 dockedItems: [297 makeDocked(left, u, 100)298 ]299 }); 300 expect(ct.getHeight()).toBe(200);301 expect(ct.getDockedItems()[0].getHeight()).toBe(200);302 });303 304 it("should constrain to a maxWidth", function(){305 makeDocker({306 maxHeight: 100,307 dockedItems: [308 makeDocked(left, u, 200)309 ]310 }); 311 expect(ct.getHeight()).toBe(100);312 expect(ct.getDockedItems()[0].getHeight()).toBe(100);313 });314 });315 316 describe("combination", function(){317 var makeDocker = function(options){318 return makeCt(Ext.apply({319 shrinkWrap: true,320 border: false,321 bodyBorder: false,322 shrinkWrapDock: true323 }, options)); 324 };325 326 it("should constrain a minHeight & maxWidth", function(){327 makeDocker({328 minHeight: 100,329 maxWidth: 100,330 dockedItems: [331 makeDocked(top, 200, u),332 makeDocked(left, u, 50)333 ]334 }); 335 expect(ct.getWidth()).toBe(100); 336 expect(ct.getHeight()).toBe(100);337 expect(ct.getDockedItems()[0].getWidth()).toBe(100);338 expect(ct.getDockedItems()[1].getHeight()).toBe(100);339 });340 341 it("should constrain a maxHeight & minWidth", function(){342 makeDocker({343 maxHeight: 100,344 minWidth: 100,345 dockedItems: [346 makeDocked(top, 50, u),347 makeDocked(left, u, 200)348 ]349 }); 350 expect(ct.getWidth()).toBe(100); 351 expect(ct.getHeight()).toBe(100);352 expect(ct.getDockedItems()[0].getWidth()).toBe(100);353 expect(ct.getDockedItems()[1].getHeight()).toBe(100);354 });355 356 it("should constrain a minHeight and minWidth", function() {357 makeDocker({358 minHeight: 100,359 minWidth: 100,360 dockedItems: [361 makeDocked(top, 50, u),362 makeDocked(left, u, 50)363 ]364 }); 365 expect(ct.getWidth()).toBe(100); 366 expect(ct.getHeight()).toBe(100);367 expect(ct.getDockedItems()[0].getWidth()).toBe(100);368 expect(ct.getDockedItems()[1].getHeight()).toBe(100);369 });370 371 it("should constrain a maxHeight and maxWidth", function() {372 makeDocker({373 maxHeight: 100,374 maxWidth: 100,375 dockedItems: [376 makeDocked(top, 200, u),377 makeDocked(left, u, 200)378 ]379 }); 380 expect(ct.getWidth()).toBe(100); 381 expect(ct.getHeight()).toBe(100);382 expect(ct.getDockedItems()[0].getWidth()).toBe(100);383 expect(ct.getDockedItems()[1].getHeight()).toBe(100);384 });385 });386 });387 388 });389 describe('interaction within box layout', function(){390 it('should handle stretchmax and minHeight together', function(){391 makeCt({392 width: 100,393 border: false,394 layout: {395 type: 'hbox',396 align: 'stretchmax'397 },398 items: [{399 xtype: 'panel',400 border: false,401 items: {402 xtype: 'component',403 width: 20,404 height: 20,405 style: 'background-color: red'406 },407 dockedItems: [{408 xtype: 'component',409 height: 20,410 dock: 'bottom',411 style: 'background-color: blue'412 }],413 minHeight: 100414 }, {415 xtype: 'component',416 style: 'background-color: yellow',417 height: 200,418 width: 20419 }]420 });421 expect(ct).toHaveLayout({422 el: { w: 100, h: 200 },423 items: {424 0: {425 el: { xywh: '0 0 20 200' },426 items: {427 0: { el: { xywh: '0 0 20 20' } }428 },429 dockedItems: {430 0: { el: { xywh: '0 180 20 20' } }431 }432 },433 1: { el: { xywh: '20 0 20 200' } }434 }435 });436 });437 });438 439 describe("DOM element order", function() {440 var defaultDockedItems = [{441 dock: 'top',442 weight: 0,443 xtype: 'toolbar',444 items: [{445 xtype: 'component',446 html: 'top outer'447 }]448 }, {449 dock: 'left',450 weight: 0,451 xtype: 'toolbar',452 vertical: true,453 items: [{454 xtype: 'component',455 html: 'left outer'456 }]457 }, {458 dock: 'bottom',459 weight: 0,460 xtype: 'toolbar',461 items: [{462 xtype: 'component',463 html: 'bottom outer'464 }]465 }, {466 dock: 'right',467 weight: 0,468 xtype: 'toolbar',469 vertical: true,470 items: [{471 xtype: 'component',472 html: 'right outer'473 }]474 }, {475 xtype: 'toolbar',476 dock: 'top',477 weight: 10,478 items: [{479 xtype: 'component',480 html: 'top inner'481 }]482 }, {483 dock: 'bottom',484 weight: 10,485 xtype: 'toolbar',486 items: [{487 xtype: 'component',488 html: 'bottom inner'489 }]490 }, {491 dock: 'right',492 weight: 10,493 xtype: 'toolbar',494 vertical: true,495 items: [{496 xtype: 'component',497 html: 'right inner'498 }]499 }, {500 dock: 'left',501 weight: 10,502 xtype: 'toolbar',503 vertical: true,504 items: [{505 xtype: 'component',506 html: 'left inner'507 }]508 }];509 510 function makeSuite(config, elOrder, wrapOrder, changeFn, desc) {511 config = config || {};512 elOrder = elOrder || [];513 wrapOrder = wrapOrder || [];514 desc = desc ? desc + ',' : 'panel w/';515 516 var hasHeader = config.title === null ? false : true;517 var numElChildren = elOrder.length;518 var numWrapChildren = wrapOrder.length;519 520 var suiteDesc = desc + (config.title === null ? ' no header' : ' header position: ' + 521 (config.headerPosition || 'left')) + 522 (config.dockedItems === null ? ' no dockedItems' : ' w/ dockedItems') +523 ', frame: ' + !!config.frame + 524 ', tab guards: ' + (config.tabGuard ? 'on' : 'off');525 526 function countChicks(panel, property, expected) {527 var numExpected = expected.length,528 children = panel[property].dom.childNodes,529 child, want, i;530 531 for (i = 0; i < numExpected; i++) {532 child = children[i];533 534 if (child) {535 want = expected[i];536 537 // Number is docked.getAt(x), string is element property name538 if (typeof want === 'number') {539 want = panel.dockedItems.getAt(want);540 }541 else {542 want = panel[want];543 }544 545 expect(child.id).toBe(want.id);546 }547 else {548 fail("DOM child not found at index " + i);549 }550 }551 }552 553 describe(suiteDesc, function() {554 beforeEach(function() {555 var cfg = Ext.apply({556 margin: 20,557 width: 400,558 height: 300,559 collapsible: hasHeader ? true : false,560 animCollapse: false,561 562 title: 'blerg',563 564 dockedItems: defaultDockedItems,565 html: 'zingbong'566 }, config);567 568 makeCt(cfg);569 570 if (changeFn) {571 changeFn(ct);572 }573 });574 575 it("should have " + numElChildren + " children in main el", function() {576 expect(ct.el.dom.childNodes.length).toBe(numElChildren);577 });578 579 it("should have main el children in right order", function() {580 countChicks(ct, 'el', elOrder);581 });582 583 it("should have " + numWrapChildren + " children in bodyWrap el", function() {584 expect(ct.bodyWrap.dom.childNodes.length).toBe(numWrapChildren);585 });586 587 it("should have bodyWrap el children in right order", function() {588 countChicks(ct, 'bodyWrap', wrapOrder);589 });590 591 if (hasHeader) {592 describe("collapsed", function() {593 beforeEach(function() {594 ct.collapse();595 });596 597 it("should have " + numElChildren + " children in main el", function() {598 expect(ct.el.dom.childNodes.length).toBe(numElChildren);599 });600 601 it("should have main el children in right order", function() {602 countChicks(ct, 'el', elOrder);603 });604 605 it("should have " + numWrapChildren + " children in bodyWrap el", function() {606 expect(ct.bodyWrap.dom.childNodes.length).toBe(numWrapChildren);607 });608 609 it("should have bodyWrap el children in right order", function() {610 countChicks(ct, 'bodyWrap', wrapOrder);611 });612 613 describe("expanded", function() {614 beforeEach(function() {615 ct.expand();616 });617 618 it("should have " + numElChildren + " children in main el", function() {619 expect(ct.el.dom.childNodes.length).toBe(numElChildren);620 });621 622 it("should have main el children in right order", function() {623 countChicks(ct, 'el', elOrder);624 });625 626 it("should have " + numWrapChildren + " children in bodyWrap el", function() {627 expect(ct.bodyWrap.dom.childNodes.length).toBe(numWrapChildren);628 });629 630 it("should have bodyWrap el children in right order", function() {631 countChicks(ct, 'bodyWrap', wrapOrder);632 });633 });634 });635 }636 });637 }638 639 // Com-pre-hen-sive is the code word for today640 641 function addHeader(panel, title) {642 panel.setTitle(title || 'foobork');643 }644 645 function addItems(panel, items) {646 items = items || defaultDockedItems;647 648 for (var i = 0, len = items.length; i < len; i++) {649 panel.addDocked(items[i]);650 }651 }652 653 function addHeaderAndItems(panel) {654 addItems(panel);655 addHeader(panel);656 }657 658 // No header659 makeSuite({ title: null, dockedItems: null }, ['bodyWrap'], ['body']);660 makeSuite({ title: null, dockedItems: null, tabGuard: true },661 ['tabGuardBeforeEl', 'bodyWrap', 'tabGuardAfterEl'], ['body']);662 663 // No header but massive eruption of dockedItems664 makeSuite({ title: null }, ['bodyWrap'], [0, 1, 4, 7, 'body', 3, 2, 5, 6]);665 666 // No header, dockedItems plus tabGuards667 makeSuite({ title: null, tabGuard: true },668 ['tabGuardBeforeEl', 'bodyWrap', 'tabGuardAfterEl'],669 [0, 1, 4, 7, 'body', 3, 2, 5, 6]);670 671 // Header position672 makeSuite({ dockedItems: null, headerPosition: 'top' }, [0, 'bodyWrap'], ['body']);673 makeSuite({ dockedItems: null, headerPosition: 'left' }, [0, 'bodyWrap'], ['body']);674 makeSuite({ dockedItems: null, headerPosition: 'right' }, ['bodyWrap', 0], ['body']);675 makeSuite({ dockedItems: null, headerPosition: 'bottom' }, ['bodyWrap', 0], ['body']);676 677 // Header position *and* dockedItems678 makeSuite({ headerPosition: 'top' }, [0, 'bodyWrap'], [1, 2, 5, 8, 'body', 4, 3, 6, 7]);679 makeSuite({ headerPosition: 'left' }, [0, 'bodyWrap'], [1, 2, 5, 8, 'body', 4, 3, 6, 7]);680 makeSuite({ headerPosition: 'right' }, ['bodyWrap', 0], [1, 2, 5, 8, 'body', 4, 3, 6, 7]);681 makeSuite({ headerPosition: 'bottom' }, ['bodyWrap', 0], [1, 2, 5, 8, 'body', 4, 3, 6, 7]);682 683 // Header position with tab guards684 makeSuite({ dockedItems: null, tabGuard: true, headerPosition: 'top' },685 ['tabGuardBeforeEl', 0, 'bodyWrap', 'tabGuardAfterEl'], ['body']);686 makeSuite({ dockedItems: null, tabGuard: true, headerPosition: 'left' },687 ['tabGuardBeforeEl', 0, 'bodyWrap', 'tabGuardAfterEl'], ['body']);688 makeSuite({ dockedItems: null, tabGuard: true, headerPosition: 'right' },689 ['tabGuardBeforeEl', 'bodyWrap', 0, 'tabGuardAfterEl'], ['body']);690 makeSuite({ dockedItems: null, tabGuard: true, headerPosition: 'bottom' },691 ['tabGuardBeforeEl', 'bodyWrap', 0, 'tabGuardAfterEl'], ['body']);692 693 // Header position with tab guards and dockedItems694 makeSuite({ tabGuard: true, headerPosition: 'top' },695 ['tabGuardBeforeEl', 0, 'bodyWrap', 'tabGuardAfterEl'],696 [1, 2, 5, 8, 'body', 4, 3, 6, 7]);697 makeSuite({ tabGuard: true, headerPosition: 'left' },698 ['tabGuardBeforeEl', 0, 'bodyWrap', 'tabGuardAfterEl'],699 [1, 2, 5, 8, 'body', 4, 3, 6, 7]);700 makeSuite({ tabGuard: true, headerPosition: 'right' },701 ['tabGuardBeforeEl', 'bodyWrap', 0, 'tabGuardAfterEl'],702 [1, 2, 5, 8, 'body', 4, 3, 6, 7]);703 makeSuite({ tabGuard: true, headerPosition: 'bottom' },704 ['tabGuardBeforeEl', 'bodyWrap', 0, 'tabGuardAfterEl'],705 [1, 2, 5, 8, 'body', 4, 3, 6, 7]);706 707 // Header added after rendering708 makeSuite({ dockedItems: null, title: null, headerPosition: 'top' },709 [0, 'bodyWrap'], ['body'], addHeader, 'dynamic header 1');710 makeSuite({ dockedItems: null, title: null, headerPosition: 'left' },711 [0, 'bodyWrap'], ['body'], addHeader, 'dynamic header 2');712 makeSuite({ dockedItems: null, title: null, headerPosition: 'right' },713 ['bodyWrap', 0], ['body'], addHeader, 'dynamic header 3');714 makeSuite({ dockedItems: null, title: null, headerPosition: 'bottom' },715 ['bodyWrap', 0], ['body'], addHeader, 'dynamic header 4');716 717 // Header added after rendering onto existing tab guards718 makeSuite({ dockedItems: null, title: null, tabGuard: true, headerPosition: 'top' },719 ['tabGuardBeforeEl', 0, 'bodyWrap', 'tabGuardAfterEl'], ['body'], addHeader,720 'dynamic header 5');721 makeSuite({ dockedItems: null, title: null, tabGuard: true, headerPosition: 'left' },722 ['tabGuardBeforeEl', 0, 'bodyWrap', 'tabGuardAfterEl'], ['body'], addHeader,723 'dynamic header 6');724 makeSuite({ dockedItems: null, title: null, tabGuard: true, headerPosition: 'right' },725 ['tabGuardBeforeEl', 'bodyWrap', 0, 'tabGuardAfterEl'], ['body'], addHeader,726 'dynamic header 7');727 makeSuite({ dockedItems: null, title: null, tabGuard: true, headerPosition: 'bottom' },728 ['tabGuardBeforeEl', 'bodyWrap', 0, 'tabGuardAfterEl'], ['body'], addHeader,729 'dynamic header 8');730 731 // Header added after rendering onto existing tab guards and dockedItems732 makeSuite({ title: null, tabGuard: true, headerPosition: 'top' },733 ['tabGuardBeforeEl', 0, 'bodyWrap', 'tabGuardAfterEl'],734 [1, 2, 5, 8, 'body', 4, 3, 6, 7], addHeader, 'dynamic header 9');735 makeSuite({ title: null, tabGuard: true, headerPosition: 'left' },736 ['tabGuardBeforeEl', 0, 'bodyWrap', 'tabGuardAfterEl'],737 [1, 2, 5, 8, 'body', 4, 3, 6, 7], addHeader, 'dynamic header 10');738 makeSuite({ title: null, tabGuard: true, headerPosition: 'right' },739 ['tabGuardBeforeEl', 'bodyWrap', 0, 'tabGuardAfterEl'],740 [1, 2, 5, 8, 'body', 4, 3, 6, 7], addHeader, 'dynamic header 11');741 makeSuite({ title: null, tabGuard: true, headerPosition: 'bottom' },742 ['tabGuardBeforeEl', 'bodyWrap', 0, 'tabGuardAfterEl'], 743 [1, 2, 5, 8, 'body', 4, 3, 6, 7], addHeader, 'dynamic header 12');744 745 // Finally, dynamically added dockedItems. One by one. Ha!746 makeSuite({ dockedItems: null, tabGuard: true, headerPosition: 'top' },747 ['tabGuardBeforeEl', 0, 'bodyWrap', 'tabGuardAfterEl'],748 [1, 2, 5, 8, 'body', 4, 3, 6, 7], addItems, 'dynamic items 1');749 makeSuite({ dockedItems: null, tabGuard: true, headerPosition: 'left' },750 ['tabGuardBeforeEl', 0, 'bodyWrap', 'tabGuardAfterEl'],751 [1, 2, 5, 8, 'body', 4, 3, 6, 7], addItems, 'dynamic items 2');752 makeSuite({ dockedItems: null, tabGuard: true, headerPosition: 'right' },753 ['tabGuardBeforeEl', 'bodyWrap', 0, 'tabGuardAfterEl'],754 [1, 2, 5, 8, 'body', 4, 3, 6, 7], addItems, 'dynamic items 3');755 makeSuite({ dockedItems: null, tabGuard: true, headerPosition: 'bottom' },756 ['tabGuardBeforeEl', 'bodyWrap', 0, 'tabGuardAfterEl'],757 [1, 2, 5, 8, 'body', 4, 3, 6, 7], addItems, 'dynamic items 4');758 759 // All together now.760 makeSuite({ title: null, dockedItems: null, tabGuard: true, headerPosition: 'top' },761 ['tabGuardBeforeEl', 0, 'bodyWrap', 'tabGuardAfterEl'],762 [1, 2, 5, 8, 'body', 4, 3, 6, 7], addHeaderAndItems, 'dynamic items 5');763 makeSuite({ title: null, dockedItems: null, tabGuard: true, headerPosition: 'left' },764 ['tabGuardBeforeEl', 0, 'bodyWrap', 'tabGuardAfterEl'],765 [1, 2, 5, 8, 'body', 4, 3, 6, 7], addHeaderAndItems, 'dynamic items 6');766 makeSuite({ title: null, dockedItems: null, tabGuard: true, headerPosition: 'right' },767 ['tabGuardBeforeEl', 'bodyWrap', 0, 'tabGuardAfterEl'],768 [1, 2, 5, 8, 'body', 4, 3, 6, 7], addHeaderAndItems, 'dynamic items 7');769 makeSuite({ title: null, dockedItems: null, tabGuard: true, headerPosition: 'bottom' },770 ['tabGuardBeforeEl', 'bodyWrap', 0, 'tabGuardAfterEl'],771 [1, 2, 5, 8, 'body', 4, 3, 6, 7], addHeaderAndItems, 'dynamic items 8');772 773 // IE8 gets framed774 if (!Ext.supports.CSS3BorderRadius) {775 // No header776 makeSuite({ frame: true, title: null, dockedItems: null },777 ['frameTL', 'frameML', 'frameBL'], ['body']);778 makeSuite({ frame: true, title: null, dockedItems: null, tabGuard: true },779 ['tabGuardBeforeEl', 'frameTL', 'frameML', 'frameBL', 'tabGuardAfterEl'],780 ['body']);781 // No header but massive eruption of dockedItems782 makeSuite({ frame: true, title: null }, ['frameTL', 'frameML', 'frameBL'],783 [0, 1, 4, 7, 'body', 3, 2, 5, 6]);784 785 // No header, dockedItems plus tabGuards786 makeSuite({ frame: true, title: null, tabGuard: true },787 ['tabGuardBeforeEl', 'frameTL', 'frameML', 'frameBL', 'tabGuardAfterEl'],788 [0, 1, 4, 7, 'body', 3, 2, 5, 6]);789 790 // bodyContainer === frameML after first layout with docked items present791 792 // Header position793 makeSuite({ frame: true, dockedItems: null, headerPosition: 'top' },794 [0, 'frameTL', 'bodyContainer', 'frameBL'], ['body']);795 makeSuite({ frame: true, dockedItems: null, headerPosition: 'left' },796 [0, 'frameTL', 'bodyContainer', 'frameBL'], ['body']);797 makeSuite({ frame: true, dockedItems: null, headerPosition: 'right' },798 ['frameTL', 'bodyContainer', 'frameBL', 0], ['body']);799 makeSuite({ frame: true, dockedItems: null, headerPosition: 'bottom' },800 ['frameTL', 'bodyContainer', 'frameBL', 0], ['body']);801 802 // Header position *and* dockedItems803 makeSuite({ frame: true, headerPosition: 'top' },804 [0, 'frameTL', 'bodyContainer', 'frameBL'], [1, 2, 5, 8, 'body', 4, 3, 6, 7]);805 makeSuite({ frame: true, headerPosition: 'left' },806 [0, 'frameTL', 'bodyContainer', 'frameBL'], [1, 2, 5, 8, 'body', 4, 3, 6, 7]);807 makeSuite({ frame: true, headerPosition: 'right' },808 ['frameTL', 'bodyContainer', 'frameBL', 0], [1, 2, 5, 8, 'body', 4, 3, 6, 7]);809 makeSuite({ frame: true, headerPosition: 'bottom' },810 ['frameTL', 'bodyContainer', 'frameBL', 0], [1, 2, 5, 8, 'body', 4, 3, 6, 7]);811 812 // Header position with tab guards813 makeSuite({ frame: true, dockedItems: null, tabGuard: true, headerPosition: 'top' },814 ['tabGuardBeforeEl', 0, 'frameTL', 'bodyContainer', 'frameBL', 'tabGuardAfterEl'],815 ['body']);816 makeSuite({ frame: true, dockedItems: null, tabGuard: true, headerPosition: 'left' },817 ['tabGuardBeforeEl', 0, 'frameTL', 'bodyContainer', 'frameBL', 'tabGuardAfterEl'],818 ['body']);819 makeSuite({ frame: true, dockedItems: null, tabGuard: true, headerPosition: 'right' },820 ['tabGuardBeforeEl', 'frameTL', 'bodyContainer', 'frameBL', 0, 'tabGuardAfterEl'],821 ['body']);822 makeSuite({ frame: true, dockedItems: null, tabGuard: true, headerPosition: 'bottom' },823 ['tabGuardBeforeEl', 'frameTL', 'bodyContainer', 'frameBL', 0, 'tabGuardAfterEl'],824 ['body']);825 826 // Header position with tab guards and dockedItems827 makeSuite({ frame: true, tabGuard: true, headerPosition: 'top' },828 ['tabGuardBeforeEl', 0, 'frameTL', 'bodyContainer', 'frameBL', 'tabGuardAfterEl'],829 [1, 2, 5, 8, 'body', 4, 3, 6, 7]);830 makeSuite({ frame: true, tabGuard: true, headerPosition: 'left' },831 ['tabGuardBeforeEl', 0, 'frameTL', 'bodyContainer', 'frameBL', 'tabGuardAfterEl'],832 [1, 2, 5, 8, 'body', 4, 3, 6, 7]);833 makeSuite({ frame: true, tabGuard: true, headerPosition: 'right' },834 ['tabGuardBeforeEl', 'frameTL', 'bodyContainer', 'frameBL', 0, 'tabGuardAfterEl'],835 [1, 2, 5, 8, 'body', 4, 3, 6, 7]);836 makeSuite({ frame: true, tabGuard: true, headerPosition: 'bottom' },837 ['tabGuardBeforeEl', 'frameTL', 'bodyContainer', 'frameBL', 0, 'tabGuardAfterEl'],838 [1, 2, 5, 8, 'body', 4, 3, 6, 7]);839 840 // Header added after rendering841 makeSuite({ frame: true, dockedItems: null, title: null, headerPosition: 'top' },842 [0, 'frameTL', 'bodyContainer', 'frameBL'], ['body'], addHeader, 'dynamic header 1');843 makeSuite({ frame: true, dockedItems: null, title: null, headerPosition: 'left' },844 [0, 'frameTL', 'bodyContainer', 'frameBL'], ['body'], addHeader, 'dynamic header 2');845 makeSuite({ frame: true, dockedItems: null, title: null, headerPosition: 'right' },846 ['frameTL', 'bodyContainer', 'frameBL', 0], ['body'], addHeader, 'dynamic header 3');847 makeSuite({ frame: true, dockedItems: null, title: null, headerPosition: 'bottom' },848 ['frameTL', 'bodyContainer', 'frameBL', 0], ['body'], addHeader, 'dynamic header 4');849 850 // Header added after rendering onto existing tab guards851 makeSuite({ frame: true, dockedItems: null, title: null, tabGuard: true, 852 headerPosition: 'top' },853 ['tabGuardBeforeEl', 0, 'frameTL', 'bodyContainer', 'frameBL', 'tabGuardAfterEl'],854 ['body'], addHeader, 'dynamic header 5');855 makeSuite({ frame: true, dockedItems: null, title: null, tabGuard: true,856 headerPosition: 'left' },857 ['tabGuardBeforeEl', 0, 'frameTL', 'bodyContainer', 'frameBL', 'tabGuardAfterEl'],858 ['body'], addHeader, 'dynamic header 6');859 makeSuite({ frame: true, dockedItems: null, title: null, tabGuard: true, headerPosition: 'right' },860 ['tabGuardBeforeEl', 'frameTL', 'bodyContainer', 'frameBL', 0, 'tabGuardAfterEl'],861 ['body'], addHeader, 'dynamic header 7');862 makeSuite({ frame: true, dockedItems: null, title: null, tabGuard: true, headerPosition: 'bottom' },863 ['tabGuardBeforeEl', 'frameTL', 'bodyContainer', 'frameBL', 0, 'tabGuardAfterEl'],864 ['body'], addHeader, 'dynamic header 8');865 866 // Header added after rendering onto existing tab guards and dockedItems867 makeSuite({ frame: true, title: null, tabGuard: true, headerPosition: 'top' },868 ['tabGuardBeforeEl', 0, 'frameTL', 'bodyContainer', 'frameBL', 'tabGuardAfterEl'],869 [1, 2, 5, 8, 'body', 4, 3, 6, 7], addHeader, 'dynamic header 9');870 makeSuite({ frame: true, title: null, tabGuard: true, headerPosition: 'left' },871 ['tabGuardBeforeEl', 0, 'frameTL', 'bodyContainer', 'frameBL', 'tabGuardAfterEl'],872 [1, 2, 5, 8, 'body', 4, 3, 6, 7], addHeader, 'dynamic header 10');873 makeSuite({ frame: true, title: null, tabGuard: true, headerPosition: 'right' },874 ['tabGuardBeforeEl', 'frameTL', 'bodyContainer', 'frameBL', 0, 'tabGuardAfterEl'],875 [1, 2, 5, 8, 'body', 4, 3, 6, 7], addHeader, 'dynamic header 11');876 makeSuite({ frame: true, title: null, tabGuard: true, headerPosition: 'bottom' },877 ['tabGuardBeforeEl', 'frameTL', 'bodyContainer', 'frameBL', 0, 'tabGuardAfterEl'], 878 [1, 2, 5, 8, 'body', 4, 3, 6, 7], addHeader, 'dynamic header 12');879 880 // Finally, dynamically added dockedItems. One by one. Ha!881 makeSuite({ frame: true, dockedItems: null, tabGuard: true, headerPosition: 'top' },882 ['tabGuardBeforeEl', 0, 'frameTL', 'bodyContainer', 'frameBL', 'tabGuardAfterEl'],883 [1, 2, 5, 8, 'body', 4, 3, 6, 7], addItems, 'dynamic items 1');884 makeSuite({ frame: true, dockedItems: null, tabGuard: true, headerPosition: 'left' },885 ['tabGuardBeforeEl', 0, 'frameTL', 'bodyContainer', 'frameBL', 'tabGuardAfterEl'],886 [1, 2, 5, 8, 'body', 4, 3, 6, 7], addItems, 'dynamic items 2');887 makeSuite({ frame: true, dockedItems: null, tabGuard: true, headerPosition: 'right' },888 ['tabGuardBeforeEl', 'frameTL', 'bodyContainer', 'frameBL', 0, 'tabGuardAfterEl'],889 [1, 2, 5, 8, 'body', 4, 3, 6, 7], addItems, 'dynamic items 3');890 makeSuite({ frame: true, dockedItems: null, tabGuard: true, headerPosition: 'bottom' },891 ['tabGuardBeforeEl', 'frameTL', 'bodyContainer', 'frameBL', 0, 'tabGuardAfterEl'],892 [1, 2, 5, 8, 'body', 4, 3, 6, 7], addItems, 'dynamic items 4');893 894 // All together now.895 makeSuite({ frame: true, title: null, dockedItems: null, tabGuard: true, headerPosition: 'top' },896 ['tabGuardBeforeEl', 0, 'frameTL', 'bodyContainer', 'frameBL', 'tabGuardAfterEl'],897 [1, 2, 5, 8, 'body', 4, 3, 6, 7], addHeaderAndItems, 'dynamic items 5');898 makeSuite({ frame: true, title: null, dockedItems: null, tabGuard: true, headerPosition: 'left' },899 ['tabGuardBeforeEl', 0, 'frameTL', 'bodyContainer', 'frameBL', 'tabGuardAfterEl'],900 [1, 2, 5, 8, 'body', 4, 3, 6, 7], addHeaderAndItems, 'dynamic items 6');901 makeSuite({ frame: true, title: null, dockedItems: null, tabGuard: true, headerPosition: 'right' },902 ['tabGuardBeforeEl', 'frameTL', 'bodyContainer', 'frameBL', 0, 'tabGuardAfterEl'],903 [1, 2, 5, 8, 'body', 4, 3, 6, 7], addHeaderAndItems, 'dynamic items 7');904 makeSuite({ frame: true, title: null, dockedItems: null, tabGuard: true, headerPosition: 'bottom' },905 ['tabGuardBeforeEl', 'frameTL', 'bodyContainer', 'frameBL', 0, 'tabGuardAfterEl'],906 [1, 2, 5, 8, 'body', 4, 3, 6, 7], addHeaderAndItems, 'dynamic items 8');907 }908 });909 910 describe('isValidParent', function() {911 var panel;912 beforeEach(function() {913 panel = new Ext.panel.Panel({914 title: 'Test',915 tbar: {916 itemId: 'top-toolbar',917 items: [{918 text: 'Top Button'919 }]920 },921 bbar: {922 itemId: 'bottom-toolbar',923 items: [{924 text: 'Bottom Button'925 }]926 },927 height: 100,928 width: 100,929 renderTo: document.body930 });931 });932 afterEach(function() {933 panel.destroy();934 });935 936 it('should not find that isValidParent returns false during a layout when docked items use itemId', function() {937 spyOn(panel.componentLayout, 'isValidParent').andCallThrough();938 939 panel.updateLayout();940 var calls = panel.componentLayout.isValidParent.calls,941 len = calls.length,942 i;943 // All the DockLayout's isValidParent calls during the layout must have returned true944 for (i = 0; i < len; i++) {945 expect(calls[i].result).toBe(true);946 }947 });948 });...
lodeRunner.guard.js
Source:lodeRunner.guard.js
1//=============================================================================2// AI reference book: "ç© Lode Runner å¸ C èªè¨"3// http://www.kingstone.com.tw/book/book_page.asp?kmcode=20147106505384//=============================================================================5var movePolicy = [ [0, 0, 0, 0, 0, 0], //* move_map is used to find *//6 [0, 1, 1, 0, 1, 1], //* wheather to move a enm *//7 [1, 1, 1, 1, 1, 1], //* by indexing into it with *//8 [1, 2, 1, 1, 2, 1], //* enm_byte + num_enm + *//9 [1, 2, 2, 1, 2, 2], //* set_num to get a byte. *//10 [2, 2, 2, 2, 2, 2], //* then that byte is checked*//11 [2, 2, 3, 2, 2, 3], //* for !=0 and then decrmnt *//12 [2, 3, 3, 2, 3, 3], //* for next test until = 0 *// 13 [3, 3, 3, 3, 3, 3], 14 [3, 3, 4, 3, 3, 4],15 [3, 4, 4, 3, 4, 4],16 [4, 4, 4, 4, 4, 4]17 ]; 18var moveOffset = 0;19var moveId = 0; //current guard id20var numOfMoveItems = movePolicy[0].length;21//********************************22//initial guard start move value 23//********************************24function initGuardVariable()25{26 moveOffset = moveId = 0;27}28function moveGuard()29{30 var moves;31 var curGuard;32 var x, y, yOffset;33 34 if(!guardCount) return; //no guard35 36 if( ++moveOffset >= numOfMoveItems ) moveOffset = 0;37 moves = movePolicy[guardCount][moveOffset]; // get next moves 38 39 while ( moves-- > 0) { // slows guard relative to runner40 if(++moveId >= guardCount) moveId = 0; 41 curGuard = guard[moveId];42 43 if(curGuard.action == ACT_IN_HOLE || curGuard.action == ACT_REBORN) {44 continue;45 }46 47 guardMoveStep(moveId, bestMove(moveId));48 }49} 50function guardMoveStep( id, action)51{52 var curGuard = guard[id];53 var x = curGuard.pos.x;54 var xOffset = curGuard.pos.xOffset;55 var y = curGuard.pos.y;56 var yOffset = curGuard.pos.yOffset;57 var curToken, nextToken;58 var centerX, centerY;59 var curShape, newShape;60 var stayCurrPos;61 62 centerX = centerY = ACT_STOP;63 curShape = newShape = curGuard.shape;64 if(curGuard.action == ACT_CLIMB_OUT && action == ACT_STOP) 65 curGuard.action = ACT_STOP; //for level 16, 30, guard will stock in hole66 67 switch(action) {68 case ACT_UP:69 case ACT_DOWN:70 case ACT_FALL:71 if ( action == ACT_UP ) { 72 stayCurrPos = ( y <= 0 ||73 (nextToken = map[x][y-1].act) == BLOCK_T ||74 nextToken == SOLID_T || nextToken == TRAP_T || 75 nextToken == GUARD_T);76 77 if( yOffset <= 0 && stayCurrPos)78 action = ACT_STOP;79 } else { //ACT_DOWN || ACT_FALL80 stayCurrPos = ( y >= maxTileY ||81 (nextToken = map[x][y+1].act) == BLOCK_T ||82 nextToken == SOLID_T || nextToken == GUARD_T); 83 84 if( action == ACT_FALL && yOffset < 0 && map[x][y].base == BLOCK_T) {85 action = ACT_IN_HOLE;86 stayCurrPos = 1;87 } else {88 if ( yOffset >= 0 && stayCurrPos) 89 action = ACT_STOP;90 }91 }92 93 if ( action != ACT_STOP ) {94 if ( xOffset > 0) 95 centerX = ACT_LEFT;96 else if ( xOffset < 0)97 centerX = ACT_RIGHT;98 }99 break;100 case ACT_LEFT:101 case ACT_RIGHT: 102 if ( action == ACT_LEFT ) {103 /* original source code from book104 stayCurrPos = ( x <= 0 ||105 (nextToken = map[x-1][y].act) == BLOCK_T ||106 nextToken == SOLID_T || nextToken == TRAP_T || 107 nextToken == GUARD_T); 108 */ 109 // change check TRAP_T from base, 110 // for support level 41==> runner in trap will cause guard move111 stayCurrPos = ( x <= 0 ||112 (nextToken = map[x-1][y].act) == BLOCK_T ||113 nextToken == SOLID_T || nextToken == GUARD_T ||114 map[x-1][y].base == TRAP_T); 115 116 if (xOffset <= 0 && stayCurrPos)117 action = ACT_STOP;118 } else { //ACT_RIGHT119 /* original source code from book120 stayCurrPos = ( x >= maxTileX ||121 (nextToken = map[x+1][y].act) == BLOCK_T ||122 nextToken == SOLID_T || nextToken == TRAP_T || 123 nextToken == GUARD_T); 124 */125 // change check TRAP_T from base, 126 // for support level 41==> runner in trap will cause guard move127 stayCurrPos = ( x >= maxTileX ||128 (nextToken = map[x+1][y].act) == BLOCK_T ||129 nextToken == SOLID_T || nextToken == GUARD_T || 130 map[x+1][y].base == TRAP_T); 131 132 if (xOffset >= 0 && stayCurrPos)133 action = ACT_STOP;134 }135 136 if ( action != ACT_STOP ) {137 if ( yOffset > 0 ) 138 centerY = ACT_UP;139 else if ( yOffset < 0) 140 centerY = ACT_DOWN;141 }142 break;143 }144 145 curToken = map[x][y].base;146 if ( action == ACT_UP ) {147 yOffset -= yMove;148 if(stayCurrPos && yOffset < 0) yOffset = 0; //stay on current position149 else if(yOffset < -H2) { //move to y-1 position 150 if ( curToken == BLOCK_T || curToken == HLADR_T ) curToken = EMPTY_T; //in hole or hide laddr151 map[x][y].act = curToken; //runner move to [x][y-1], so set [x][y].act to previous state152 y--;153 yOffset = tileH + yOffset;154 if(map[x][y].act == RUNNER_T) setRunnerDead(); //collision155 //map[x][y].act = GUARD_T;156 }157 158 if( yOffset <= 0 && yOffset > -yMove) {159 dropGold(id); //decrease count160 }161 newShape = "runUpDn";162 }163 164 if ( centerY == ACT_UP ) {165 yOffset -= yMove;166 if( yOffset < 0) yOffset = 0; //move to center Y 167 }168 169 if ( action == ACT_DOWN || action == ACT_FALL || action == ACT_IN_HOLE) {170 var holdOnBar = 0;171 if(curToken == BAR_T) {172 if( yOffset < 0) holdOnBar = 1;173 else if(action == ACT_DOWN && y < maxTileY && map[x][y+1].act != LADDR_T) {174 action = ACT_FALL; //shape fixed: 2014/03/27175 }176 }177 178 yOffset += yMove;179 180 if(holdOnBar == 1 && yOffset >= 0) {181 yOffset = 0; //fall and hold on bar182 action = ACT_FALL_BAR;183 }184 if(stayCurrPos && yOffset > 0 ) yOffset = 0; //stay on current position185 else if(yOffset > H2) { //move to y+1 position186 if(curToken == BLOCK_T || curToken == HLADR_T) curToken = EMPTY_T; //in hole or hide laddr187 map[x][y].act = curToken; //runner move to [x][y+1], so set [x][y].act to previous state188 y++;189 yOffset = yOffset - tileH;190 if(map[x][y].act == RUNNER_T) setRunnerDead(); //collision191 //map[x][y].act = GUARD_T;192 }193 194 //add condition: AI version >= 3 will decrease drop count while guard fall195 if( ((curAiVersion >= 3 && action == ACT_FALL) || action == ACT_DOWN) && 196 yOffset >= 0 && yOffset < yMove) 197 { //try drop gold198 dropGold(id); //decrease count199 }200 201 if(action == ACT_IN_HOLE) { //check in hole or still falling202 if (yOffset < 0) {203 action = ACT_FALL; //still falling204 205 //----------------------------------------------------------------------206 //For AI version >= 4, drop gold before guard failing into hole totally207 if(curAiVersion >= 4 && curGuard.hasGold > 0) {208 if(map[x][y-1].base == EMPTY_T) {209 //drop gold above210 addGold(x, y-1);211 } else 212 decGold(); //gold disappear 213 curGuard.hasGold = 0;214 guardRemoveRedhat(curGuard); //9/4/2016215 }216 //----------------------------------------------------------------------217 218 } else { //fall into hole (yOffset MUST = 0)219 //----------------------------------------------------------------------220 //For AI version < 4, drop gold after guard failing into hole totally221 if( curGuard.hasGold > 0 ) {222 if(map[x][y-1].base == EMPTY_T) {223 //drop gold above224 addGold(x, y-1);225 } else 226 decGold(); //gold disappear 227 }228 curGuard.hasGold = 0;229 guardRemoveRedhat(curGuard); //9/4/2016230 //----------------------------------------------------------------------231 232 if( curShape == "fallRight") newShape = "shakeRight";233 else newShape = "shakeLeft";234 themeSoundPlay("trap");235 shakeTimeStart = recordCount; //for debug236 if(curAiVersion < 3) {237 curGuard.sprite.on("animationend", function() { climbOut(id); });238 } else {239 add2GuardShakeQueue(id, newShape);240 }241 242 if(playMode == PLAY_CLASSIC || playMode == PLAY_AUTO || playMode == PLAY_DEMO) {243 drawScore(SCORE_IN_HOLE);244 } else {245 //for modem mode & edit mode246 //drawGuard(1); //only guard dead need add count247 }248 }249 }250 251 if(action == ACT_DOWN) {252 newShape = "runUpDn";253 } else { //ACT_FALL or ACT_FALL_BAR254 if (action == ACT_FALL_BAR) {255 if(curGuard.lastLeftRight == ACT_LEFT) newShape = "barLeft";256 else newShape = "barRight";257 } else {258 if(action == ACT_FALL && curShape != "fallLeft" && curShape != "fallRight") {259 if (curGuard.lastLeftRight == ACT_LEFT) newShape = "fallLeft";260 else newShape = "fallRight";261 }262 }263 }264 } 265 if ( centerY == ACT_DOWN ) {266 yOffset += yMove;267 if ( yOffset > 0 ) yOffset = 0; //move to center Y268 }269 270 if ( action == ACT_LEFT) {271 xOffset -= xMove;272 if(stayCurrPos && xOffset < 0) xOffset = 0; //stay on current position273 else if ( xOffset < -W2) { //move to x-1 position 274 if(curToken == BLOCK_T || curToken == HLADR_T) curToken = EMPTY_T; //in hole or hide laddr275 map[x][y].act = curToken; //runner move to [x-1][y], so set [x][y].act to previous state276 x--;277 xOffset = tileW + xOffset;278 if(map[x][y].act == RUNNER_T) setRunnerDead(); //collision279 //map[x][y].act = GUARD_T;280 }281 if( xOffset <= 0 && xOffset > -xMove) {282 dropGold(id); //try to drop gold283 }284 if(curToken == BAR_T) newShape = "barLeft";285 else newShape = "runLeft";286 }287 288 if ( centerX == ACT_LEFT ) {289 xOffset -= xMove;290 if ( xOffset < 0) xOffset = 0; //move to center X291 }292 293 if ( action == ACT_RIGHT ) {294 xOffset += xMove;295 if(stayCurrPos && xOffset > 0) xOffset = 0; //stay on current position296 else if ( xOffset > W2) { //move to x+1 position 297 if(curToken == BLOCK_T || curToken == HLADR_T) curToken = EMPTY_T; //in hole or hide laddr298 map[x][y].act = curToken; //runner move to [x+1][y], so set [x][y].act to previous state299 x++;300 xOffset = xOffset - tileW;301 if(map[x][y].act == RUNNER_T) setRunnerDead(); //collision302 //map[x][y].act = GUARD_T;303 }304 if( xOffset >= 0 && xOffset < xMove) {305 dropGold(id);306 }307 if(curToken == BAR_T) newShape = "barRight";308 else newShape = "runRight";309 }310 311 if ( centerX == ACT_RIGHT ) {312 xOffset += xMove;313 if ( xOffset > 0) xOffset = 0; //move to center X314 }315 316 //if(curGuard == ACT_CLIMB_OUT) action == ACT_CLIMB_OUT;317 318 if(action == ACT_STOP) {319 if(curGuard.action != ACT_STOP){320 curGuard.sprite.stop();321 if(curGuard.action != ACT_CLIMB_OUT) curGuard.action = ACT_STOP;322 }323 } else {324 if(curGuard.action == ACT_CLIMB_OUT) action = ACT_CLIMB_OUT;325 curGuard.sprite.x = (x * tileW + xOffset) * tileScale | 0;326 curGuard.sprite.y = (y * tileH + yOffset) * tileScale | 0;327 curGuard.pos = { x:x, y:y, xOffset:xOffset, yOffset:yOffset}; 328 if(curShape != newShape) {329 curGuard.sprite.gotoAndPlay(newShape);330 curGuard.shape = newShape;331 }332 if(action != curGuard.action){333 curGuard.sprite.play();334 }335 curGuard.action = action;336 if(action == ACT_LEFT || action == ACT_RIGHT) curGuard.lastLeftRight = action;337 }338 map[x][y].act = GUARD_T;339 // Check to get gold and carry 340 if(map[x][y].base == GOLD_T && curGuard.hasGold == 0 &&341 ((!xOffset && yOffset >= 0 && yOffset < H4) || 342 (!yOffset && xOffset >= 0 && xOffset < W4) || 343 (y < maxTileY && map[x][y+1].base == LADDR_T && yOffset < H4) // gold above laddr344 )345 ) 346 {347 //curGuard.hasGold = ((Math.random()*26)+14)|0; //14 - 39 348 curGuard.hasGold = ((Math.random()*26)+12)|0; //12 - 37 change gold drop steps349 guardWearRedhat(curGuard); //9/4/2016350 if(playMode == PLAY_AUTO || playMode == PLAY_DEMO || playMode == PLAY_DEMO_ONCE) getDemoGold(curGuard);351 if(recordMode) processRecordGold(curGuard);352 removeGold(x, y);353 //debug ("get, (x,y) = " + x + "," + y + ", offset = " + xOffset); 354 }355 //check collision again 356 //checkCollision(runner.pos.x, runner.pos.y);357}358//meanings: guard with gold359function guardWearRedhat(guard)360{361 if(redhatMode) guard.sprite.spriteSheet = redhatData;362}363//meanings: guard without gold364function guardRemoveRedhat(guard) 365{366 if(redhatMode) guard.sprite.spriteSheet = guardData;367}368function dropGold(id) 369{370 var curGuard = guard[id];371 var nextToken;372 var drop = 0;373 374 switch (true) {375 case (curGuard.hasGold > 1):376 curGuard.hasGold--; // count > 1, don't drop it only decrease count 377 //loadingTxt.text = "(" + id + ") = " + curGuard.hasGold;378 break; 379 case (curGuard.hasGold == 1): //drop gold380 var x = curGuard.pos.x, y = curGuard.pos.y;381 382 if(map[x][y].base == EMPTY_T && ( y >= maxTileY ||383 ((nextToken = map[x][y+1].base) == BLOCK_T || 384 nextToken == SOLID_T || nextToken == LADDR_T) )385 ) {386 addGold(x,y);387 curGuard.hasGold = -1; //for record play action always use value = -1388 //curGuard.hasGold = -(((Math.random()*10)+1)|0); //-1 ~ -10; //waiting time for get gold389 guardRemoveRedhat(curGuard); //9/4/2016 390 drop = 1;391 }392 break; 393 case (curGuard.hasGold < 0):394 curGuard.hasGold++; //wait, don't get gold till count = 0395 //loadingTxt.text = "(" + id + ") = " + curGuard.hasGold;396 break; 397 }398 return drop;399}400//=============================================401// BEGIN NEW SHAKE METHOD for AI version >= 3402//=============================================403var DEBUG_TIME = 0;404var shakeRight = [ 8, 9, 10, 9, 10, 8 ];405var shakeLeft = [ 30, 31, 32, 31, 32, 30 ];406var shakeTime = [ 36, 3, 3, 3, 3, 3 ];407var shakingGuardList = [];408function initStillFrameVariable()409{410 initGuardShakeVariable();411 initFillHoleVariable();412 initRebornVariable();413}414function initGuardShakeVariable()415{416 shakingGuardList = [];417 418 //-------------------------------------------------------------------------419 // Shake time extension when guard in hole,420 // so the runner can dig three hold for three guards and pass through them. 421 // The behavior almost same as original lode runner (APPLE-II version).422 // 2016/06/04423 //-------------------------------------------------------------------------424 if(curAiVersion <= 3) shakeTime = [ 36, 3, 3, 3, 3, 3 ]; //for AI VERSION = 3425 else shakeTime = [ 51, 3, 3, 3, 3, 3 ]; //for AI VERSION > 3426}427function add2GuardShakeQueue(id, shape)428{429 var curGuard = guard[id];430 431 if(shape == "shakeRight") {432 curGuard.shapeFrame = shakeRight; 433 } else { 434 curGuard.shapeFrame = shakeLeft; 435 }436 437 curGuard.curFrameIdx = 0;438 curGuard.curFrameTime = -1; //for init439 440 shakingGuardList.push(id);441 //error(arguments.callee.name, "push id =" + id + "(" + shakingGuardList + ")" );442 443}444function processGuardShake()445{446 var curGuard, curIdx;447 for(var i = 0; i < shakingGuardList.length;) {448 curGuard = guard[shakingGuardList[i]];449 curIdx = curGuard.curFrameIdx;450 451 if( curGuard.curFrameTime < 0) { //start shake => set still frame452 curGuard.curFrameTime = 0;453 curGuard.sprite.gotoAndStop(curGuard.shapeFrame[curIdx]);454 } else {455 if(++curGuard.curFrameTime >= shakeTime[curIdx]) {456 if(++curGuard.curFrameIdx < curGuard.shapeFrame.length) {457 //change frame458 curGuard.curFrameTime = 0;459 curGuard.sprite.gotoAndStop(curGuard.shapeFrame[curGuard.curFrameIdx]);460 } else {461 //shake time out 462 463 var id = shakingGuardList[i];464 shakingGuardList.splice(i, 1); //remove from list465 //error(arguments.callee.name, "remove id =" + id + "(" + shakingGuardList + ")" );466 climbOut(id); //climb out467 continue;468 }469 470 }471 }472 i++;473 }474}475function removeFromShake(id)476{477 for(var i = 0; i < shakingGuardList.length;i++) {478 if(shakingGuardList[i] == id) {479 shakingGuardList.splice(i, 1); //remove from list480 //error(arguments.callee.name, "remove id =" + id + "(" + shakingGuardList + ")" );481 return;482 }483 }484 error(arguments.callee.name, "design error id =" + id + "(" + shakingGuardList + ")" );485}486//======================487// END NEW SHAKE METHOD 488//======================489function climbOut(id)490{491 var curGuard = guard[id]492 493 curGuard.action = ACT_CLIMB_OUT;494 curGuard.sprite.removeAllEventListeners ("animationend");495 curGuard.sprite.gotoAndPlay("runUpDn");496 curGuard.shape = "runUpDn";497 curGuard.holePos = {x: curGuard.pos.x, y: curGuard.pos.y };498 499 if(DEBUG_TIME) loadingTxt.text = "ShakeTime = " + (recordCount - shakeTimeStart); //for debug500}501function bestMove(id)502{503 var guarder = guard[id];504 var x = guarder.pos.x;505 var xOffset = guarder.pos.xOffset;506 var y = guarder.pos.y;507 var yOffset = guarder.pos.yOffset;508 509 var curToken, nextBelow, nextMove;510 var checkSameLevelOnly = 0;511 512 curToken = map[x][y].base;513 514 if(guarder.action == ACT_CLIMB_OUT) { //clib from hole515 if(guarder.pos.y == guarder.holePos.y) {516 return (ACT_UP);517 }else {518 checkSameLevelOnly = 1;519 if(guarder.pos.x != guarder.holePos.x) { //out of hole520 guarder.action = ACT_LEFT;521 }522 }523 }524 525 if( !checkSameLevelOnly) {526 527 /****** next check to see if enm must fall. if so ***********/528 /****** return e_fall and skip the rest. ***********/529 530 if ( curToken == LADDR_T || (curToken == BAR_T && yOffset === 0) ) { //ladder & bar531 /* no guard fall */ 532 } else if ( yOffset < 0) //no laddr & yOffset < 0 ==> falling533 return (ACT_FALL);534 else if ( y < maxTileY )535 {536 nextBelow = map[x][y+1].act;537 538 if ( (nextBelow == EMPTY_T || nextBelow == RUNNER_T )) {539 return (ACT_FALL);540 } else if ( nextBelow == BLOCK_T || nextBelow == SOLID_T || 541 nextBelow == GUARD_T || nextBelow == LADDR_T ) {542 /* no guard fall */543 } else {544 return ( ACT_FALL ); 545 }546 } 547 }548 /******* next check to see if palyer on same floor *********/549 /******* and whether enm can get him. Ignore walls *********/550 var runnerX = runner.pos.x;551 var runnerY = runner.pos.y; 552 553// if ( y == runnerY ) { // same floor with runner554 if ( y == runnerY && runner.action != ACT_FALL) { //case : guard on laddr and falling => don't catch it 555 while ( x != runnerX ) {556 if ( y < maxTileY )557 nextBelow = map[x][y+1].base;558 else nextBelow = SOLID_T;559 560 curToken = map[x][y].base;561 562 if ( curToken == LADDR_T || curToken == BAR_T || // go through 563 nextBelow == SOLID_T || nextBelow == LADDR_T ||564 nextBelow == BLOCK_T || map[x][y+1].act == GUARD_T || //fixed: must check map[].act with guard_t (for support champLevel:43)565 nextBelow == BAR_T || nextBelow == GOLD_T) //add BAR_T & GOLD_T for support level 92 566 {567 if ( x < runnerX) // guard left to runner568 ++x; 569 else if ( x > runnerX )570 --x; // guard right to runner571 } else break; // exit loop with closest x if no path to runner572 }573 574 if ( x == runnerX ) // scan for a path ignoring walls is a success575 {576 if (guarder.pos.x < runnerX ) { //if left of man go right else left 577 nextMove = ACT_RIGHT;578 } else if ( guarder.pos.x > runnerX ) {579 nextMove = ACT_LEFT;580 } else { // guard X = runner X581 if ( guarder.pos.xOffset < runner.pos.xOffset )582 nextMove = ACT_RIGHT;583 else584 nextMove = ACT_LEFT;585 }586 return (nextMove); 587 }588 } // if ( y == runnerY ) { ... 589 590 /********** If can't reach man on current level, then scan floor *********/591 /********** (ignoring walls) and look up and down for best move *********/592 return scanFloor(id);593}594var bestPath, bestRating, curRating; 595var leftEnd, rightEnd; 596var startX, startY;597function scanFloor(id)598{599 var x, y;600 var curToken, nextBelow;601 var curPath;602 603 x = startX = guard[id].pos.x;604 y = startY = guard[id].pos.y;605 606 bestRating = 255; // start with worst rating607 curRating = 255;608 bestPath = ACT_STOP;609 610 /****** get ends for search along floor ******/611 612 while ( x > 0 ) { //get left end first613 curToken = map[x-1][y].act;614 if ( curToken == BLOCK_T || curToken == SOLID_T )615 break;616 if ( curToken == LADDR_T || curToken == BAR_T || y >= maxTileY ||617 y < maxTileY && ( ( nextBelow = map[x-1][y+1].base) == BLOCK_T ||618 nextBelow == SOLID_T || nextBelow == LADDR_T ) )619 --x;620 else {621 --x; // go on left anyway 622 break;623 } 624 }625 626 leftEnd = x;627 x = startX;628 while ( x < maxTileX ) { // get right end next629 curToken = map[x+1][y].act;630 if ( curToken == BLOCK_T || curToken == SOLID_T )631 break;632 633 if ( curToken == LADDR_T || curToken == BAR_T || y >= maxTileY ||634 y < maxTileY && ( ( nextBelow = map[x+1][y+1].base) == BLOCK_T ||635 nextBelow == SOLID_T || nextBelow == LADDR_T ) )636 ++x;637 else { // go on right anyway638 ++x; 639 break;640 } 641 }642 643 rightEnd = x;644 /******* Do middle scan first for best rating and direction *******/645 646 x = startX;647 if ( y < maxTileY && 648 (nextBelow = map[x][y+1].base) != BLOCK_T && nextBelow != SOLID_T )649 scanDown( x, ACT_DOWN ); 650 if( map[x][y].base == LADDR_T )651 scanUp( x, ACT_UP );652 /******* next scan both sides of floor for best rating *******/653 curPath = ACT_LEFT;654 x = leftEnd; 655 656 while ( true ) {657 if ( x == startX ) {658 if ( curPath == ACT_LEFT && rightEnd != startX ) {659 curPath = ACT_RIGHT;660 x = rightEnd;661 }662 else break;663 }664 665 if( y < maxTileY && 666 (nextBelow = map [x][y+1].base) != BLOCK_T && nextBelow != SOLID_T )667 scanDown (x, curPath );668 if( map[x][y].base == LADDR_T )669 scanUp ( x, curPath );670 671 if ( curPath == ACT_LEFT )672 x++;673 else x--; 674 } 675 676 return ( bestPath ); 677} // end scan floor for best direction to go 678 679function scanDown(x, curPath ) 680{681 var y;682 var nextBelow; //curRating;683 var runnerX = runner.pos.x;684 var runnerY = runner.pos.y;685 686 y = startY;687 688 while( y < maxTileY && ( nextBelow = map [x][y+1].base) != BLOCK_T &&689 nextBelow != SOLID_T ) // while no floor below ==> can move down690 {691 if ( map[x][y].base != EMPTY_T && map[x][y].base != HLADR_T) { // if not falling ==> try move left or right 692 //************************************************************************************693 // 2014/04/14 Add check "map[x][y].base != HLADR_T" for support 694 // champLevel 19: a guard in hole with h-ladder can run left after dig the left hole695 //************************************************************************************696 if ( x > 0 ) { // if not at left edge check left side697 if ( (nextBelow = map[x-1][y+1].base) == BLOCK_T ||698 nextBelow == LADDR_T || nextBelow == SOLID_T ||699 map[x-1][y].base == BAR_T ) // can move left 700 {701 if ( y >= runnerY ) // no need to go on702 break; // already below runner703 }704 } 705 706 if ( x < maxTileX ) // if not at right edge check right side707 {708 if ( (nextBelow = map[x+1][y+1].base) == BLOCK_T ||709 nextBelow == LADDR_T || nextBelow == SOLID_T ||710 map[x+1][y].base == BAR_T ) // can move right711 {712 if ( y >= runnerY )713 break;714 }715 }716 } // end if not falling717 ++y; // go to next level down718 } // end while ( y < maxTileY ... ) scan down719 720 if( y == runnerY ) { // update best rating and direct.721 curRating = Math.abs(startX - x); 722// if ( (curRating = runnerX - x) < 0) //BUG from original book ? (changed by Simon)723// curRating = -curRating; //ABS724 } else if ( y > runnerY )725 curRating = y - runnerY + 200; // position below runner726 else curRating = runnerY - y + 100; // position above runner727 728 if( curRating < bestRating )729 {730 bestRating = curRating;731 bestPath = curPath;732 }733 734} // end Scan Down735function scanUp( x, curPath )736{737 var y;738 var nextBelow; //curRating;739 var runnerX = runner.pos.x;740 var runnerY = runner.pos.y;741 742 y = startY;743 744 while ( y > 0 && map[x][y].base == LADDR_T ) { // while can go up745 --y;746 if ( x > 0 ) { // if not at left edge check left side747 if ( (nextBelow = map[x-1][y+1].base) == BLOCK_T ||748 nextBelow == SOLID_T || nextBelow == LADDR_T ||749 map[x-1][y].base == BAR_T ) // can move left750 {751 if ( y <= runnerY ) // no need to go on 752 break; // already above runner753 }754 }755 if ( x < maxTileX ) { // if not at right edge check right side756 if ( (nextBelow = map[x+1][y+1].base) == BLOCK_T ||757 nextBelow == SOLID_T || nextBelow == LADDR_T ||758 map[x+1][y].base == BAR_T ) // can move right759 {760 if ( y <= runnerY )761 break;762 }763 } 764 //--y;765 } // end while ( y > 0 && laddr up) scan up 766 767 if ( y == runnerY ) { // update best rating and direct.768 curRating = Math.abs(startX - x);769 //if ( (curRating = runnerX - x) < 0) // BUG from original book ? (changed by Simon)770 // curRating = -curRating; //ABS771 } else if ( y > runnerY )772 curRating = y - runnerY + 200; // position below runner 773 else curRating = runnerY - y + 100; // position above runner 774 775 if ( curRating < bestRating )776 {777 bestRating = curRating;778 bestPath = curPath;779 }780 781} // end scan Up782var bornRndX; //range random 0..maxTileX783function initRnd()784{785 //bornRndX = new rangeRandom(0, maxTileX, curLevel); //set fixed seed for demo mode786 bornRndX = new rangeRandom(0, maxTileX, 0); //random range 0 .. maxTileX787}788function getGuardId(x, y)789{790 var id;791 792 for(id = 0; id < guardCount; id++) {793 if ( guard[id].pos.x == x && guard[id].pos.y == y) break;794 }795 assert(id < guardCount, "Error: can not get guard position!");796 797 return id;798}799function guardReborn(x, y)800{801 var id;802 803 //get guard id by current in hole position804 id = getGuardId(x, y);805 var bornY = 1; //start on line 2806 var bornX = bornRndX.get();807 var rndStart = bornX;808 809 810 while(map[bornX][bornY].act != EMPTY_T || map[bornX][bornY].base == GOLD_T || map[bornX][bornY].base == BLOCK_T ) { 811 //BUG FIXED for level 115 (can not reborn at bornX=27)812 //don't born at gold position & diged position, 2/24/2015813 if( (bornX = bornRndX.get()) == rndStart) { 814 bornY++;815 }816 assert(bornY <= maxTileY, "Error: Born Y too large !");817 }818 //debug("bornX = " + bornX);819 if(playMode == PLAY_AUTO || playMode == PLAY_DEMO || playMode == PLAY_DEMO_ONCE) {820 var bornPos = getDemoBornPos();821 bornX = bornPos.x;822 bornY = bornPos.y;823 }824 825 if(recordMode == RECORD_KEY) saveRecordBornPos(bornX, bornY);826 else if(recordMode == RECORD_PLAY) {827 var bornPos = getRecordBornPos();828 bornX = bornPos.x;829 bornY = bornPos.y;830 }831 832 map[bornX][bornY].act = GUARD_T;833 //debug("born (x,y) = (" + bornX + "," + bornY + ")");834 835 var curGuard = guard[id];836 837 curGuard.pos = { x:bornX, y:bornY, xOffset:0, yOffset: 0 };838 curGuard.sprite.x = bornX * tileWScale | 0;839 curGuard.sprite.y = bornY * tileHScale | 0;840 841 rebornTimeStart = recordCount;842 if(curAiVersion < 3) {843 curGuard.sprite.on("animationend", function() { rebornComplete(id); });844 curGuard.sprite.gotoAndPlay("reborn");845 } else {846 add2RebornQueue(id);847 }848 curGuard.shape = "reborn";849 curGuard.action = ACT_REBORN;850 851}852function rebornComplete(id)853{854 var x = guard[id].pos.x;855 var y = guard[id].pos.y;856 if( map[x][y].act == RUNNER_T) setRunnerDead(); //collision857 map[x][y].act = GUARD_T; 858 guard[id].sprite.removeAllEventListeners ("animationend");859 guard[id].action = ACT_FALL;860 guard[id].shape = "fallRight";861 //guard[id].hasGold = 0;862 guard[id].sprite.gotoAndPlay("fallRight");863 themeSoundPlay("reborn");864 865 if(DEBUG_TIME) loadingTxt.text = "rebornTime = " + (recordCount - rebornTimeStart); //for debug866}867function setRunnerDead()868{869 if(!godMode) gameState = GAME_RUNNER_DEAD; 870}871//===============================================872// BEGIN NEW FOR REBORN (ai version >= 3)873//===============================================874var rebornFrame = [ 28, 29 ];875var rebornTime = [ 6, 2 ];876var rebornGuardList = [];877function initRebornVariable()878{879 rebornGuardList = [];880}881function add2RebornQueue(id)882{883 var curGuard = guard[id];884 885 curGuard.sprite.gotoAndStop("reborn");886 curGuard.curFrameIdx = 0;887 curGuard.curFrameTime = -1;888 889 rebornGuardList.push(id);890}891function processReborn()892{893 var curGuard, curIdx;894 895 for(var i = 0; i < rebornGuardList.length;) {896 curGuard = guard[rebornGuardList[i]];897 curIdx = curGuard.curFrameIdx;898 899 if(++curGuard.curFrameTime >= rebornTime[curIdx]) {900 if(++curGuard.curFrameIdx < rebornFrame.length) {901 //change frame902 curGuard.curFrameTime = 0;903 curGuard.sprite.gotoAndStop(rebornFrame[curGuard.curFrameIdx]);904 } else {905 //reborn 906 var id = rebornGuardList[i];907 rebornGuardList.splice(i, 1); //remove from list908 rebornComplete(id);909 continue;910 }911 }912 i++;913 }914}915//====================916// END NEW FOR REBORN ...
revisionGuardTest.js
Source:revisionGuardTest.js
...156 if (guarded === 3) {157 done();158 }159 }160 guard.guard(evt1, function (err, finish) {161 expect(err).not.to.be.ok();162 finish(function (err) {163 expect(err).not.to.be.ok();164 expect(guarded).to.eql(0);165 check();166 });167 });168 setTimeout(function () {169 guard.guard(evt2, function (err, finish) {170 expect(err).not.to.be.ok();171 finish(function (err) {172 expect(err).not.to.be.ok();173 expect(guarded).to.eql(1);174 check();175 });176 });177 }, 10);178 setTimeout(function () {179 guard.guard(evt3, function (err, finish) {180 expect(err).not.to.be.ok();181 finish(function (err) {182 expect(err).not.to.be.ok();183 expect(guarded).to.eql(2);184 check();185 });186 });187 }, 20);188 });189 describe('but with slow beginning events', function () {190 var specialGuard;191 before(function () {192 specialGuard = new RevisionGuard(store, { queueTimeout: 2000, queueTimeoutMaxLoops: 15 });193 specialGuard.defineEvent({194 correlationId: 'correlationId',195 id: 'id',196 payload: 'payload',197 name: 'name',198 aggregateId: 'aggregate.id',199 aggregate: 'aggregate.name',200 context: 'context.name',201 revision: 'revision',202 version: 'version',203 meta: 'meta'204 });205 });206 beforeEach(function (done) {207 specialGuard.currentHandlingRevisions = {};208 store.clear(done);209 });210 it('it should work as expected', function (done) {211 var guarded = 0;212 function check () {213 guarded++;214 if (guarded === 3) {215 done();216 }217 }218 var start1 = Date.now();219 specialGuard.guard(evt1, function (err, finish1) {220 var diff1 = Date.now() - start1;221 console.log('guarded 1: ' + diff1);222 expect(err).not.to.be.ok();223 setTimeout(function () {224 start1 = Date.now();225 finish1(function (err) {226 diff1 = Date.now() - start1;227 console.log('finished 1: ' + diff1);228 expect(err).not.to.be.ok();229 expect(guarded).to.eql(0);230 check();231 });232 }, 250);233 });234 var start2 = Date.now();235 specialGuard.guard(evt2, function (err, finish2) {236 var diff2 = Date.now() - start2;237 console.log('guarded 2: ' + diff2);238 expect(err).not.to.be.ok();239 start2 = Date.now();240 finish2(function (err) {241 diff2 = Date.now() - start2;242 console.log('finished 2: ' + diff2);243 expect(err).not.to.be.ok();244 expect(guarded).to.eql(1);245 check();246 });247 });248 var start3 = Date.now();249 specialGuard.guard(evt3, function (err, finish3) {250 var diff3 = Date.now() - start3;251 console.log('guarded 3: ' + diff3);252 expect(err).not.to.be.ok();253 start3 = Date.now();254 finish3(function (err) {255 diff3 = Date.now() - start3;256 console.log('finished 3: ' + diff3);257 expect(err).not.to.be.ok();258 expect(guarded).to.eql(2);259 check();260 });261 });262 });263 });264 describe('but having a startRevisionNumber', function () {265 var specialGuard;266 beforeEach(function (done) {267 specialGuard = new RevisionGuard(store, { queueTimeout: 200, queueTimeoutMaxLoops: 3, startRevisionNumber: 1 });268 specialGuard.defineEvent({269 correlationId: 'correlationId',270 id: 'id',271 payload: 'payload',272 name: 'name',273 aggregateId: 'aggregate.id',274 aggregate: 'aggregate.name',275 context: 'context.name',276 revision: 'revision',277 version: 'version',278 meta: 'meta'279 });280 specialGuard.currentHandlingRevisions = {};281 store.clear(done);282 });283 it('and guarding an event with revision greater than expected, it should emit an eventMissing event', function (done) {284 specialGuard.onEventMissing(function (info, e) {285 expect(info.aggregateId).to.equal(evt2.aggregate.id);286 expect(info.aggregateRevision).to.equal(evt2.revision);287 expect(info.guardRevision).to.equal(1);288 expect(e).to.equal(evt2);289 done();290 });291 specialGuard.guard(evt2, function (err, finish) {});292 });293 it('and guarding an event with revision like expected, it should work normally', function (done) {294 specialGuard.guard(evt1, function (err, finish) {295 expect(err).not.to.be.ok();296 finish(function (err) {297 expect(err).not.to.be.ok();298 done();299 });300 });301 });302 it('and guarding an event with revision smaller than expected, it work normally', function (done) {303 var evt0 = _.cloneDeep(evt1);304 evt0.revision = 0;305 specialGuard.guard(evt0, function (err, finish) {306 expect(err).not.to.be.ok();307 finish(function (err) {308 expect(err).not.to.be.ok();309 done();310 });311 });312 });313 });314 });315 describe('in wrong order', function () {316 it('it should work as expected', function (done) {317 var guarded = 0;318 function check () {319 guarded++;320// if (guarded === 3) {321// done();322// }323 }324 guard.guard(evt1, function (err, finish) {325 expect(err).not.to.be.ok();326 finish(function (err) {327 expect(err).not.to.be.ok();328 expect(guarded).to.eql(0);329 check();330 });331 });332 setTimeout(function () {333 guard.guard(evt2, function (err, finish) {334 expect(err).not.to.be.ok();335 finish(function (err) {336 expect(err).not.to.be.ok();337 expect(guarded).to.eql(1);338 check();339 });340 });341 }, 30);342 setTimeout(function () {343 guard.guard(evt3, function (err, finish) {344 expect(err).not.to.be.ok();345 finish(function (err) {346 expect(err).not.to.be.ok();347 expect(guarded).to.eql(2);348 check();349 });350 });351 guard.guard(evt3, function (err, finish) {352 expect(err).to.be.ok();353 expect(err.name).to.eql('AlreadyDenormalizingError');354 });355 }, 10);356 setTimeout(function () {357 guard.guard(evt2, function (err) {358 expect(err).to.be.ok();359 expect(err.name).to.eql('AlreadyDenormalizedError');360 expect(guarded).to.eql(3);361 guard.guard(evt3, function (err) {362 expect(err).to.be.ok();363 expect(err.name).to.eql('AlreadyDenormalizedError');364 expect(guarded).to.eql(3);365 store.getLastEvent(function (err, evt) {366 expect(err).not.to.be.ok();367 expect(evt.id).to.eql(evt3.id);368 done();369 });370 });371 });372 }, 300);373 });374 });375 describe('and missing something', function () {376 it('it should work as expected', function (done) {377 var guarded = 0;378 function check () {379 guarded++;380// if (guarded === 3) {381// done();382// }383 }384 guard.onEventMissing(function (info, evt) {385 expect(guarded).to.eql(1);386 expect(evt).to.eql(evt3);387 expect(info.aggregateId).to.eql('aggId1');388 expect(info.aggregateRevision).to.eql(3);389 expect(info.guardRevision).to.eql(2);390 expect(info.aggregate).to.eql('agg');391 expect(info.context).to.eql('ctx');392 done();393 });394 guard.guard(evt1, function (err, finish) {395 expect(err).not.to.be.ok();396 finish(function (err) {397 expect(err).not.to.be.ok();398 expect(guarded).to.eql(0);399 check();400 });401 });402 setTimeout(function () {403 guard.guard(evt3, function (err, finish) {404 expect(err).not.to.be.ok();405 finish(function (err) {406 expect(err).not.to.be.ok();407 expect(guarded).to.eql(2);408 check();409 });410 });411 }, 20);412 });413 });414 });415 });...
class_illuminate_1_1_auth_1_1_guard.js
Source:class_illuminate_1_1_auth_1_1_guard.js
1var class_illuminate_1_1_auth_1_1_guard =2[3 [ "__construct", "class_illuminate_1_1_auth_1_1_guard.html#a8e87194add3984de660aac287ebd495d", null ],4 [ "__construct", "class_illuminate_1_1_auth_1_1_guard.html#a8e87194add3984de660aac287ebd495d", null ],5 [ "attempt", "class_illuminate_1_1_auth_1_1_guard.html#a944394beca1c1f40ee92de86dcb939d0", null ],6 [ "attempt", "class_illuminate_1_1_auth_1_1_guard.html#a5047509e33eb88dc5fa45d39077b451d", null ],7 [ "attemptBasic", "class_illuminate_1_1_auth_1_1_guard.html#aff6e0ec1bc42a3ca0a44c9013a0730dc", null ],8 [ "attemptBasic", "class_illuminate_1_1_auth_1_1_guard.html#aff6e0ec1bc42a3ca0a44c9013a0730dc", null ],9 [ "attempting", "class_illuminate_1_1_auth_1_1_guard.html#a0d1c441fcc50f7a15325773c42733b4e", null ],10 [ "attempting", "class_illuminate_1_1_auth_1_1_guard.html#a0d1c441fcc50f7a15325773c42733b4e", null ],11 [ "basic", "class_illuminate_1_1_auth_1_1_guard.html#a8941b297eb28787d08464ac687040c4e", null ],12 [ "basic", "class_illuminate_1_1_auth_1_1_guard.html#a8941b297eb28787d08464ac687040c4e", null ],13 [ "check", "class_illuminate_1_1_auth_1_1_guard.html#a5fb1933974ac9aae8c7ac4d3344caca6", null ],14 [ "check", "class_illuminate_1_1_auth_1_1_guard.html#a5fb1933974ac9aae8c7ac4d3344caca6", null ],15 [ "clearUserDataFromStorage", "class_illuminate_1_1_auth_1_1_guard.html#a9824aae665052a49661a6adb252301ce", null ],16 [ "clearUserDataFromStorage", "class_illuminate_1_1_auth_1_1_guard.html#a9824aae665052a49661a6adb252301ce", null ],17 [ "createRecaller", "class_illuminate_1_1_auth_1_1_guard.html#a5510f7604d38cffda66db64cd0352739", null ],18 [ "createRecaller", "class_illuminate_1_1_auth_1_1_guard.html#a5510f7604d38cffda66db64cd0352739", null ],19 [ "createRememberTokenIfDoesntExist", "class_illuminate_1_1_auth_1_1_guard.html#a5da2e6d65f643ded9d9d1935041983dd", null ],20 [ "createRememberTokenIfDoesntExist", "class_illuminate_1_1_auth_1_1_guard.html#a5da2e6d65f643ded9d9d1935041983dd", null ],21 [ "fireAttemptEvent", "class_illuminate_1_1_auth_1_1_guard.html#a9c08131595729c1afad42a26eb5dda09", null ],22 [ "fireAttemptEvent", "class_illuminate_1_1_auth_1_1_guard.html#a9c08131595729c1afad42a26eb5dda09", null ],23 [ "fireLoginEvent", "class_illuminate_1_1_auth_1_1_guard.html#af4bc30ae74ad958e322de133a9cc51fb", null ],24 [ "fireLoginEvent", "class_illuminate_1_1_auth_1_1_guard.html#af4bc30ae74ad958e322de133a9cc51fb", null ],25 [ "getBasicCredentials", "class_illuminate_1_1_auth_1_1_guard.html#aeb13faa74740f4b198f21f383ed36c34", null ],26 [ "getBasicCredentials", "class_illuminate_1_1_auth_1_1_guard.html#aeb13faa74740f4b198f21f383ed36c34", null ],27 [ "getBasicResponse", "class_illuminate_1_1_auth_1_1_guard.html#a43cb59c4c6fa887dea6eafb439b3eabf", null ],28 [ "getBasicResponse", "class_illuminate_1_1_auth_1_1_guard.html#a43cb59c4c6fa887dea6eafb439b3eabf", null ],29 [ "getCookieJar", "class_illuminate_1_1_auth_1_1_guard.html#a9536636aceb9653fe5d0f2365193caab", null ],30 [ "getCookieJar", "class_illuminate_1_1_auth_1_1_guard.html#a9536636aceb9653fe5d0f2365193caab", null ],31 [ "getDispatcher", "class_illuminate_1_1_auth_1_1_guard.html#a2c6ae191baffbfeb2260f88736bbb15b", null ],32 [ "getDispatcher", "class_illuminate_1_1_auth_1_1_guard.html#a2c6ae191baffbfeb2260f88736bbb15b", null ],33 [ "getLastAttempted", "class_illuminate_1_1_auth_1_1_guard.html#a204b5f36603321a21042914878a06abc", null ],34 [ "getLastAttempted", "class_illuminate_1_1_auth_1_1_guard.html#a204b5f36603321a21042914878a06abc", null ],35 [ "getName", "class_illuminate_1_1_auth_1_1_guard.html#a3d0963e68bb313b163a73f2803c64600", null ],36 [ "getName", "class_illuminate_1_1_auth_1_1_guard.html#a3d0963e68bb313b163a73f2803c64600", null ],37 [ "getProvider", "class_illuminate_1_1_auth_1_1_guard.html#ac78cba8e9aa7dfb1f003a7c5cb77151c", null ],38 [ "getProvider", "class_illuminate_1_1_auth_1_1_guard.html#ac78cba8e9aa7dfb1f003a7c5cb77151c", null ],39 [ "getRecaller", "class_illuminate_1_1_auth_1_1_guard.html#abe650fdc0de5ed6e1a2800f4aada6112", null ],40 [ "getRecaller", "class_illuminate_1_1_auth_1_1_guard.html#abe650fdc0de5ed6e1a2800f4aada6112", null ],41 [ "getRecallerId", "class_illuminate_1_1_auth_1_1_guard.html#a434e17b12ca53d575ec2709905991004", null ],42 [ "getRecallerId", "class_illuminate_1_1_auth_1_1_guard.html#a434e17b12ca53d575ec2709905991004", null ],43 [ "getRecallerName", "class_illuminate_1_1_auth_1_1_guard.html#ab6890804bdb401d71c29c16cafd806c7", null ],44 [ "getRecallerName", "class_illuminate_1_1_auth_1_1_guard.html#ab6890804bdb401d71c29c16cafd806c7", null ],45 [ "getRequest", "class_illuminate_1_1_auth_1_1_guard.html#adf1a35ad20e475c59cc0967d5764aa22", null ],46 [ "getRequest", "class_illuminate_1_1_auth_1_1_guard.html#adf1a35ad20e475c59cc0967d5764aa22", null ],47 [ "getSession", "class_illuminate_1_1_auth_1_1_guard.html#aefa4c5bd150e2a7d525576d7959c6911", null ],48 [ "getSession", "class_illuminate_1_1_auth_1_1_guard.html#aefa4c5bd150e2a7d525576d7959c6911", null ],49 [ "getUser", "class_illuminate_1_1_auth_1_1_guard.html#ae81b7186fb97a7c6457edcc68c9aa2ef", null ],50 [ "getUser", "class_illuminate_1_1_auth_1_1_guard.html#ae81b7186fb97a7c6457edcc68c9aa2ef", null ],51 [ "getUserByRecaller", "class_illuminate_1_1_auth_1_1_guard.html#aadb995ece9c56afc5b9b39b5c2359ce3", null ],52 [ "getUserByRecaller", "class_illuminate_1_1_auth_1_1_guard.html#aadb995ece9c56afc5b9b39b5c2359ce3", null ],53 [ "guest", "class_illuminate_1_1_auth_1_1_guard.html#af3b5cea15df2e2bc5862865e2f86710a", null ],54 [ "guest", "class_illuminate_1_1_auth_1_1_guard.html#af3b5cea15df2e2bc5862865e2f86710a", null ],55 [ "hasValidCredentials", "class_illuminate_1_1_auth_1_1_guard.html#a6e9db831a9f6e6dde1d9cb940b07228f", null ],56 [ "hasValidCredentials", "class_illuminate_1_1_auth_1_1_guard.html#a6e9db831a9f6e6dde1d9cb940b07228f", null ],57 [ "id", "class_illuminate_1_1_auth_1_1_guard.html#a087060b582403885d08e89ad894ecc5d", null ],58 [ "id", "class_illuminate_1_1_auth_1_1_guard.html#a087060b582403885d08e89ad894ecc5d", null ],59 [ "login", "class_illuminate_1_1_auth_1_1_guard.html#addf8071951fd8ab3e1a0633a761e46e6", null ],60 [ "login", "class_illuminate_1_1_auth_1_1_guard.html#addf8071951fd8ab3e1a0633a761e46e6", null ],61 [ "loginUsingId", "class_illuminate_1_1_auth_1_1_guard.html#a83389212384770daa98b5184db6a27c6", null ],62 [ "loginUsingId", "class_illuminate_1_1_auth_1_1_guard.html#a83389212384770daa98b5184db6a27c6", null ],63 [ "logout", "class_illuminate_1_1_auth_1_1_guard.html#a082405d89acd6835c3a7c7a08a7adbab", null ],64 [ "logout", "class_illuminate_1_1_auth_1_1_guard.html#a082405d89acd6835c3a7c7a08a7adbab", null ],65 [ "once", "class_illuminate_1_1_auth_1_1_guard.html#aa3e3ffb8659f3fae4c67278bcda2057a", null ],66 [ "once", "class_illuminate_1_1_auth_1_1_guard.html#ada98b313c6562787b60164f71d0d0546", null ],67 [ "onceBasic", "class_illuminate_1_1_auth_1_1_guard.html#a4114b66e760313663525fc13749d017a", null ],68 [ "onceBasic", "class_illuminate_1_1_auth_1_1_guard.html#a4114b66e760313663525fc13749d017a", null ],69 [ "onceUsingId", "class_illuminate_1_1_auth_1_1_guard.html#a47e0fe78dc15ea610d8e3237846a561c", null ],70 [ "onceUsingId", "class_illuminate_1_1_auth_1_1_guard.html#a47e0fe78dc15ea610d8e3237846a561c", null ],71 [ "queueRecallerCookie", "class_illuminate_1_1_auth_1_1_guard.html#a33480a74e2a2416f85025ce1c2a12843", null ],72 [ "queueRecallerCookie", "class_illuminate_1_1_auth_1_1_guard.html#a33480a74e2a2416f85025ce1c2a12843", null ],73 [ "refreshRememberToken", "class_illuminate_1_1_auth_1_1_guard.html#aaaed00f928329b0f20aa80ba40e6caac", null ],74 [ "refreshRememberToken", "class_illuminate_1_1_auth_1_1_guard.html#aaaed00f928329b0f20aa80ba40e6caac", null ],75 [ "setCookieJar", "class_illuminate_1_1_auth_1_1_guard.html#ad65394539c0bad485d243892f96d3616", null ],76 [ "setCookieJar", "class_illuminate_1_1_auth_1_1_guard.html#ad65394539c0bad485d243892f96d3616", null ],77 [ "setDispatcher", "class_illuminate_1_1_auth_1_1_guard.html#aea49c5f1053ec710cdc5ae487eea2df4", null ],78 [ "setDispatcher", "class_illuminate_1_1_auth_1_1_guard.html#aea49c5f1053ec710cdc5ae487eea2df4", null ],79 [ "setProvider", "class_illuminate_1_1_auth_1_1_guard.html#a035c5554e857dbd1b65b4e95de33026f", null ],80 [ "setProvider", "class_illuminate_1_1_auth_1_1_guard.html#a035c5554e857dbd1b65b4e95de33026f", null ],81 [ "setRequest", "class_illuminate_1_1_auth_1_1_guard.html#a5f37f0cbf56308f0ef744ba02a61989e", null ],82 [ "setRequest", "class_illuminate_1_1_auth_1_1_guard.html#a5f37f0cbf56308f0ef744ba02a61989e", null ],83 [ "setUser", "class_illuminate_1_1_auth_1_1_guard.html#a94ec4fad4575c0e25fc1b31da3415835", null ],84 [ "setUser", "class_illuminate_1_1_auth_1_1_guard.html#a94ec4fad4575c0e25fc1b31da3415835", null ],85 [ "updateSession", "class_illuminate_1_1_auth_1_1_guard.html#a030ab4388a28354315edf1fd2971a787", null ],86 [ "updateSession", "class_illuminate_1_1_auth_1_1_guard.html#a030ab4388a28354315edf1fd2971a787", null ],87 [ "user", "class_illuminate_1_1_auth_1_1_guard.html#ae8a275690ff1b618e1947378b0ed73ae", null ],88 [ "user", "class_illuminate_1_1_auth_1_1_guard.html#ae8a275690ff1b618e1947378b0ed73ae", null ],89 [ "validate", "class_illuminate_1_1_auth_1_1_guard.html#a74012c4727212ac362a5a536e54f5e50", null ],90 [ "validate", "class_illuminate_1_1_auth_1_1_guard.html#a92895dc28a096a42404b2e1721907cef", null ],91 [ "validRecaller", "class_illuminate_1_1_auth_1_1_guard.html#a20e1a0bbd1c7bb075faf6adc2eb4fbcc", null ],92 [ "validRecaller", "class_illuminate_1_1_auth_1_1_guard.html#a20e1a0bbd1c7bb075faf6adc2eb4fbcc", null ],93 [ "viaRemember", "class_illuminate_1_1_auth_1_1_guard.html#a4bd4262ccfe767f8c9c044ff639d747b", null ],94 [ "viaRemember", "class_illuminate_1_1_auth_1_1_guard.html#a4bd4262ccfe767f8c9c044ff639d747b", null ],95 [ "$cookie", "class_illuminate_1_1_auth_1_1_guard.html#ab8deb5892402f43a0fde234f317f8e31", null ],96 [ "$events", "class_illuminate_1_1_auth_1_1_guard.html#a1bcec9bbd34255927faaf155bf3a940a", null ],97 [ "$lastAttempted", "class_illuminate_1_1_auth_1_1_guard.html#a82283df525e6ba05e41e8c861dd8103e", null ],98 [ "$loggedOut", "class_illuminate_1_1_auth_1_1_guard.html#a250bc1e8a7f4b94f34540f8b516de85b", null ],99 [ "$provider", "class_illuminate_1_1_auth_1_1_guard.html#a934c4a71069a9e3bf15bcb8206884031", null ],100 [ "$request", "class_illuminate_1_1_auth_1_1_guard.html#abb35c8495a232b510389fa6d7b15d38a", null ],101 [ "$session", "class_illuminate_1_1_auth_1_1_guard.html#abefb3c26429d514777313e9a63d7cbac", null ],102 [ "$tokenRetrievalAttempted", "class_illuminate_1_1_auth_1_1_guard.html#a30093c0b1c2acecddd3de87f9399a9a9", null ],103 [ "$user", "class_illuminate_1_1_auth_1_1_guard.html#a598ca4e71b15a1313ec95f0df1027ca5", null ],104 [ "$viaRemember", "class_illuminate_1_1_auth_1_1_guard.html#a358ef6701c0f6a7b5b9bc882ccde273a", null ]...
TabGuard.js
Source:TabGuard.js
1/**2 * Prevents DOM focusability while modal windows are visible.3 */4Ext.define('Ext.plugin.TabGuard', {5 extend: 'Ext.plugin.Abstract',6 alias: 'plugin.tabguard',7 /**8 * When set to `true`, two elements are added to the container's element. These are the9 * `{@link #tabGuardBeforeEl}` and `{@link #tabGuardAfterEl}`.10 * @cfg {Boolean} tabGuard11 * @private12 * @since 6.5.113 */14 tabGuard: true,15 /**16 * @cfg {Number} [tabGuardBeforeIndex] Top tab guard tabIndex. Use this when17 * there are elements with tabIndex > 0 within the dialog.18 * @private19 * @since 6.5.120 */21 /**22 * @cfg {Number} [tabGuardAfterIndex] Bottom tab guard tabIndex. Use this23 * when there are elements with tabIndex > 0 within the dialog.24 * @private25 * @since 6.5.126 */27 /**28 * @property {Array} tabGuardTemplate29 * This template is used to generate the `tabGuard` elements. It is used once per30 * element (see `{@link #tabGuardBeforeEl}` and `{@link #tabGuardAfterEl}`).31 * @private32 * @since 6.5.133 */34 tabGuardTemplate: [{35 // We use span instead of div because of IE bug/misfeature: it will focus36 // block elements upon clicking or calling node.focus() regardless of37 // tabIndex attribute. It doesn't do that with inline elements, hence span.38 tag: 'span',39 'aria-hidden': 'true',40 cls: Ext.baseCSSPrefix + 'tab-guard-el'41 }],42 /**43 * @property {Object} tabGuardElements44 * Read only object containing property names for tab guard elements, keyed by position.45 * @private46 * @since 6.5.147 */48 tabGuardElements: {49 before: 'tabGuardBeforeEl',50 after: 'tabGuardAfterEl'51 },52 init: function(cmp) {53 var me = this;54 me.decorateComponent(cmp);55 if (cmp.addTool) {56 cmp.addTool = Ext.Function.createSequence(cmp.addTool, me.maybeInitTabGuards, me);57 }58 if (cmp.add) {59 cmp.add = Ext.Function.createSequence(cmp.add, me.maybeInitTabGuards, me);60 }61 if (cmp.remove) {62 cmp.remove = Ext.Function.createSequence(cmp.remove, me.maybeInitTabGuards, me);63 }64 cmp.onRender = Ext.Function.createSequence(cmp.onRender, me.maybeInitTabGuards, me);65 cmp.getTabGuard = me.getTabGuard.bind(me);66 cmp.on('show', me.initTabGuards, me);67 },68 destroy: function() {69 var cmp = this.getCmp();70 if (cmp) {71 delete cmp.addTool;72 delete cmp.add;73 delete cmp.remove;74 }75 this.callParent();76 },77 privates: {78 decorateComponent: function(cmp) {79 var me = this,80 tpl = me.tabGuardTemplate;81 cmp = cmp || me.getCmp();82 cmp[me.tabGuardElements.before] = cmp.el.insertFirst(tpl);83 cmp[me.tabGuardElements.after] = cmp.el.createChild(tpl);84 },85 getTabGuard: function(position) {86 var cmp = this.getCmp(),87 prop = this.tabGuardElements[position];88 return cmp[prop];89 },90 maybeInitTabGuards: function() {91 var cmp = this.getCmp();92 if (cmp.rendered && cmp.initialized && cmp.tabGuard) {93 this.initTabGuards();94 }95 },96 initTabGuards: function() {97 var me = this,98 cmp = me.getCmp(),99 minTabIndex = me.tabGuardBeforeIndex || 0,100 maxTabIndex = me.tabGuardAfterIndex || 0,101 beforeGuard = me.getTabGuard('before'),102 afterGuard = me.getTabGuard('after'),103 i, tabIndex, nodes;104 if (!cmp.rendered || !cmp.tabGuard) {105 return;106 }107 nodes = cmp.el.findTabbableElements({108 skipSelf: true109 });110 // Both tab guards may be in the list, disregard them111 if (nodes[0] === beforeGuard.dom) {112 nodes.shift();113 }114 if (nodes[nodes.length - 1] === afterGuard.dom) {115 nodes.pop();116 }117 if (nodes && nodes.length) {118 // In some cases it might be desirable to configure before and after119 // guard elements' tabIndex explicitly but if it is missing we try to120 // infer it from the DOM. If we don't and there are elements with121 // tabIndex > 0 within the container then tab order will be very122 // unintuitive.123 if (minTabIndex == null || maxTabIndex == null) {124 for (i = 0; i < nodes.length; i++) {125 // Can't use node.tabIndex property here126 tabIndex = +nodes[i].getAttribute('tabIndex');127 if (tabIndex > 0) {128 minTabIndex = Math.min(minTabIndex, tabIndex);129 maxTabIndex = Math.max(maxTabIndex, tabIndex);130 }131 }132 }133 beforeGuard.dom.setAttribute('tabIndex', minTabIndex);134 afterGuard.dom.setAttribute('tabIndex', maxTabIndex);135 }136 else {137 // We don't want the guards to participate in tab flow138 // if there are no tabbable children in the container139 beforeGuard.dom.removeAttribute('tabIndex');140 afterGuard.dom.removeAttribute('tabIndex');141 }142 if (!beforeGuard.hasListeners.focusenter) {143 beforeGuard.on('focusenter', me.onTabGuardFocusEnter, cmp);144 }145 if (!afterGuard.hasListeners.focusenter) {146 afterGuard.on('focusenter', me.onTabGuardFocusEnter, cmp);147 }148 },149 onTabGuardFocusEnter: function(e, target) {150 var cmp = this,151 el = cmp.el,152 beforeGuard = cmp.getTabGuard('before'),153 afterGuard = cmp.getTabGuard('after'),154 from = e.relatedTarget,155 nodes, forward, nextFocus;156 nodes = el.findTabbableElements({157 skipSelf: true158 });159 // Tabbables might include two tab guards, so remove them160 if (nodes[0] === beforeGuard.dom) {161 nodes.shift();162 }163 if (nodes[nodes.length - 1] === afterGuard.dom) {164 nodes.pop();165 }166 // Totally possible not to have anything tabbable within the window167 // but we have to do something so focus back the window el. At least168 // in that case the user will be able to press Escape key to close it.169 if (nodes.length === 0) {170 nextFocus = el;171 }172 // The window itself was focused, possibly by clicking or programmatically;173 // but this time we do have something tabbable to choose from.174 else if (from === el.dom) {175 forward = target === beforeGuard.dom;176 }177 // Focus was within the window and is trying to escape; 178 // for topmost guard we need to bounce focus back to the last tabbable179 // element in the window, and vice versa for the bottom guard.180 else if (el.contains(from)) {181 forward = !!e.forwardTab;182 }183 // It is entirely possible that focus was outside the window and184 // the user tabbed into the window. In that case we forward the focus185 // to the next available element in the natural tab order, i.e. the element186 // after the topmost guard, or the element before the bottom guard.187 else {188 forward = target === beforeGuard.dom;189 }190 nextFocus = nextFocus || (forward ? nodes[0] : nodes[nodes.length - 1]);191 if (nextFocus) {192 // If there is only one focusable node in the window, focusing it193 // while we're in focusenter handler for the tab guard might cause194 // race condition where the focusable node will be refocused first195 // and then its original blur handler will kick in, removing focus196 // styling erroneously.197 Ext.fly(nextFocus).focus(nodes.length === 1 ? 1 : 0);198 }199 }200 }...
guard.js
Source:guard.js
1function InitializeGuard(){2 var canvas = document.getElementById('mainCanvas');3 var context = canvas.getContext('2d');4 context.scale(1,1);5 GUARD = {6 initialized: true,7 directions : [0, 90, 180, 270],8 x : 10,9 y : 10,10 width : 60,11 height : 75,12 speed : 5,13 currentDirection : 0,14 latest : {15 x : 0,16 y : 017 },18 src : "pics/guardsolo.png"19 };20 GUARD.currentDirection = Math.trunc(Math.random() * 3);21}22function InitializeBeam(){23 BEAM = {24 initialized : true,25 x : GUARD.x,26 y : GUARD.y,27 theta : 180,28 width : 50,29 height : 70,30 latest : {31 x : 0,32 y : 033 },34 src : ""35 };36}37function HandleGuardCollision(){38 if(GUARD.y > 0 && GUARD.x < (GAME.canvas.width-GUARD.width) && GUARD.x > 0 && GUARD.y < (GAME.canvas.height - GUARD.height))39 {40 return false;41 }42 return true;43}44// Rotate rotates a point around45// cx, cy : The central point46// x, y : The coordinates of point to be rotatedPoint47// angle : Angle in degrees of rotation48function RotateGuard(cx, cy, x, y, angle) {49 var radians = (Math.PI / 180) * angle,50 cos = Math.cos(radians),51 sin = Math.sin(radians),52 nx = (cos * (x - cx)) + (sin * (y - cy)) + cx,53 ny = (cos * (y - cy)) - (sin * (x - cx)) + cy;54 return [nx, ny];55}56// RotateAroundOrigin57// x, y : The coordinates of point to be rotatedPoint58// angle : Angle in degrees of rotation59function RotateAroundOrigin(x, y, angle) {60 return Rotate(0, 0, x, y, angle);61}62function RenderGuard(context) {63 var guardimg = new Image();64 guardimg.src = GUARD.src;65 if (!GUARD.initialized) {66 return;67 }68 context.drawImage(guardimg, GUARD.x, GUARD.y, GUARD.width, GUARD.height);69}70function RenderBeam(context){71 context.beginPath();72 context.lineWidth = "6";73 context.strokeStyle = "yellow";74 //check the current direction of the guard to make the beam75 // if (GUARD.currentDirection == 0){76 // context.rect(BEAM.x, BEAM.y, BEAM.height+((GAME.level-1)*8), BEAM.width+((GAME.level-1)*8));77 // }78 // else if (GUARD.currentDirection == 1){79 // context.rect(BEAM.x, BEAM.y, BEAM.height+((GAME.level-1)*8), BEAM.width+((GAME.level-1)*8));80 // }81 // else if (GUARD.currentDirection == 2){82 // context.rect(BEAM.x, BEAM.y, BEAM.width+((GAME.level-1)*8), BEAM.height+((GAME.level-1)*8));83 // }84 // else{85 //86 // }87 context.rect(BEAM.x, BEAM.y, BEAM.width+((GAME.level-1)*8), BEAM.height+((GAME.level-1)*8));88 context.stroke();89 context.closePath();90}91function checkGuard(){92 var random;93 var list;94 if(GUARD.x - GUARD.width <= 0 && GUARD.currentDirection == 2)95 {96 if(!(GUARD.y - GUARD.height <= 0) && !(GUARD.y + GUARD.height >= GAME.canvas.height))97 {98 list = [0, 1, 3];99 }100 else if(!(GUARD.y - GUARD.height <= 0))101 {102 list = [0, 1];103 }104 else if(!(GUARD.y + GUARD.height >= GAME.canvas.height))105 {106 list = [0, 3];107 }108 random = Math.trunc(Math.random() * list.length);109 GUARD.currentDirection = list[random];110 return GUARD.currentDirection;111 }112 else if(GUARD.x + GUARD.width >= GAME.canvas.width && GUARD.currentDirection == 0)113 {114 if(!(GUARD.y - GUARD.height <= 0) && !(GUARD.y + GUARD.height >= GAME.canvas.height))115 {116 list = [1, 2, 3];117 }118 else if(!(GUARD.y - GUARD.height <= 0))119 {120 list = [1, 2];121 }122 else if(!(GUARD.y + GUARD.height >= GAME.canvas.height))123 {124 list = [2, 3];125 }126 random = Math.trunc(Math.random() * list.length);127 GUARD.currentDirection = list[random];128 return GUARD.currentDirection;129 }130 else if(GUARD.y - GUARD.height <= 0 && GUARD.currentDirection == 1)131 {132 if(!(GUARD.x - GUARD.width <= 0) && !(GUARD.x + GUARD.width >= GAME.canvas.width))133 {134 list = [0, 2, 3];135 }136 else if(!(GUARD.x - GUARD.width <= 0))137 {138 list = [0, 3];139 }140 else if(!(GUARD.x + GUARD.width >= GAME.canvas.width))141 {142 list = [2, 3];143 }144 random = Math.trunc(Math.random() * list.length);145 GUARD.currentDirection = list[random];146 return GUARD.currentDirection;147 }148 else if (GUARD.y + GUARD.height >= GAME.canvas.height && GUARD.currentDirection == 3) {149 if(!(GUARD.x - GUARD.width <= 0) && !(GUARD.x + GUARD.width >= GAME.canvas.width))150 {151 list = [0, 1, 2];152 }153 else if(!(GUARD.x - GUARD.width <= 0))154 {155 list = [0, 1];156 }157 else if(!(GUARD.x + GUARD.width >= GAME.canvas.width))158 {159 list = [1, 2];160 }161 random = Math.trunc(Math.random() * list.length);162 GUARD.currentDirection = list[random];163 return GUARD.currentDirection;164 }165 /*166 else if(GUARD.x + GUARD.width >= GAME.canvas.width)167 {168 list = RotateGuard(GAME.canvas.width, y, x, y, 180);169 GUARD.x -= GUARD.speed * Math.sin(list[0]);170 }171 if(GUARD.y + GUARD.height <= 0)172 {173 list = RotateGuard(x, 0, x, y, 180);174 GUARD.y += GUARD.speed * Math.cos(list[1]);175 }176 if(GUARD.y - GUARD.height >= GAME.canvas.height)177 {178 list = RotateGuard(x, GAME.canvas.height, x, y, 180);179 GUARD.y -= GUARD.speed * Math.cos(list[1]);180 }181 */182 else{183 return GUARD.currentDirection;184 }...
FocusTrap.js
Source:FocusTrap.js
1/**2 * This mixin implements focus trap for widgets that do not want to allow the user3 * to tab out, circling focus among the child items instead. The widget should be4 * derived from Panel since it relies on the tab guards feature of the Panel.5 *6 * The best example of such widget is a Window, or a dialog as per WAI-ARIA 1.0:7 * http://www.w3.org/TR/wai-aria-practices/#dialog_modal8 * http://www.w3.org/TR/wai-aria-practices/#dialog_nonmodal9 *10 * @private11 */12Ext.define('Ext.util.FocusTrap', {13 extend: 'Ext.Mixin',14 15 mixinConfig: {16 id: 'focustrap',17 18 after: {19 afterRender: 'initTabGuards',20 addTool: 'initTabGuards',21 add: 'initTabGuards',22 remove: 'initTabGuards',23 addDocked: 'initTabGuards',24 removeDocked: 'initTabGuards',25 onShow: 'initTabGuards',26 afterHide: 'initTabGuards'27 }28 },29 30 config: {31 tabGuard: true,32 33 tabGuardTpl:34 '<div id="{id}-{tabGuardEl}" data-ref="{tabGuardEl}" role="button" ' +35 'data-tabguardposition="{tabGuard}" aria-busy="true" style="height:0"' +36 'class="' + Ext.baseCSSPrefix + 'hidden-clip">' +37 '</div>',38 39 tabGuardIndex: 040 },41 42 tabGuardPositionAttribute: 'data-tabguardposition',43 44 privates: {45 initTabGuards: function() {46 var me = this,47 posAttr = me.tabGuardPositionAttribute,48 beforeGuard = me.tabGuardBeforeEl,49 afterGuard = me.tabGuardAfterEl,50 tabIndex = me.tabGuardIndex,51 nodes;52 53 if (!me.rendered || !me.tabGuard) {54 return;55 }56 57 nodes = me.el.findTabbableElements({58 skipSelf: true59 });60 61 // Both tab guards may be in the list, disregard them62 if (nodes[0] && nodes[0].hasAttribute(posAttr)) {63 nodes.shift();64 }65 66 if (nodes.length && nodes[nodes.length - 1].hasAttribute(posAttr)) {67 nodes.pop();68 }69 70 if (nodes.length) {71 beforeGuard.dom.setAttribute('tabIndex', tabIndex);72 beforeGuard.on('focusenter', me.onTabGuardFocusEnter, me);73 74 afterGuard.dom.setAttribute('tabIndex', tabIndex);75 afterGuard.on('focusenter', me.onTabGuardFocusEnter, me);76 }77 else {78 beforeGuard.dom.removeAttribute('tabIndex');79 beforeGuard.un('focusenter', me.onTabGuardFocusEnter, me);80 81 afterGuard.dom.removeAttribute('tabIndex');82 afterGuard.un('focusenter', me.onTabGuardFocusEnter, me);83 }84 },85 86 onTabGuardFocusEnter: function(e, target) {87 var me = this,88 el = me.el,89 posAttr = me.tabGuardPositionAttribute,90 position = target.getAttribute(posAttr),91 from = e.relatedTarget,92 nodes, forward, nextFocus;93 94 // Focus was within the parent widget and is trying to escape;95 // for topmost guard we need to bounce focus back to the last tabbable96 // element in the parent widget, and vice versa for the bottom trap.97 if (!from.hasAttribute(posAttr) && from !== el.dom && el.contains(from)) {98 forward = position === 'before' ? false : true;99 }100 101 // It is entirely possible that focus was outside the widget and102 // the user tabbed into the widget, or widget main el was focused103 // and the user pressed the Tab key. In that case we forward the focus104 // to the next available element in the natural tab order, i.e. the element105 // after the topmost guard, or the element before the bottom guard.106 else {107 forward = position === 'before' ? true : false;108 }109 110 nodes = el.findTabbableElements({111 skipSelf: true112 });113 114 // Tabbables will include two tab guards, so remove them115 nodes.shift();116 nodes.pop();117 118 nextFocus = forward ? nodes[0] : nodes[nodes.length - 1];119 120 if (nextFocus) {121 nextFocus.focus();122 }123 }124 }
...
day-04.js
Source:day-04.js
1const { getMinutes, getDayOfYear } = require('date-fns');2const guardStartsRx = /\[(.+)] Guard #(\d+)/i;3const guardStateChangesRx = /\[(.+)] (wakes|falls)/i;4function parseLog(inputLines) {5 return inputLines.sort().map(line => {6 if (guardStartsRx.test(line)) {7 const [_, dateFormat, guardId] = line.match(guardStartsRx);8 return {9 date: new Date(dateFormat),10 guardId: parseInt(guardId, 10),11 };12 } else {13 const [_, dateFormat, stateChange] = line.match(guardStateChangesRx);14 return {15 date: new Date(dateFormat),16 stateChange,17 };18 }19 });20}21function Guard(id) {22 const timesAsleep = Array.from({ length: 60 }).map(() => 0);23 function markAsleep(atMinute) {24 timesAsleep[atMinute]++;25 }26 return {27 id,28 timesAsleep,29 markAsleep,30 };31}32function processLog(logs) {33 const guards = {};34 function getGuard(id) {35 if (id in guards) return guards[id];36 return (guards[id] = Guard(id));37 }38 let currentGuard = null;39 let isAsleepAt = null;40 logs.forEach(log => {41 if (log.guardId) {42 currentGuard = getGuard(log.guardId);43 isAsleepAt = null;44 } else if (log.stateChange === 'falls') {45 isAsleepAt = log.date;46 } else if (log.stateChange === 'wakes') {47 if (getDayOfYear(isAsleepAt) === getDayOfYear(log.date)) {48 for (49 let minute = getMinutes(isAsleepAt);50 minute < getMinutes(log.date);51 minute++52 ) {53 currentGuard.markAsleep(minute);54 }55 }56 isAsleepAt = null;57 }58 });59 return Object.values(guards);60}61function getMostAsleepGuard(guards) {62 function getAsleepTime(guard) {63 return guard.timesAsleep.reduce((a, b) => a + b, 0);64 }65 let mostAsleepGuard = guards[0];66 let mostAsleepTime = getAsleepTime(guards[0]);67 for (const guard of guards) {68 const asleepTime = getAsleepTime(guard);69 if (asleepTime > mostAsleepTime) {70 mostAsleepGuard = guard;71 mostAsleepTime = asleepTime;72 }73 }74 return mostAsleepGuard;75}76function getMostFrequentlyAsleepGuard(guards) {77 function getHighestFrequency(guard) {78 return Math.max(...guard.timesAsleep);79 }80 let guardWithHighestFrequency = guards[0];81 let mostHighestFrequency = getHighestFrequency(guards[0]);82 for (const guard of guards) {83 const highestFrequency = getHighestFrequency(guard);84 if (highestFrequency > mostHighestFrequency) {85 guardWithHighestFrequency = guard;86 mostHighestFrequency = highestFrequency;87 }88 }89 return guardWithHighestFrequency;90}91module.exports = {92 part1: inputLines => {93 const guards = processLog(parseLog(inputLines));94 const mostAsleepGuard = getMostAsleepGuard(guards);95 const mostAsleepValue = Math.max(...mostAsleepGuard.timesAsleep);96 return (97 mostAsleepGuard.id * mostAsleepGuard.timesAsleep.indexOf(mostAsleepValue)98 );99 },100 part2: inputLines => {101 const guards = processLog(parseLog(inputLines));102 const mostAsleepGuard = getMostFrequentlyAsleepGuard(guards);103 const mostAsleepValue = Math.max(...mostAsleepGuard.timesAsleep);104 return (105 mostAsleepGuard.id * mostAsleepGuard.timesAsleep.indexOf(mostAsleepValue)106 );107 },...
Using AI Code Generation
1describe('My First Test', function() {2 it('Does not do much!', function() {3 expect(true).to.equal(true)4 })5 it('Visits the Kitchen Sink', function() {6 })7 it('Finds an element', function() {8 cy.contains('type')9 })10 it('Clicks an element', function() {11 cy.contains('type').click()12 })13 it('Gets, types and asserts', function() {14 cy.contains('type').click()15 cy.url().should('include', '/commands/actions')16 cy.get('.action-email')17 .type('fake@email')18 .should('have.value', 'fake@email')19 })20 it('Gets, types and asserts', function() {21 cy.contains('type').click()22 cy.url().should('include', '/commands/actions')23 cy.get('.action-email')24 .type('fakeemail')25 .should('have.value', 'fakeemail')26 })27})
Using AI Code Generation
1describe('My First Test', function () {2 it('Does not do much!', function () {3 expect(true).to.equal(true)4 })5 it('Visits the Kitchen Sink', function () {6 cy.contains('type').click()7 cy.url().should('include', '/commands/actions')8 cy.get('.action-email')9 .type('
Using AI Code Generation
1describe('My First Test', function() {2 it('Does not do much!', function() {3 expect(true).to.equal(true)4 })5})6describe('My First Test', function() {7 it('Does not do much!', function() {8 assert.equal(true, true)9 })10})11describe('My First Test', function() {12 it('Does not do much!', function() {13 true.should.equal(true)14 })15})16describe('My First Test', function() {17 it('Does not do much!', function() {18 expect(true).to.equal(true)19 })20})21describe('My First Test', function() {22 it('Does not do much!', function() {23 assert.equal(true, true)24 })25})26describe('My First Test', function() {27 it('Does not do much!', function() {28 true.should.equal(true)29 })30})31describe('My First Test', function() {32 it('Does not do much!', function() {33 expect(true).toEqual(true)34 })35})36describe('My First Test', function() {37 it('Does not do much!', function() {38 assert.equal(true, true)39 })40})41describe('My First Test', function() {42 it('Does not do much!', function() {43 true.should.equal(true)44 })45})46describe('My First Test', function() {47 it('Does not do much!', function() {48 expect(true).to.equal(true)49 })50})51describe('My First Test', function() {52 it('Does not do much!', function() {53 assert.equal(true, true)54 })55})56describe('My First Test', function() {57 it('Does not do much!', function() {58 true.should.equal(true)59 })60})61describe('My First Test', function() {62 it('Does not do much!', function() {63 expect(true).toBe(true
Using AI Code Generation
1describe('My First Test', () => {2 it('Does not do much!', () => {3 expect(true).to.equal(true)4 })5})6describe('My First Test', () => {7 it('Visits the Kitchen Sink', () => {8 })9})10describe('My First Test', () => {11 it('Finds an element', () => {12 cy.contains('type')13 })14})15describe('My First Test', () => {16 it('Clicks an element', () => {17 cy.contains('type').click()18 })19})20describe('My First Test', () => {21 it('Gets, types and asserts', () => {22 cy.contains('type').click()23 cy.url().should('include', '/commands/actions')24 })25})26describe('My First Test', () => {27 it('Gets, types and asserts', () => {28 cy.contains('type').click()29 cy.url().should('include', '/commands/actions')30 cy.get('.action-email')31 .type('fake@email')32 .should('have.value', 'fake@email')33 })34})35describe('My First Test', () => {36 it('Gets, types and asserts', () => {37 cy.contains('type').click()38 cy.url().should('include', '/commands/actions')39 cy.get('.action-email')40 .type('fake@email')41 .should('have.value', 'fake@email')
Using AI Code Generation
1describe('My First Test', () => {2 it('Does not do much!', () => {3 expect(true).to.equal(true)4 })5 })6describe('My First Test', () => {7 it('Does not do much!', () => {8 assert.equal(true, true)9 })10 })11describe('My First Test', () => {12 it('Does not do much!', () => {13 cy.contains('type').click()14 cy.url().should('include', '/commands/actions')15 cy.get('.action-email')16 .type('fake@email')17 .should('have.value', 'fake@email')18 })19 })20describe('My First Test', () => {21 it('Does not do much!', () => {22 cy.contains('type').click()23 cy.url().should('include', '/commands/actions')24 cy.get('.action-email')25 .type('fake@email')26 .should('have.value', 'fake@email')27 })28 })29describe('My First Test', () => {30 it('Does not do much!', () => {31 cy.contains('type').click()32 cy.url().should('include', '/commands/actions')33 cy.get('.action-email')34 .type('fake@email')35 .should('have.value', 'fake@email')36 })37 })38describe('My First Test', () => {39 it('Does not do much!', () => {40 cy.contains('type').click()
Using AI Code Generation
1describe('Test Suite', function() 2{3 it('Test case', function() 4 {5 cy.get('.search-keyword').type('ca')6 cy.wait(2000)7 cy.get('.products').as('productLocator')8 cy.get('@productLocator').find('.product').should('have.length',4)9 cy.get('@productLocator').find('.product').eq(2).contains('ADD TO CART').click().then(function()10 {11 console.log('sf')12 })13 cy.get('@productLocator').find('.product').each(($el, index, $list) => {14 const textVeg=$el.find('h4.product-name').text()15 if(textVeg.includes('Cashews'))16 {17 $el.find('button').click()18 }19 })20 cy.get('.brand').should('have.text','GREENKART')21 cy.get('.brand').then(function(logoelement)22 {23 cy.log(logoelement.text())24 })25 cy.get('.brand').then(function(logoelement)26 {27 cy.log(logoelement.text())28 })
Using AI Code Generation
1import { Given, When, Then, And } from "cypress-cucumber-preprocessor/steps";2Given('I open Google page', () => {3 })4 When('I type {string} in search field', (searchText) => {5 cy.get('input[name="q"]').type(searchText)6 })7 Then('I click on search button', () => {8 cy.get('input[value="Google Search"]').click()9 })10 Then('I should see {string} in the search results', (searchText) => {11 cy.get('.g').should('contain', searchText)12 })13 Then('the search result should have {string}', (searchText) => {14 cy.get('.g').should('contain', searchText)15 })16 And('I should see {string} in the search results', (searchText) => {17 cy.get('.g').should('contain', searchText)18 })19 And('I should see {string} in the search results', (searchText) => {20 cy.get('.g').should('contain', searchText)21 })22 And('I should see {string} in the search results', (searchText) => {23 cy.get('.g').should('contain', searchText)24 })25 And('I should see {string} in the search results', (searchText) => {26 cy.get('.g').should('contain', searchText)27 })28 And('I should see {string} in the search results', (searchText) => {29 cy.get('.g').should('contain', searchText)30 })31 And('I should see {string} in the search results', (searchText) => {32 cy.get('.g').should('contain', searchText)33 })34 And('I should see {string} in the search results', (searchText) => {35 cy.get('.g').should('contain', searchText)36 })37 And('I should see {string} in the search results', (searchText) => {38 cy.get('.g').should('contain', searchText)39 })40 And('I should see {string} in the search results', (searchText) => {41 cy.get('.g').should('contain', searchText)42 })
Using AI Code Generation
1describe('Login to the application', () => {2 it('should log in the application with valid credentials', () => {3 cy.get('#username').type('tomsmith')4 cy.get('#password').type('SuperSecretPassword!')5 cy.get('.fa').click()6 cy.url().should('include', '/secure')7 cy.get('#flash').should('be.visible').and('contain', 'You logged into a secure area!')8 })9})
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!!