How to use suite method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

Center.js

Source:Center.js Github

copy

Full Screen

1describe("Ext.layout.container.Center", function() {23 var ct, item;45 afterEach(function() {6 item = ct = Ext.destroy(ct);7 });89 function makeCt(cfg) {10 ct = new Ext.container.Container(Ext.apply({11 renderTo: Ext.getBody(),12 defaultType: 'component',13 layout: 'center'14 }, cfg));15 item = ct.items.getAt(0);16 }1718 function expectResult(w, h, left, top, ctWidth, ctHeight) {19 var pos = item.getEl().getStyle(['left', 'top']);20 expect(item.getWidth()).toBe(w);21 expect(item.getHeight()).toBe(h);22 expect(parseInt(pos.left, 10)).toBe(left);23 expect(parseInt(pos.top, 10)).toBe(top);24 expect(ct.getWidth()).toBe(ctWidth);25 expect(ct.getHeight()).toBe(ctHeight);26 }2728 function makeAutoSizer(w, h) {29 var css = [];30 if (w) {31 css.push('width: ' + w + 'px');32 }33 if (h) {34 css.push('height: ' + h + 'px');35 }36 return '<div style="' + css.join(';') + '"></div>';37 }3839 it("should respect bodyPadding when used as a panel", function() {40 var pad = 20;4142 ct = new Ext.panel.Panel({43 width: 400,44 height: 400,45 renderTo: Ext.getBody(),46 layout: 'center',47 bodyPadding: pad,48 border: false,49 items: {50 xtype: 'component',51 width: '100%',52 height: '100%'53 }54 });5556 item = ct.items.getAt(0);5758 expect(item.getX() - ct.getX()).toBe(pad);59 expect(item.getY() - ct.getY()).toBe(pad);60 });6162 describe("shrink wrapping child item where dimension is calculated", function() {63 it("should layout width correctly when width is being calculated by parent", function() {64 var p = new Ext.panel.Panel({65 renderTo: Ext.getBody(),66 height: 400,67 width: 400,68 dockedItems: [{69 xtype: 'container',70 dock: 'top',71 layout: 'center',72 items: [{73 xtype: 'component',74 html: makeAutoSizer(100, 30)75 }]76 }]77 });78 ct = p.getDockedItems()[0];79 item = ct.items.first();80 expectResult(100, 30, 150, 0, 400, 30);81 // Assign here so it gets destroyed.82 ct = p;83 });8485 it("should layout height correctly when width is being calculated by parent", function() {86 var p = new Ext.panel.Panel({87 renderTo: Ext.getBody(),88 height: 400,89 width: 400,90 dockedItems: [{91 xtype: 'container',92 dock: 'left',93 layout: 'center',94 items: [{95 xtype: 'component',96 html: makeAutoSizer(30, 100)97 }]98 }]99 });100 ct = p.getDockedItems()[0];101 item = ct.items.first();102 expectResult(30, 100, 0, 150, 30, 400);103 // Assign here so it gets destroyed.104 ct = p;105 });106 });107108 describe("container: fixed width, fixed height", function() {109 function makeSuiteCt(item) {110 makeCt({111 width: 400,112 height: 400,113 items: item114 });115 }116117 function expectSuiteResult(w, h, left, top) {118 // Ct size is static119 expectResult(w, h, left, top, 400, 400);120 }121122 describe("component: fixed width", function() {123 describe("fixed height", function() {124 it("should center the item", function() {125 makeSuiteCt({126 width: 200,127 height: 200128 });129 expectSuiteResult(200, 200, 100, 100);130 });131132 it("should take margins into account", function() {133 makeSuiteCt({134 width: 200,135 height: 200,136 margin: '20 30'137 });138 expectSuiteResult(200, 200, 70, 80);139 });140 });141142 describe("calculated height", function() {143 it("should center the item", function() {144 makeSuiteCt({145 width: 200,146 height: '40%'147 });148 expectSuiteResult(200, 160, 100, 120);149 });150151 it("should take margins into account", function() {152 makeSuiteCt({153 width: 200,154 height: '40%',155 margin: '20 30'156 });157 expectSuiteResult(200, 144, 70, 128);158 });159160 describe("constraints", function() {161 it("should take minHeight into account", function() {162 makeSuiteCt({163 width: 200,164 height: '10%',165 minHeight: 300166 });167 expectSuiteResult(200, 300, 100, 50);168 });169170 it("should take maxHeight into account", function() {171 makeSuiteCt({172 width: 200,173 height: '80%',174 maxHeight: 100175 });176 expectSuiteResult(200, 100, 100, 150);177 });178 });179 });180181 describe("auto height", function() {182 it("should center the item", function() {183 makeSuiteCt({184 width: 200,185 html: makeAutoSizer(null, 50)186 });187 expectSuiteResult(200, 50, 100, 175);188 });189190 it("should take margins into account", function() {191 makeSuiteCt({192 width: 200,193 html: makeAutoSizer(null, 50),194 margin: '20 30'195 });196 expectSuiteResult(200, 50, 70, 155);197 });198199 describe("constraints", function() {200 it("should take minHeight into account", function() {201 makeSuiteCt({202 width: 200,203 html: makeAutoSizer(null, 50),204 minHeight: 300205 });206 expectSuiteResult(200, 300, 100, 50);207 });208209 it("should take maxHeight into account", function() {210 makeSuiteCt({211 width: 200,212 html: makeAutoSizer(null, 300),213 maxHeight: 100214 });215 expectSuiteResult(200, 100, 100, 150);216 });217 });218 });219 });220221 describe("component: calculated width", function() {222 describe("fixed height", function() {223 it("should center the item", function() {224 makeSuiteCt({225 width: '80%',226 height: 200227 });228 expectSuiteResult(320, 200, 40, 100);229 });230231 it("should take margins into account", function() {232 makeSuiteCt({233 width: '80%',234 height: 200,235 margin: '20 30'236 });237 expectSuiteResult(272, 200, 64, 80);238 });239240 describe("constraints", function() {241 it("should take minWidth into account", function() {242 makeSuiteCt({243 width: '10%',244 minWidth: 320,245 height: 200246 });247 expectSuiteResult(320, 200, 40, 100);248 });249250 it("should take maxWidth into account", function() {251 makeSuiteCt({252 width: '80%',253 maxWidth: 100,254 height: 200255 });256 expectSuiteResult(100, 200, 150, 100);257 });258 });259 });260261 describe("calculated height", function() {262 it("should center the item", function() {263 makeSuiteCt({264 width: '80%',265 height: '40%'266 });267 expectSuiteResult(320, 160, 40, 120);268 });269270 it("should take margins into account", function() {271 makeSuiteCt({272 width: '80%',273 height: '40%',274 margin: '20 30'275 });276 expectSuiteResult(272, 144, 64, 128);277 });278279 describe("constraints", function() {280 it("should take minHeight into account", function() {281 makeSuiteCt({282 width: '80%',283 height: '40%',284 minHeight: 300285 });286 expectSuiteResult(320, 300, 40, 50);287 });288289 it("should take maxHeight into account", function() {290 makeSuiteCt({291 width: '80%',292 height: '40%',293 maxHeight: 50294 });295 expectSuiteResult(320, 50, 40, 175);296 });297298 it("should take minWidth into account", function() {299 makeSuiteCt({300 width: '80%',301 height: '40%',302 minWidth: 350303 });304 expectSuiteResult(350, 160, 25, 120);305 });306307 it("should take maxWidth into account", function() {308 makeSuiteCt({309 width: '80%',310 height: '40%',311 maxWidth: 100312 });313 expectSuiteResult(100, 160, 150, 120);314 });315 });316 });317318 describe("auto height", function() {319 it("should center the item", function() {320 makeSuiteCt({321 width: '80%',322 html: makeAutoSizer(null, 100)323 });324 expectSuiteResult(320, 100, 40, 150);325 });326327 it("should take margins into account", function() {328 makeSuiteCt({329 width: '80%',330 html: makeAutoSizer(null, 100),331 margin: '20 30'332 });333 expectSuiteResult(272, 100, 64, 130);334 });335336 describe("constraints", function() {337 it("should take minHeight into account", function() {338 makeSuiteCt({339 width: '80%',340 html: makeAutoSizer(null, 100),341 minHeight: 300342 });343 expectSuiteResult(320, 300, 40, 50);344 });345346 it("should take maxHeight into account", function() {347 makeSuiteCt({348 width: '80%',349 html: makeAutoSizer(null, 350),350 maxHeight: 300351 });352 expectSuiteResult(320, 300, 40, 50);353 });354355 it("should take minWidth into account", function() {356 makeSuiteCt({357 width: '80%',358 html: makeAutoSizer(null, 100),359 minWidth: 350360 });361 expectSuiteResult(350, 100, 25, 150);362 });363364 it("should take maxWidth into account", function() {365 makeSuiteCt({366 width: '80%',367 html: makeAutoSizer(null, 100),368 maxWidth: 100369 });370 expectSuiteResult(100, 100, 150, 150);371 });372 });373 });374 });375376 describe("component: auto width", function() {377 describe("fixed height", function() {378 it("should center the item", function() {379 makeSuiteCt({380 html: makeAutoSizer(200),381 height: 200382 });383 expectSuiteResult(200, 200, 100, 100);384 });385386 it("should take margins into account", function() {387 makeSuiteCt({388 html: makeAutoSizer(200),389 height: 200,390 margin: '20 30'391 });392 expectSuiteResult(200, 200, 70, 80);393 });394395 describe("constraints", function() {396 it("should take minWidth into account", function() {397 makeSuiteCt({398 html: makeAutoSizer(200),399 height: 200,400 minWidth: 300401 });402 expectSuiteResult(300, 200, 50, 100);403 });404405 it("should take maxWidth into account", function() {406 makeSuiteCt({407 html: makeAutoSizer(200),408 height: 200,409 maxWidth: 100410 });411 expectSuiteResult(100, 200, 150, 100);412 });413 });414 });415416 describe("calculated height", function() {417 it("should center the item", function() {418 makeSuiteCt({419 html: makeAutoSizer(200),420 height: '40%'421 });422 expectSuiteResult(200, 160, 100, 120);423 });424425 it("should take margins into account", function() {426 makeSuiteCt({427 html: makeAutoSizer(200),428 height: '40%',429 margin: '20 30'430 });431 expectSuiteResult(200, 144, 70, 128);432 });433434 describe("constraints", function() {435 it("should take minHeight into account", function() {436 makeSuiteCt({437 html: makeAutoSizer(200),438 height: '40%',439 minHeight: 300440 });441 expectSuiteResult(200, 300, 100, 50);442 });443444 it("should take maxHeight into account", function() {445 makeSuiteCt({446 html: makeAutoSizer(200),447 height: '40%',448 maxHeight: 50449 });450 expectSuiteResult(200, 50, 100, 175);451 });452453 it("should take minWidth into account", function() {454 makeSuiteCt({455 html: makeAutoSizer(200),456 height: '40%',457 minWidth: 300458 });459 expectSuiteResult(300, 160, 50, 120);460 });461462 it("should take maxWidth into account", function() {463 makeSuiteCt({464 html: makeAutoSizer(200),465 height: '40%',466 maxWidth: 100467 });468 expectSuiteResult(100, 160, 150, 120);469 });470 });471 });472473 describe("auto height", function() {474 it("should center the item", function() {475 makeSuiteCt({476 html: makeAutoSizer(200, 100)477 });478 expectSuiteResult(200, 100, 100, 150);479 });480481 it("should take margins into account", function() {482 makeSuiteCt({483 html: makeAutoSizer(200, 100),484 margin: '20 30'485 });486 expectSuiteResult(200, 100, 70, 130);487 });488489 describe("constraints", function() {490 it("should take minHeight into account", function() {491 makeSuiteCt({492 html: makeAutoSizer(200, 100),493 minHeight: 300494 });495 expectSuiteResult(200, 300, 100, 50);496 });497498 it("should take maxHeight into account", function() {499 makeSuiteCt({500 html: makeAutoSizer(200, 100),501 maxHeight: 50502 });503 expectSuiteResult(200, 50, 100, 175);504 });505506 it("should take minWidth into account", function() {507 makeSuiteCt({508 html: makeAutoSizer(200, 100),509 minWidth: 300510 });511 expectSuiteResult(300, 100, 50, 150);512 });513514 it("should take maxWidth into account", function() {515 makeSuiteCt({516 html: makeAutoSizer(200, 100),517 maxWidth: 100518 });519 expectSuiteResult(100, 100, 150, 150);520 });521 });522 });523 });524 });525526 describe("container: fixed width, auto height", function() {527 function makeSuiteCt(item) {528 makeCt({529 width: 400,530 items: item531 });532 }533534 function expectSuiteResult(w, h, left, ctHeight) {535 // Top of the item & ctWidth are static536 expectResult(w, h, left, 0, 400, ctHeight);537 }538539 describe("component: fixed width", function() {540 describe("fixed height", function() {541 it("should center the item", function() {542 makeSuiteCt({543 width: 200,544 height: 200545 });546 expectSuiteResult(200, 200, 100, 200);547 });548549 it("should take margins into account", function() {550 makeSuiteCt({551 width: 200,552 height: 200,553 margin: '20 30'554 });555 expectSuiteResult(200, 200, 70, 240);556 });557 });558559 describe("calculated height", function() {560 it("should center the item", function() {561 makeSuiteCt({562 width: 200,563 height: '40%'564 });565 expectSuiteResult(200, 0, 100, 0);566 });567568 it("should take margins into account", function() {569 makeSuiteCt({570 width: 200,571 height: '40%',572 margin: '20 30'573 });574 expectSuiteResult(200, 0, 70, 40);575 });576577 describe("constraints", function() {578 it("should take minHeight into account", function() {579 makeSuiteCt({580 width: 200,581 height: '10%',582 minHeight: 300583 });584 expectSuiteResult(200, 300, 100, 300);585 });586587 it("should take maxHeight into account", function() {588 makeSuiteCt({589 width: 200,590 height: '80%',591 maxHeight: 100592 });593 expectSuiteResult(200, 0, 100, 0);594 });595 });596 });597598 describe("auto height", function() {599 it("should center the item", function() {600 makeSuiteCt({601 width: 200,602 html: makeAutoSizer(null, 50)603 });604 expectSuiteResult(200, 50, 100, 50);605 });606607 it("should take margins into account", function() {608 makeSuiteCt({609 width: 200,610 html: makeAutoSizer(null, 50),611 margin: '20 30'612 });613 expectSuiteResult(200, 50, 70, 90);614 });615616 describe("constraints", function() {617 it("should take minHeight into account", function() {618 makeSuiteCt({619 width: 200,620 html: makeAutoSizer(null, 50),621 minHeight: 300622 });623 expectSuiteResult(200, 300, 100, 300);624 });625626 it("should take maxHeight into account", function() {627 makeSuiteCt({628 width: 200,629 html: makeAutoSizer(null, 300),630 maxHeight: 100631 });632 expectSuiteResult(200, 100, 100, 100);633 });634 });635 });636 });637638 describe("component: calculated width", function() {639 describe("fixed height", function() {640 it("should center the item", function() {641 makeSuiteCt({642 width: '80%',643 height: 200644 });645 expectSuiteResult(320, 200, 40, 200);646 });647648 it("should take margins into account", function() {649 makeSuiteCt({650 width: '80%',651 height: 200,652 margin: '20 30'653 });654 expectSuiteResult(272, 200, 64, 240);655 });656657 describe("constraints", function() {658 it("should take minWidth into account", function() {659 makeSuiteCt({660 width: '10%',661 minWidth: 320,662 height: 200663 });664 expectSuiteResult(320, 200, 40, 200);665 });666667 it("should take maxWidth into account", function() {668 makeSuiteCt({669 width: '80%',670 maxWidth: 100,671 height: 200672 });673 expectSuiteResult(100, 200, 150, 200);674 });675 });676 });677678 describe("calculated height", function() {679 it("should center the item", function() {680 makeSuiteCt({681 width: '80%',682 height: '40%'683 });684 expectSuiteResult(320, 0, 40, 0);685 });686687 it("should take margins into account", function() {688 makeSuiteCt({689 width: '80%',690 height: '40%',691 margin: '20 30'692 });693 expectSuiteResult(272, 0, 64, 40);694 });695696 describe("constraints", function() {697 it("should take minHeight into account", function() {698 makeSuiteCt({699 width: '80%',700 height: '40%',701 minHeight: 300702 });703 expectSuiteResult(320, 300, 40, 300);704 });705706 it("should take maxHeight into account", function() {707 makeSuiteCt({708 width: '80%',709 height: '40%',710 maxHeight: 50711 });712 expectSuiteResult(320, 0, 40, 0);713 });714715 it("should take minWidth into account", function() {716 makeSuiteCt({717 width: '80%',718 height: '40%',719 minWidth: 350720 });721 expectSuiteResult(350, 0, 25, 0);722 });723724 it("should take maxWidth into account", function() {725 makeSuiteCt({726 width: '80%',727 height: '40%',728 maxWidth: 100729 });730 expectSuiteResult(100, 0, 150, 0);731 });732 });733 });734735 describe("auto height", function() {736 it("should center the item", function() {737 makeSuiteCt({738 width: '80%',739 html: makeAutoSizer(null, 100)740 });741 expectSuiteResult(320, 100, 40, 100);742 });743744 it("should take margins into account", function() {745 makeSuiteCt({746 width: '80%',747 html: makeAutoSizer(null, 100),748 margin: '20 30'749 });750 expectSuiteResult(272, 100, 64, 140);751 });752753 describe("constraints", function() {754 it("should take minHeight into account", function() {755 makeSuiteCt({756 width: '80%',757 html: makeAutoSizer(null, 100),758 minHeight: 300759 });760 expectSuiteResult(320, 300, 40, 300);761 });762763 it("should take maxHeight into account", function() {764 makeSuiteCt({765 width: '80%',766 html: makeAutoSizer(null, 350),767 maxHeight: 300768 });769 expectSuiteResult(320, 300, 40, 300);770 });771772 it("should take minWidth into account", function() {773 makeSuiteCt({774 width: '80%',775 html: makeAutoSizer(null, 100),776 minWidth: 350777 });778 expectSuiteResult(350, 100, 25, 100);779 });780781 it("should take maxWidth into account", function() {782 makeSuiteCt({783 width: '80%',784 html: makeAutoSizer(null, 100),785 maxWidth: 100786 });787 expectSuiteResult(100, 100, 150, 100);788 });789 });790 });791 });792793 describe("component: auto width", function() {794 describe("fixed height", function() {795 it("should center the item", function() {796 makeSuiteCt({797 html: makeAutoSizer(200),798 height: 200799 });800 expectSuiteResult(200, 200, 100, 200);801 });802803 it("should take margins into account", function() {804 makeSuiteCt({805 html: makeAutoSizer(200),806 height: 200,807 margin: '20 30'808 });809 expectSuiteResult(200, 200, 70, 240);810 });811812 describe("constraints", function() {813 it("should take minWidth into account", function() {814 makeSuiteCt({815 html: makeAutoSizer(200),816 height: 200,817 minWidth: 300818 });819 expectSuiteResult(300, 200, 50, 200);820 });821822 it("should take maxWidth into account", function() {823 makeSuiteCt({824 html: makeAutoSizer(200),825 height: 200,826 maxWidth: 100827 });828 expectSuiteResult(100, 200, 150, 200);829 });830 });831 });832833 describe("calculated height", function() {834 it("should center the item", function() {835 makeSuiteCt({836 html: makeAutoSizer(200),837 height: '40%'838 });839 expectSuiteResult(200, 0, 100, 0);840 });841842 it("should take margins into account", function() {843 makeSuiteCt({844 html: makeAutoSizer(200),845 height: '40%',846 margin: '20 30'847 });848 expectSuiteResult(200, 0, 70, 40);849 });850851 describe("constraints", function() {852 it("should take minHeight into account", function() {853 makeSuiteCt({854 html: makeAutoSizer(200),855 height: '40%',856 minHeight: 300857 });858 expectSuiteResult(200, 300, 100, 300);859 });860861 it("should take maxHeight into account", function() {862 makeSuiteCt({863 html: makeAutoSizer(200),864 height: '40%',865 maxHeight: 50866 });867 expectSuiteResult(200, 0, 100, 0);868 });869870 it("should take minWidth into account", function() {871 makeSuiteCt({872 html: makeAutoSizer(200),873 height: '40%',874 minWidth: 300875 });876 expectSuiteResult(300, 0, 50, 0);877 });878879 it("should take maxWidth into account", function() {880 makeSuiteCt({881 html: makeAutoSizer(200),882 height: '40%',883 maxWidth: 100884 });885 expectSuiteResult(100, 0, 150, 0);886 });887 });888 });889890 describe("auto height", function() {891 it("should center the item", function() {892 makeSuiteCt({893 html: makeAutoSizer(200, 100)894 });895 expectSuiteResult(200, 100, 100, 100);896 });897898 it("should take margins into account", function() {899 makeSuiteCt({900 html: makeAutoSizer(200, 100),901 margin: '20 30'902 });903 expectSuiteResult(200, 100, 70, 140);904 });905906 describe("constraints", function() {907 it("should take minHeight into account", function() {908 makeSuiteCt({909 html: makeAutoSizer(200, 100),910 minHeight: 300911 });912 expectSuiteResult(200, 300, 100, 300);913 });914915 it("should take maxHeight into account", function() {916 makeSuiteCt({917 html: makeAutoSizer(200, 100),918 maxHeight: 50919 });920 expectSuiteResult(200, 50, 100, 50);921 });922923 it("should take minWidth into account", function() {924 makeSuiteCt({925 html: makeAutoSizer(200, 100),926 minWidth: 300927 });928 expectSuiteResult(300, 100, 50, 100);929 });930931 it("should take maxWidth into account", function() {932 makeSuiteCt({933 html: makeAutoSizer(200, 100),934 maxWidth: 100935 });936 expectSuiteResult(100, 100, 150, 100);937 });938 });939 });940 });941 });942943 describe("container: auto width, fixed height", function() {944 function makeSuiteCt(item) {945 makeCt({946 floating: true, // Float the ct so it shrink wraps947 height: 400,948 items: item949 });950 }951952 function expectSuiteResult(w, h, top, ctWidth) {953 // Left of the item & ctHeight are static954 expectResult(w, h, 0, top, ctWidth, 400);955 }956957 describe("component: fixed width", function() {958 describe("fixed height", function() {959 it("should center the item", function() {960 makeSuiteCt({961 width: 200,962 height: 200963 });964 expectSuiteResult(200, 200, 100, 200);965 });966967 it("should take margins into account", function() {968 makeSuiteCt({969 width: 200,970 height: 200,971 margin: '20 30'972 });973 expectSuiteResult(200, 200, 80, 260);974 });975 });976977 describe("calculated height", function() {978 it("should center the item", function() {979 makeSuiteCt({980 width: 200,981 height: '40%'982 });983 expectSuiteResult(200, 160, 120, 200);984 });985986 it("should take margins into account", function() {987 makeSuiteCt({988 width: 200,989 height: '40%',990 margin: '20 30'991 });992 expectSuiteResult(200, 144, 128, 260);993 });994995 describe("constraints", function() {996 it("should take minHeight into account", function() {997 makeSuiteCt({998 width: 200,999 height: '10%',1000 minHeight: 3001001 });1002 expectSuiteResult(200, 300, 50, 200);1003 });10041005 it("should take maxHeight into account", function() {1006 makeSuiteCt({1007 width: 200,1008 height: '80%',1009 maxHeight: 1001010 });1011 expectSuiteResult(200, 100, 150, 200);1012 });1013 });1014 });10151016 describe("auto height", function() {1017 it("should center the item", function() {1018 makeSuiteCt({1019 width: 200,1020 html: makeAutoSizer(null, 50)1021 });1022 expectSuiteResult(200, 50, 175, 200);1023 });10241025 it("should take margins into account", function() {1026 makeSuiteCt({1027 width: 200,1028 html: makeAutoSizer(null, 50),1029 margin: '20 30'1030 });1031 expectSuiteResult(200, 50, 155, 260);1032 });10331034 describe("constraints", function() {1035 it("should take minHeight into account", function() {1036 makeSuiteCt({1037 width: 200,1038 html: makeAutoSizer(null, 50),1039 minHeight: 3001040 });1041 expectSuiteResult(200, 300, 50, 200);1042 });10431044 it("should take maxHeight into account", function() {1045 makeSuiteCt({1046 width: 200,1047 html: makeAutoSizer(null, 300),1048 maxHeight: 1001049 });1050 expectSuiteResult(200, 100, 150, 200);1051 });1052 });1053 });1054 });10551056 describe("component: calculated width", function() {1057 describe("fixed height", function() {1058 it("should center the item", function() {1059 makeSuiteCt({1060 width: '80%',1061 height: 2001062 });1063 expectSuiteResult(0, 200, 100, 0);1064 });10651066 it("should take margins into account", function() {1067 makeSuiteCt({1068 width: '80%',1069 height: 200,1070 margin: '20 30'1071 });1072 expectSuiteResult(0, 200, 80, 60);1073 });10741075 describe("constraints", function() {1076 it("should take minWidth into account", function() {1077 makeSuiteCt({1078 width: '10%',1079 minWidth: 320,1080 height: 2001081 });1082 expectSuiteResult(320, 200, 100, 320);1083 });10841085 it("should take maxWidth into account", function() {1086 makeSuiteCt({1087 width: '80%',1088 maxWidth: 100,1089 height: 2001090 });1091 expectSuiteResult(0, 200, 100, 0);1092 });1093 });1094 });10951096 describe("calculated height", function() {1097 it("should center the item", function() {1098 makeSuiteCt({1099 width: '80%',1100 height: '40%'1101 });1102 expectSuiteResult(0, 160, 120, 0);1103 });11041105 it("should take margins into account", function() {1106 makeSuiteCt({1107 width: '80%',1108 height: '40%',1109 margin: '20 30'1110 });1111 expectSuiteResult(0, 144, 128, 60);1112 });11131114 describe("constraints", function() {1115 it("should take minHeight into account", function() {1116 makeSuiteCt({1117 width: '80%',1118 height: '40%',1119 minHeight: 3001120 });1121 expectSuiteResult(0, 300, 50, 0);1122 });11231124 it("should take maxHeight into account", function() {1125 makeSuiteCt({1126 width: '80%',1127 height: '40%',1128 maxHeight: 501129 });1130 expectSuiteResult(0, 50, 175, 0);1131 });11321133 it("should take minWidth into account", function() {1134 makeSuiteCt({1135 width: '80%',1136 height: '40%',1137 minWidth: 3501138 });1139 expectSuiteResult(350, 160, 120, 350);1140 });11411142 it("should take maxWidth into account", function() {1143 makeSuiteCt({1144 width: '80%',1145 height: '40%',1146 maxWidth: 1001147 });1148 expectSuiteResult(0, 160, 120, 0);1149 });1150 });1151 });11521153 describe("auto height", function() {1154 it("should center the item", function() {1155 makeSuiteCt({1156 width: '80%',1157 html: makeAutoSizer(null, 100)1158 });1159 expectSuiteResult(0, 100, 150, 0);1160 });11611162 it("should take margins into account", function() {1163 makeSuiteCt({1164 width: '80%',1165 html: makeAutoSizer(null, 100),1166 margin: '20 30'1167 });1168 expectSuiteResult(0, 100, 130, 60);1169 });11701171 describe("constraints", function() {1172 it("should take minHeight into account", function() {1173 makeSuiteCt({1174 width: '80%',1175 html: makeAutoSizer(null, 100),1176 minHeight: 3001177 });1178 expectSuiteResult(0, 300, 50, 0);1179 });11801181 it("should take maxHeight into account", function() {1182 makeSuiteCt({1183 width: '80%',1184 html: makeAutoSizer(null, 350),1185 maxHeight: 3001186 });1187 expectSuiteResult(0, 300, 50, 0);1188 });11891190 it("should take minWidth into account", function() {1191 makeSuiteCt({1192 width: '80%',1193 html: makeAutoSizer(null, 100),1194 minWidth: 3501195 });1196 expectSuiteResult(350, 100, 150, 350);1197 });11981199 it("should take maxWidth into account", function() {1200 makeSuiteCt({1201 width: '80%',1202 html: makeAutoSizer(null, 100),1203 maxWidth: 1001204 });1205 expectSuiteResult(0, 100, 150, 0);1206 });1207 });1208 });1209 });12101211 describe("component: auto width", function() {1212 describe("fixed height", function() {1213 it("should center the item", function() {1214 makeSuiteCt({1215 html: makeAutoSizer(200),1216 height: 2001217 });1218 expectSuiteResult(200, 200, 100, 200);1219 });12201221 it("should take margins into account", function() {1222 makeSuiteCt({1223 html: makeAutoSizer(200),1224 height: 200,1225 margin: '20 30'1226 });1227 expectSuiteResult(200, 200, 80, 260);1228 });12291230 describe("constraints", function() {1231 it("should take minWidth into account", function() {1232 makeSuiteCt({1233 html: makeAutoSizer(200),1234 height: 200,1235 minWidth: 3001236 });1237 expectSuiteResult(300, 200, 100, 300);1238 });12391240 it("should take maxWidth into account", function() {1241 makeSuiteCt({1242 html: makeAutoSizer(200),1243 height: 200,1244 maxWidth: 1001245 });1246 expectSuiteResult(100, 200, 100, 100);1247 });1248 });1249 });12501251 describe("calculated height", function() {1252 it("should center the item", function() {1253 makeSuiteCt({1254 html: makeAutoSizer(200),1255 height: '40%'1256 });1257 expectSuiteResult(200, 160, 120, 200);1258 });12591260 it("should take margins into account", function() {1261 makeSuiteCt({1262 html: makeAutoSizer(200),1263 height: '40%',1264 margin: '20 30'1265 });1266 expectSuiteResult(200, 144, 128, 260);1267 });12681269 describe("constraints", function() {1270 it("should take minHeight into account", function() {1271 makeSuiteCt({1272 html: makeAutoSizer(200),1273 height: '40%',1274 minHeight: 3001275 });1276 expectSuiteResult(200, 300, 50, 200);1277 });12781279 it("should take maxHeight into account", function() {1280 makeSuiteCt({1281 html: makeAutoSizer(200),1282 height: '40%',1283 maxHeight: 501284 });1285 expectSuiteResult(200, 50, 175, 200);1286 });12871288 it("should take minWidth into account", function() {1289 makeSuiteCt({1290 html: makeAutoSizer(200),1291 height: '40%',1292 minWidth: 3001293 });1294 expectSuiteResult(300, 160, 120, 300);1295 });12961297 it("should take maxWidth into account", function() {1298 makeSuiteCt({1299 html: makeAutoSizer(200),1300 height: '40%',1301 maxWidth: 1001302 });1303 expectSuiteResult(100, 160, 120, 100);1304 });1305 });1306 });13071308 describe("auto height", function() {1309 it("should center the item", function() {1310 makeSuiteCt({1311 html: makeAutoSizer(200, 100)1312 });1313 expectSuiteResult(200, 100, 150, 200);1314 });13151316 it("should take margins into account", function() {1317 makeSuiteCt({1318 html: makeAutoSizer(200, 100),1319 margin: '20 30'1320 });1321 expectSuiteResult(200, 100, 130, 260);1322 });13231324 describe("constraints", function() {1325 it("should take minHeight into account", function() {1326 makeSuiteCt({1327 html: makeAutoSizer(200, 100),1328 minHeight: 3001329 });1330 expectSuiteResult(200, 300, 50, 200);1331 });13321333 it("should take maxHeight into account", function() {1334 makeSuiteCt({1335 html: makeAutoSizer(200, 100),1336 maxHeight: 501337 });1338 expectSuiteResult(200, 50, 175, 200);1339 });13401341 it("should take minWidth into account", function() {1342 makeSuiteCt({1343 html: makeAutoSizer(200, 100),1344 minWidth: 3001345 });1346 expectSuiteResult(300, 100, 150, 300);1347 });13481349 it("should take maxWidth into account", function() {1350 makeSuiteCt({1351 html: makeAutoSizer(200, 100),1352 maxWidth: 1001353 });1354 expectSuiteResult(100, 100, 150, 100);1355 });1356 });1357 });1358 });1359 });13601361 describe("container: auto width, auto height", function() {1362 function makeSuiteCt(item) {1363 makeCt({1364 floating: true, // Float the ct so it shrink wraps1365 items: item1366 });1367 }13681369 function expectSuiteResult(w, h, ctWidth, ctHeight) {1370 // Position of the item should always be 0,01371 expectResult(w, h, 0, 0, ctWidth, ctHeight);1372 }13731374 describe("component: fixed width", function() {1375 describe("fixed height", function() {1376 it("should center the item", function() {1377 makeSuiteCt({1378 width: 200,1379 height: 2001380 });1381 expectSuiteResult(200, 200, 200, 200);1382 });13831384 it("should take margins into account", function() {1385 makeSuiteCt({1386 width: 200,1387 height: 200,1388 margin: '20 30'1389 });1390 expectSuiteResult(200, 200, 260, 240);1391 });1392 });13931394 describe("calculated height", function() {1395 it("should center the item", function() {1396 makeSuiteCt({1397 width: 200,1398 height: '40%'1399 });1400 expectSuiteResult(200, 0, 200, 0);1401 });14021403 it("should take margins into account", function() {1404 makeSuiteCt({1405 width: 200,1406 height: '40%',1407 margin: '20 30'1408 });1409 expectSuiteResult(200, 0, 260, 40);1410 });14111412 describe("constraints", function() {1413 it("should take minHeight into account", function() {1414 makeSuiteCt({1415 width: 200,1416 height: '10%',1417 minHeight: 3001418 });1419 expectSuiteResult(200, 300, 200, 300);1420 });14211422 it("should take maxHeight into account", function() {1423 makeSuiteCt({1424 width: 200,1425 height: '80%',1426 maxHeight: 1001427 });1428 expectSuiteResult(200, 0, 200, 0);1429 });1430 });1431 });14321433 describe("auto height", function() {1434 it("should center the item", function() {1435 makeSuiteCt({1436 width: 200,1437 html: makeAutoSizer(null, 50)1438 });1439 expectSuiteResult(200, 50, 200, 50);1440 });14411442 it("should take margins into account", function() {1443 makeSuiteCt({1444 width: 200,1445 html: makeAutoSizer(null, 50),1446 margin: '20 30'1447 });1448 expectSuiteResult(200, 50, 260, 90);1449 });14501451 describe("constraints", function() {1452 it("should take minHeight into account", function() {1453 makeSuiteCt({1454 width: 200,1455 html: makeAutoSizer(null, 50),1456 minHeight: 3001457 });1458 expectSuiteResult(200, 300, 200, 300);1459 });14601461 it("should take maxHeight into account", function() {1462 makeSuiteCt({1463 width: 200,1464 html: makeAutoSizer(null, 300),1465 maxHeight: 1001466 });1467 expectSuiteResult(200, 100, 200, 100);1468 });1469 });1470 });1471 });14721473 describe("component: calculated width", function() {1474 describe("fixed height", function() {1475 it("should center the item", function() {1476 makeSuiteCt({1477 width: '80%',1478 height: 2001479 });1480 expectSuiteResult(0, 200, 0, 200);1481 });14821483 it("should take margins into account", function() {1484 makeSuiteCt({1485 width: '80%',1486 height: 200,1487 margin: '20 30'1488 });1489 expectSuiteResult(0, 200, 60, 240);1490 });14911492 describe("constraints", function() {1493 it("should take minWidth into account", function() {1494 makeSuiteCt({1495 width: '10%',1496 minWidth: 320,1497 height: 2001498 });1499 expectSuiteResult(320, 200, 320, 200);1500 });15011502 it("should take maxWidth into account", function() {1503 makeSuiteCt({1504 width: '80%',1505 maxWidth: 100,1506 height: 2001507 });1508 expectSuiteResult(0, 200, 0, 200);1509 });1510 });1511 });15121513 describe("calculated height", function() {1514 it("should center the item", function() {1515 makeSuiteCt({1516 width: '80%',1517 height: '40%'1518 });1519 expectSuiteResult(0, 0, 0, 0);1520 });15211522 it("should take margins into account", function() {1523 makeSuiteCt({1524 width: '80%',1525 height: '40%',1526 margin: '20 30'1527 });1528 expectSuiteResult(0, 0, 60, 40);1529 });15301531 describe("constraints", function() {1532 it("should take minHeight into account", function() {1533 makeSuiteCt({1534 width: '80%',1535 height: '40%',1536 minHeight: 3001537 });1538 expectSuiteResult(0, 300, 0, 300);1539 });15401541 it("should take maxHeight into account", function() {1542 makeSuiteCt({1543 width: '80%',1544 height: '40%',1545 maxHeight: 501546 });1547 expectSuiteResult(0, 0, 0, 0);1548 });15491550 it("should take minWidth into account", function() {1551 makeSuiteCt({1552 width: '80%',1553 height: '40%',1554 minWidth: 3501555 });1556 expectSuiteResult(350, 0, 350, 0);1557 });15581559 it("should take maxWidth into account", function() {1560 makeSuiteCt({1561 width: '80%',1562 height: '40%',1563 maxWidth: 1001564 });1565 expectSuiteResult(0, 0, 0, 0);1566 });1567 });1568 });15691570 describe("auto height", function() {1571 it("should center the item", function() {1572 makeSuiteCt({1573 width: '80%',1574 html: makeAutoSizer(null, 100)1575 });1576 expectSuiteResult(0, 100, 0, 100);1577 });15781579 it("should take margins into account", function() {1580 makeSuiteCt({1581 width: '80%',1582 html: makeAutoSizer(null, 100),1583 margin: '20 30'1584 });1585 expectSuiteResult(0, 100, 60, 140);1586 });15871588 describe("constraints", function() {1589 it("should take minHeight into account", function() {1590 makeSuiteCt({1591 width: '80%',1592 html: makeAutoSizer(null, 100),1593 minHeight: 3001594 });1595 expectSuiteResult(0, 300, 0, 300);1596 });15971598 it("should take maxHeight into account", function() {1599 makeSuiteCt({1600 width: '80%',1601 html: makeAutoSizer(null, 350),1602 maxHeight: 3001603 });1604 expectSuiteResult(0, 300, 0, 300);1605 });16061607 it("should take minWidth into account", function() {1608 makeSuiteCt({1609 width: '80%',1610 html: makeAutoSizer(null, 100),1611 minWidth: 3501612 });1613 expectSuiteResult(350, 100, 350, 100);1614 });16151616 it("should take maxWidth into account", function() {1617 makeSuiteCt({1618 width: '80%',1619 html: makeAutoSizer(null, 100),1620 maxWidth: 1001621 });1622 expectSuiteResult(0, 100, 0, 100);1623 });1624 });1625 });1626 });16271628 describe("component: auto width", function() {1629 describe("fixed height", function() {1630 it("should center the item", function() {1631 makeSuiteCt({1632 html: makeAutoSizer(200),1633 height: 2001634 });1635 expectSuiteResult(200, 200, 200, 200);1636 });16371638 it("should take margins into account", function() {1639 makeSuiteCt({1640 html: makeAutoSizer(200),1641 height: 200,1642 margin: '20 30'1643 });1644 expectSuiteResult(200, 200, 260, 240);1645 });16461647 describe("constraints", function() {1648 it("should take minWidth into account", function() {1649 makeSuiteCt({1650 html: makeAutoSizer(200),1651 height: 200,1652 minWidth: 3001653 });1654 expectSuiteResult(300, 200, 300, 200);1655 });16561657 it("should take maxWidth into account", function() {1658 makeSuiteCt({1659 html: makeAutoSizer(200),1660 height: 200,1661 maxWidth: 1001662 });1663 expectSuiteResult(100, 200, 100, 200);1664 });1665 });1666 });16671668 describe("calculated height", function() {1669 it("should center the item", function() {1670 makeSuiteCt({1671 html: makeAutoSizer(200),1672 height: '40%'1673 });1674 expectSuiteResult(200, 0, 200, 0);1675 });16761677 it("should take margins into account", function() {1678 makeSuiteCt({1679 html: makeAutoSizer(200),1680 height: '40%',1681 margin: '20 30'1682 });1683 expectSuiteResult(200, 0, 260, 40);1684 });16851686 describe("constraints", function() {1687 it("should take minHeight into account", function() {1688 makeSuiteCt({1689 html: makeAutoSizer(200),1690 height: '40%',1691 minHeight: 3001692 });1693 expectSuiteResult(200, 300, 200, 300);1694 });16951696 it("should take maxHeight into account", function() {1697 makeSuiteCt({1698 html: makeAutoSizer(200),1699 height: '40%',1700 maxHeight: 501701 });1702 expectSuiteResult(200, 0, 200, 0);1703 });17041705 it("should take minWidth into account", function() {1706 makeSuiteCt({1707 html: makeAutoSizer(200),1708 height: '40%',1709 minWidth: 3001710 });1711 expectSuiteResult(300, 0, 300, 0);1712 });17131714 it("should take maxWidth into account", function() {1715 makeSuiteCt({1716 html: makeAutoSizer(200),1717 height: '40%',1718 maxWidth: 1001719 });1720 expectSuiteResult(100, 0, 100, 0);1721 });1722 });1723 });17241725 describe("auto height", function() {1726 it("should center the item", function() {1727 makeSuiteCt({1728 html: makeAutoSizer(200, 100)1729 });1730 expectSuiteResult(200, 100, 200, 100);1731 });17321733 it("should take margins into account", function() {1734 makeSuiteCt({1735 html: makeAutoSizer(200, 100),1736 margin: '20 30'1737 });1738 expectSuiteResult(200, 100, 260, 140);1739 });17401741 describe("constraints", function() {1742 it("should take minHeight into account", function() {1743 makeSuiteCt({1744 html: makeAutoSizer(200, 100),1745 minHeight: 3001746 });1747 expectSuiteResult(200, 300, 200, 300);1748 });17491750 it("should take maxHeight into account", function() {1751 makeSuiteCt({1752 html: makeAutoSizer(200, 100),1753 maxHeight: 501754 });1755 expectSuiteResult(200, 50, 200, 50);1756 });17571758 it("should take minWidth into account", function() {1759 makeSuiteCt({1760 html: makeAutoSizer(200, 100),1761 minWidth: 3001762 });1763 expectSuiteResult(300, 100, 300, 100);1764 });17651766 it("should take maxWidth into account", function() {1767 makeSuiteCt({1768 html: makeAutoSizer(200, 100),1769 maxWidth: 1001770 });1771 expectSuiteResult(100, 100, 100, 100);1772 });1773 });1774 });1775 });1776 });1777 ...

Full Screen

Full Screen

testcase_grid.js

Source:testcase_grid.js Github

copy

Full Screen

1/*2 * Copyright 2017 SideeX committers3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 *16 */17function cleanSelected() {18 // use jquery's API to add and remove class property19 $('#testCase-grid .selectedCase').removeClass('selectedCase');20 $('#testCase-grid .selectedSuite').removeClass('selectedSuite');21}22function setSelectedSuite(id) {23 saveOldCase();24 cleanSelected();25 $("#" + id).addClass('selectedSuite');26 clean_panel();27}28function setSelectedCase(id) {29 saveOldCase();30 var suite_id = document.getElementById(id).parentNode.id;31 setSelectedSuite(suite_id);32 $("#" + id).addClass('selectedCase');33 clean_panel();34 document.getElementById("records-grid").innerHTML = escapeHTML(sideex_testCase[id].records);35 attachEvent(1, getRecordsNum());36}37function getSelectedSuite() {38 if (document.getElementById("testCase-grid").getElementsByClassName("selectedSuite")) {39 return document.getElementById("testCase-grid").getElementsByClassName("selectedSuite")[0];40 } else {41 return null;42 }43}44function getSelectedCase() {45 if (document.getElementById("testCase-grid").getElementsByClassName("selectedCase")) {46 return document.getElementById("testCase-grid").getElementsByClassName("selectedCase")[0];47 } else {48 return null;49 }50}51function getSuiteNum() {52 return document.getElementById("testCase-grid").getElementsByTagName("DIV").length;53}54function getCaseNumInSuite() {55 let selectedSuite = getSelectedSuite();56 if (selectedSuite != null) {57 return selectedSuite.getElementsByTagName("P").length;58 }59 return 0;60}61function saveOldCase() {62 var old_case = getSelectedCase();63 if (old_case) {64 sideex_testCase[old_case.id].records = document.getElementById("records-grid").innerHTML;65 }66}67function appendContextMenu(node, isCase) {68 var ul = document.createElement("ul");69 var a;70 if (isCase) {71 var add_case = document.createElement("li");72 a = document.createElement("a");73 a.setAttribute("href", "#");74 a.textContent = "Add New Test Case";75 add_case.appendChild(a);76 add_case.addEventListener("click", function(event) {77 event.stopPropagation();78 document.getElementById('add-testCase').click();79 }, false);80 ul.appendChild(add_case);81 var remove_case = document.createElement("li");82 a = document.createElement("a");83 a.setAttribute("href", "#");84 a.textContent = "Remove Test Case";85 remove_case.appendChild(a);86 remove_case.addEventListener("click", function(event) {87 event.stopPropagation();88 document.getElementById('delete-testCase').click();89 }, false);90 ul.appendChild(remove_case);91 var rename_case = document.createElement("li");92 a = document.createElement("a");93 a.setAttribute("href", "#");94 a.textContent = "Rename Test Case";95 rename_case.appendChild(a);96 rename_case.addEventListener("click", function(event) {97 event.stopPropagation();98 var s_case = getSelectedCase();99 var n_title = prompt("Please enter the Test Case's name", sideex_testCase[s_case.id].title);100 if (n_title) {101 // get text node102 s_case.childNodes[0].textContent = n_title;103 sideex_testCase[s_case.id].title = n_title;104 }105 }, false);106 ul.appendChild(rename_case);107 } else {108 var open_suite = document.createElement("li");109 a = document.createElement("a");110 a.setAttribute("href", "#");111 a.textContent = "Open Test Suites";112 open_suite.appendChild(a);113 open_suite.addEventListener("click", function(event) {114 event.stopPropagation();115 document.getElementById('load-testSuite-hidden').click();116 }, false);117 ul.appendChild(open_suite);118 var add_suite = document.createElement("li");119 a = document.createElement("a");120 a.setAttribute("href", "#");121 a.textContent = "Add New Test Suite";122 add_suite.appendChild(a);123 add_suite.addEventListener("click", function(event) {124 event.stopPropagation();125 document.getElementById("add-testSuite").click();126 }, false);127 ul.appendChild(add_suite);128 var save_suite = document.createElement("li");129 a = document.createElement("a");130 a.setAttribute("href", "#");131 a.textContent = "Save Test Suite As...";132 save_suite.appendChild(a);133 save_suite.addEventListener("click", function(event) {134 event.stopPropagation();135 document.getElementById('save-testSuite').click();136 }, false);137 ul.appendChild(save_suite);138 var close_suite = document.createElement("li");139 a = document.createElement("a");140 a.setAttribute("href", "#");141 a.textContent = "Close Test Suite";142 close_suite.appendChild(a);143 close_suite.addEventListener("click", function(event) {144 event.stopPropagation();145 document.getElementById('close-testSuite').click();146 }, false);147 ul.appendChild(close_suite);148 var add_case = document.createElement("li");149 a = document.createElement("a");150 a.setAttribute("href", "#");151 a.textContent = "Add New Test Case";152 add_case.appendChild(a);153 add_case.addEventListener("click", function(event) {154 event.stopPropagation();155 document.getElementById('add-testCase').click();156 }, false);157 ul.appendChild(add_case);158 var rename_suite = document.createElement("li");159 a = document.createElement("a");160 a.setAttribute("href", "#");161 a.textContent = "Rename Test Suite";162 rename_suite.appendChild(a);163 rename_suite.addEventListener("click", function(event) {164 event.stopPropagation();165 var s_suite = getSelectedSuite();166 var n_title = prompt("Please enter the Test Suite's name", sideex_testSuite[s_suite.id].title);167 if (n_title) {168 // get text node169 s_suite.getElementsByTagName("STRONG")[0].textContent = n_title;170 sideex_testSuite[s_suite.id].title = n_title;171 sideex_testSuite[s_suite.id].file_name = n_title + ".html";172 $(s_suite).find("strong").addClass("modified");173 closeConfirm(true);174 }175 }, false);176 ul.appendChild(rename_suite);177 }178 node.appendChild(ul);179}180function addTestCase(title, id) {181 if (!getSelectedSuite()) {182 var suite_id = "suite" + sideex_testSuite.count;183 sideex_testSuite.count++;184 sideex_testSuite[suite_id] = {185 file_name: "Untitled Test Suite.html",186 title: "Untitled Test Suite"187 };188 addTestSuite("Untitled Test Suite", suite_id);189 }190 var p = document.createElement("p");191 p.textContent = title;192 p.setAttribute("id", id);193 p.setAttribute("contextmenu", "menu" + id);194 var s_case = getSelectedCase();195 if (s_case) {196 s_case.parentNode.insertBefore(p, s_case.nextSibling);197 } else {198 getSelectedSuite().appendChild(p);199 }200 cleanSelected();201 p.classList.add("selectedCase");202 p.classList.add("test-case-title");203 p.parentNode.classList.add("selectedSuite");204 if (sideex_testCase[id]) { // load file205 clean_panel();206 document.getElementById("records-grid").innerHTML = escapeHTML(sideex_testCase[id].records);207 if (getRecordsNum() !== '0') {208 reAssignId("records-1", "records-" + getRecordsNum());209 attachEvent(1, getRecordsNum());210 }211 } else { // add new testCase212 clean_panel();213 document.getElementById("records-grid").innerHTML = escapeHTML('<input id="records-count" type=hidden value=0></input>');214 sideex_testCase[id] = {215 records: "",216 title: title217 };218 p.classList.add("modified");219 p.parentNode.getElementsByTagName("strong")[0].classList.add("modified");220 }221 // attach event222 p.addEventListener("click", function(event) {223 event.stopPropagation();224 saveOldCase();225 // use jquery's API to add and remove class property226 cleanSelected();227 this.classList.add("selectedCase");228 this.parentNode.classList.add("selectedSuite");229 if (sideex_testCase[this.id].records) {230 clean_panel();231 document.getElementById("records-grid").innerHTML = escapeHTML(sideex_testCase[this.id].records);232 if (getRecordsNum() !== '0') {233 reAssignId("records-1", "records-" + getRecordsNum());234 attachEvent(1, getRecordsNum());235 }236 } else {237 clean_panel();238 document.getElementById("records-grid").innerHTML = escapeHTML('<input id="records-count" type=hidden value=0></input>');239 }240 // prevent event trigger on parent from child241 event.stopPropagation();242 }, false);243 var menu = document.createElement("div");244 menu.setAttribute("class", "menu");245 menu.setAttribute("id", "menu" + id);246 appendContextMenu(menu, true);247 p.appendChild(menu);248 // right click249 p.addEventListener("contextmenu", function(event) {250 event.preventDefault();251 event.stopPropagation();252 saveOldCase();253 setSelectedCase(this.id);254 var mid = "#" + "menu" + id;255 $(".menu").css("left", event.pageX);256 $(".menu").css("top", event.pageY);257 $(mid).show();258 }, false);259 closeConfirm(true);260 261 // enable play button262 enableButton("playback");263}264function addTestSuite(title, id) {265 // set test suite title div266 var textDiv = document.createElement("div");267 textDiv.classList.add("test-suite-title");268 // add save icon269 var saveIcon = document.createElement("i");270 saveIcon.classList.add("fa");271 saveIcon.classList.add("fa-download");272 saveIcon.setAttribute("aria-hidden", "true");273 saveIcon.addEventListener("click", clickSaveIcon);274 textDiv.appendChild(saveIcon);275 // set test suite title276 var text = document.createElement("strong");277 text.classList.add("test-suite-title");278 text.innerHTML = escapeHTML(title);279 textDiv.appendChild(text);280 // add plus icon281 var plusIcon = document.createElement("i");282 plusIcon.classList.add("fa");283 plusIcon.classList.add("fa-plus");284 plusIcon.classList.add("case-plus");285 plusIcon.setAttribute("aria-hidden", "true");286 plusIcon.addEventListener("click", clickCasePlusIcon);287 textDiv.appendChild(plusIcon);288 // set test suite div289 var div = document.createElement("div");290 div.setAttribute("id", id);291 div.setAttribute("contextmenu", "menu" + id);292 div.setAttribute("class", "message");293 div.addEventListener("mouseover", mouseOnAndOutTestSuite);294 div.addEventListener("mouseout", mouseOnAndOutTestSuite);295 div.appendChild(textDiv);296 var s_suite = getSelectedSuite();297 if (s_suite) {298 s_suite.parentNode.insertBefore(div, s_suite.nextSibling);299 } else {300 document.getElementById("testCase-grid").appendChild(div);301 }302 cleanSelected();303 div.classList.add("selectedSuite");304 // attach event305 div.addEventListener("click", function(event) {306 if (this.getElementsByTagName("p").length != 0) {307 this.getElementsByTagName("p")[0].click();308 } else {309 event.stopPropagation();310 saveOldCase();311 cleanSelected();312 this.classList.add("selectedSuite");313 clean_panel();314 }315 }, false);316 var menu = document.createElement("div");317 menu.setAttribute("class", "menu");318 menu.setAttribute("id", "menu" + id);319 appendContextMenu(menu, false);320 div.appendChild(menu);321 // right click322 div.addEventListener("contextmenu", function(event) {323 event.preventDefault();324 event.stopPropagation();325 saveOldCase();326 setSelectedSuite(this.id);327 var mid = "#" + "menu" + id;328 $(".menu").css("left", event.pageX);329 $(".menu").css("top", event.pageY);330 $(mid).show();331 }, false);332 makeCaseSortable(div);333 // enable play button334 enableButton("playSuites");335 enableButton("playSuite");336}337function modifyCaseSuite() {338 getSelectedCase().classList.add("modified");339 getSelectedSuite().getElementsByTagName("strong")[0].classList.add("modified");340}341document.getElementById("add-testSuite").addEventListener("click", function(event) {342 event.stopPropagation();343 var title = prompt("Please enter the Test Suite's name", "Untitled Test Suite");344 if (title) {345 var id = "suite" + sideex_testSuite.count;346 sideex_testSuite.count++;347 sideex_testSuite[id] = {348 file_name: title + ".html",349 title: title350 };351 addTestSuite(title, id);352 }353}, false);354document.getElementById("add-testSuite-menu").addEventListener("click", function(event) {355 event.stopPropagation();356 document.getElementById('add-testSuite').click();357}, false);358var confirmCloseSuite = function(question) {359 var defer = $.Deferred();360 $('<div></div>')361 .html(question)362 .dialog({363 title: "Save?",364 resizable: false,365 height: "auto",366 width: 400,367 modal: true,368 buttons: {369 "Yes": function() {370 defer.resolve("true");371 $(this).dialog("close");372 },373 "No": function() {374 defer.resolve("false");375 $(this).dialog("close");376 },377 Cancel: function() {378 $(this).dialog("close");379 }380 },381 close: function() {382 $(this).remove();383 }384 });385 return defer.promise();386};387var remove_testSuite = function() {388 var s_suite = getSelectedSuite();389 sideex_testSuite[s_suite.id] = null;390 s_suite.parentNode.removeChild(s_suite);391 clean_panel();392};393document.getElementById("close-testSuite").addEventListener('click', function(event) {394 event.stopPropagation();395 var s_suite = getSelectedSuite();396 if (s_suite) {397 if ($(s_suite).find(".modified").length) {398 confirmCloseSuite("Would you like to save this test suite?").then(function(answer) {399 if (answer === "true")400 downloadSuite(s_suite, remove_testSuite);401 else402 remove_testSuite(s_suite);403 // disable play button when there is no suite404 if (getSuiteNum() == 0) {405 disableButton("playback");406 disableButton("playSuite");407 disableButton("playSuites");408 }409 });410 } else {411 remove_testSuite(s_suite);412 // disable play button when there is no suite413 if (getSuiteNum() == 0) {414 disableButton("playback");415 disableButton("playSuite");416 disableButton("playSuites");417 } 418 }419 }420}, false);421document.getElementById("add-testCase").addEventListener("click", function(event) {422 var title = prompt("Please enter the Test Case's name", "Untitled Test Case");423 if (title) {424 var id = "case" + sideex_testCase.count;425 sideex_testCase.count++;426 addTestCase(title, id);427 }428}, false);429var remove_testCase = function() {430 var s_case = getSelectedCase();431 sideex_testCase[s_case.id] = null;432 s_case.parentNode.removeChild(s_case);433 clean_panel();434};435document.getElementById("delete-testCase").addEventListener('click', function() {436 var s_case = getSelectedCase();437 if (s_case) {438 if ($(s_case).hasClass("modified")) {439 confirmCloseSuite("Would you like to save this test case?").then(function(answer) {440 if (answer === "true")441 downloadSuite(getSelectedSuite(), remove_testCase);442 else443 remove_testCase();444 // disable play button when there is no test case445 if (getCaseNumInSuite() == 0) {446 disableButton("playback");447 }448 });449 } else {450 remove_testCase();451 // disable play button when there is no test case452 if (getCaseNumInSuite() == 0) {453 disableButton("playback");454 }455 }456 }457}, false);458function clickCasePlusIcon(event) {459 event.stopPropagation();460 event.target.parentNode.parentNode.click();461 document.getElementById('add-testCase').click();462}463function clickSaveIcon(event) {464 event.stopPropagation();465 event.target.parentNode.parentNode.click();466 document.getElementById('save-testSuite').click();467}468function clickSuitePlusIcon(event) {469 document.getElementById("add-testSuite").click();470}471function clickSuiteOpenIcon(event) {472 document.getElementById("load-testSuite-hidden").click();473}474document.getElementById("suite-plus").addEventListener("click", clickSuitePlusIcon);...

Full Screen

Full Screen

suite.spec.js

Source:suite.spec.js Github

copy

Full Screen

1var mocha = require('../')2 , Context = mocha.Context3 , Suite = mocha.Suite4 , Test = mocha.Test;5describe('Suite', function(){6 describe('.clone()', function(){7 beforeEach(function(){8 this.suite = new Suite('To be cloned');9 this.suite._timeout = 3043;10 this.suite._slow = 101;11 this.suite._bail = true;12 this.suite.suites.push(1);13 this.suite.tests.push('hello');14 this.suite._beforeEach.push(2);15 this.suite._beforeAll.push(3);16 this.suite._afterEach.push(4);17 this.suite._afterAll.push(5);18 });19 it('should copy the title', function(){20 this.suite.clone().title.should.equal('To be cloned');21 });22 it('should copy the timeout value', function(){23 this.suite.clone().timeout().should.equal(3043);24 });25 it('should copy the slow value', function(){26 this.suite.clone().slow().should.equal(101);27 });28 it('should copy the bail value', function(){29 this.suite.clone().bail().should.be.true();30 });31 it('should not copy the values from the suites array', function(){32 this.suite.clone().suites.should.be.empty();33 });34 it('should not copy the values from the tests array', function(){35 this.suite.clone().tests.should.be.empty();36 });37 it('should not copy the values from the _beforeEach array', function(){38 this.suite.clone()._beforeEach.should.be.empty();39 });40 it('should not copy the values from the _beforeAll array', function(){41 this.suite.clone()._beforeAll.should.be.empty();42 });43 it('should not copy the values from the _afterEach array', function(){44 this.suite.clone()._afterEach.should.be.empty();45 });46 it('should not copy the values from the _afterAll array', function(){47 this.suite.clone()._afterAll.should.be.empty();48 });49 });50 describe('.timeout()', function(){51 beforeEach(function(){52 this.suite = new Suite('A Suite');53 });54 describe('when no argument is passed', function(){55 it('should return the timeout value', function(){56 this.suite.timeout().should.equal(2000);57 });58 });59 describe('when argument is passed', function(){60 it('should return the Suite object', function(){61 var newSuite = this.suite.timeout(5000);62 newSuite.timeout().should.equal(5000);63 });64 });65 });66 describe('.slow()', function(){67 beforeEach(function(){68 this.suite = new Suite('A Suite');69 });70 describe('when given a string', function(){71 it('should parse it', function(){72 this.suite.slow('5 seconds');73 this.suite.slow().should.equal(5000);74 })75 })76 describe('when no argument is passed', function(){77 it('should return the slow value', function(){78 this.suite.slow().should.equal(75);79 });80 });81 describe('when argument is passed', function(){82 it('should return the Suite object', function(){83 var newSuite = this.suite.slow(5000);84 newSuite.slow().should.equal(5000);85 });86 });87 });88 describe('.bail()', function(){89 beforeEach(function(){90 this.suite = new Suite('A Suite');91 this.suite._bail = true92 });93 describe('when no argument is passed', function(){94 it('should return the bail value', function(){95 this.suite.bail().should.be.true();96 });97 });98 describe('when argument is passed', function(){99 it('should return the Suite object', function(){100 var newSuite = this.suite.bail(false);101 newSuite.bail().should.be.false();102 });103 });104 });105 describe('.beforeAll()', function(){106 beforeEach(function(){107 this.suite = new Suite('A Suite');108 });109 describe('wraps the passed in function in a Hook', function(){110 it('adds it to _beforeAll', function(){111 var fn = function(){};112 this.suite.beforeAll(fn);113 this.suite._beforeAll.should.have.length(1);114 var beforeAllItem = this.suite._beforeAll[0];115 beforeAllItem.title.should.match(/^"before all" hook/);116 beforeAllItem.fn.should.equal(fn);117 });118 it('appends title to hook', function(){119 var fn = function(){};120 this.suite.beforeAll('test', fn);121 this.suite._beforeAll.should.have.length(1);122 var beforeAllItem = this.suite._beforeAll[0];123 beforeAllItem.title.should.equal('"before all" hook: test');124 beforeAllItem.fn.should.equal(fn);125 function namedFn(){}126 this.suite.beforeAll(namedFn);127 this.suite._beforeAll.should.have.length(2);128 beforeAllItem = this.suite._beforeAll[1];129 beforeAllItem.title.should.equal('"before all" hook: namedFn');130 beforeAllItem.fn.should.equal(namedFn);131 });132 });133 });134 describe('.afterAll()', function(){135 beforeEach(function(){136 this.suite = new Suite('A Suite');137 });138 describe('wraps the passed in function in a Hook', function(){139 it('adds it to _afterAll', function(){140 var fn = function(){};141 this.suite.afterAll(fn);142 this.suite._afterAll.should.have.length(1);143 var afterAllItem = this.suite._afterAll[0];144 afterAllItem.title.should.match(/^"after all" hook/);145 afterAllItem.fn.should.equal(fn);146 });147 it('appends title to hook', function(){148 var fn = function(){};149 this.suite.afterAll('test', fn);150 this.suite._afterAll.should.have.length(1);151 var beforeAllItem = this.suite._afterAll[0];152 beforeAllItem.title.should.equal('"after all" hook: test');153 beforeAllItem.fn.should.equal(fn);154 function namedFn(){}155 this.suite.afterAll(namedFn);156 this.suite._afterAll.should.have.length(2);157 beforeAllItem = this.suite._afterAll[1];158 beforeAllItem.title.should.equal('"after all" hook: namedFn');159 beforeAllItem.fn.should.equal(namedFn);160 });161 });162 });163 describe('.beforeEach()', function(){164 beforeEach(function(){165 this.suite = new Suite('A Suite');166 });167 describe('wraps the passed in function in a Hook', function(){168 it('adds it to _beforeEach', function(){169 var fn = function(){};170 this.suite.beforeEach(fn);171 this.suite._beforeEach.should.have.length(1);172 var beforeEachItem = this.suite._beforeEach[0];173 beforeEachItem.title.should.match(/^"before each" hook/);174 beforeEachItem.fn.should.equal(fn);175 });176 it('appends title to hook', function(){177 var fn = function(){};178 this.suite.beforeEach('test', fn);179 this.suite._beforeEach.should.have.length(1);180 var beforeAllItem = this.suite._beforeEach[0];181 beforeAllItem.title.should.equal('"before each" hook: test');182 beforeAllItem.fn.should.equal(fn);183 function namedFn(){}184 this.suite.beforeEach(namedFn);185 this.suite._beforeEach.should.have.length(2);186 beforeAllItem = this.suite._beforeEach[1];187 beforeAllItem.title.should.equal('"before each" hook: namedFn');188 beforeAllItem.fn.should.equal(namedFn);189 });190 });191 });192 describe('.afterEach()', function(){193 beforeEach(function(){194 this.suite = new Suite('A Suite');195 });196 describe('wraps the passed in function in a Hook', function(){197 it('adds it to _afterEach', function(){198 var fn = function(){};199 this.suite.afterEach(fn);200 this.suite._afterEach.should.have.length(1);201 var afterEachItem = this.suite._afterEach[0];202 afterEachItem.title.should.match(/^"after each" hook/);203 afterEachItem.fn.should.equal(fn);204 });205 it('appends title to hook', function(){206 var fn = function(){};207 this.suite.afterEach('test', fn);208 this.suite._afterEach.should.have.length(1);209 var beforeAllItem = this.suite._afterEach[0];210 beforeAllItem.title.should.equal('"after each" hook: test');211 beforeAllItem.fn.should.equal(fn);212 function namedFn(){}213 this.suite.afterEach(namedFn);214 this.suite._afterEach.should.have.length(2);215 beforeAllItem = this.suite._afterEach[1];216 beforeAllItem.title.should.equal('"after each" hook: namedFn');217 beforeAllItem.fn.should.equal(namedFn);218 });219 });220 });221 describe('.addSuite()', function(){222 beforeEach(function(){223 this.first = new Suite('First suite');224 this.first.timeout(4002);225 this.first.slow(200);226 this.second = new Suite('Second suite');227 this.first.addSuite(this.second);228 });229 it('sets the parent on the added Suite', function(){230 this.second.parent.should.equal(this.first);231 });232 it('copies the timeout value', function(){233 this.second.timeout().should.equal(4002);234 });235 it('copies the slow value', function(){236 this.second.slow().should.equal(200);237 });238 it('adds the suite to the suites collection', function(){239 this.first.suites.should.have.length(1);240 this.first.suites[0].should.equal(this.second);241 });242 it('treats suite as pending if its parent is pending', function(){243 this.first.pending = true244 this.second.isPending.should.be.true245 });246 });247 // describe('.addTest()', function(){248 // beforeEach(function(){249 // this.suite = new Suite('A Suite', new Context);250 // this.suite.timeout(4002);251 // this.test = new Test('test');252 // this.suite.addTest(this.test);253 // });254 //255 // it('sets the parent on the added test', function(){256 // this.test.parent.should.equal(this.suite);257 // });258 //259 // it('copies the timeout value', function(){260 // this.test.timeout().should.equal(4002);261 // });262 //263 // it('adds the test to the tests collection', function(){264 // this.suite.tests.should.have.length(1);265 // this.suite.tests[0].should.equal(this.test);266 // });267 // });268 describe('.fullTitle()', function(){269 beforeEach(function(){270 this.suite = new Suite('A Suite');271 });272 describe('when there is no parent', function(){273 it('returns the suite title', function(){274 this.suite.fullTitle().should.equal('A Suite');275 });276 });277 describe('when there is a parent', function(){278 it('returns the combination of parent\'s and suite\'s title', function(){279 var parentSuite = new Suite('I am a parent');280 parentSuite.addSuite(this.suite);281 this.suite.fullTitle().should.equal('I am a parent A Suite');282 });283 });284 });285 describe('.total()', function(){286 beforeEach(function(){287 this.suite = new Suite('A Suite');288 });289 describe('when there are no nested suites or tests', function(){290 it('should return 0', function(){291 this.suite.total().should.equal(0);292 });293 });294 describe('when there are several tests in the suite', function(){295 it('should return the number', function(){296 this.suite.addTest(new Test('a child test'));297 this.suite.addTest(new Test('another child test'));298 this.suite.total().should.equal(2);299 });300 });301 });302 describe('.eachTest(fn)', function(){303 beforeEach(function(){304 this.suite = new Suite('A Suite');305 });306 describe('when there are no nested suites or tests', function(){307 it('should return 0', function(){308 var n = 0;309 function fn(){ n++; }310 this.suite.eachTest(fn);311 n.should.equal(0);312 });313 });314 describe('when there are several tests in the suite', function(){315 it('should return the number', function(){316 this.suite.addTest(new Test('a child test'));317 this.suite.addTest(new Test('another child test'));318 var n = 0;319 function fn(){ n++; }320 this.suite.eachTest(fn);321 n.should.equal(2);322 });323 });324 describe('when there are several levels of nested suites', function(){325 it('should return the number', function(){326 this.suite.addTest(new Test('a child test'));327 var suite = new Suite('a child suite');328 suite.addTest(new Test('a test in a child suite'));329 this.suite.addSuite(suite);330 var n = 0;331 function fn(){ n++; }332 this.suite.eachTest(fn);333 n.should.equal(2);334 });335 });336 });337 describe('initialization', function() {338 it('should throw an error if the title isn\'t a string', function() {339 (function() {340 new Suite(undefined, 'root');341 }).should.throw();342 (function() {343 new Suite(function(){}, 'root');344 }).should.throw();345 });346 it('should not throw if the title is a string', function() {347 (function() {348 new Suite('Bdd suite', 'root');349 }).should.not.throw();350 });351 });352});353describe('Test', function() {354 describe('initialization', function() {355 it('should throw an error if the title isn\'t a string', function() {356 (function() {357 new Test(function(){});358 }).should.throw();359 (function() {360 new Test(undefined, function(){});361 }).should.throw();362 });363 it('should not throw if the title is a string', function() {364 (function() {365 new Test('test-case', function(){});366 }).should.not.throw();367 });368 });...

Full Screen

Full Screen

jasmine-jsreporter.js

Source:jasmine-jsreporter.js Github

copy

Full Screen

1/*2 This file is part of the Jasmine JSReporter project from Ivan De Marino.3 Copyright (C) 2011-2014 Ivan De Marino <http://ivandemarino.me>4 Copyright (C) 2014 Alex Treppass <http://alextreppass.co.uk>5 Redistribution and use in source and binary forms, with or without6 modification, are permitted provided that the following conditions are met:7 * Redistributions of source code must retain the above copyright8 notice, this list of conditions and the following disclaimer.9 * Redistributions in binary form must reproduce the above copyright10 notice, this list of conditions and the following disclaimer in the11 documentation and/or other materials provided with the distribution.12 * Neither the name of the <organization> nor the13 names of its contributors may be used to endorse or promote products14 derived from this software without specific prior written permission.15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18 ARE DISCLAIMED. IN NO EVENT SHALL IVAN DE MARINO BE LIABLE FOR ANY19 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES20 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;21 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND22 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT23 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF24 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.25*/26(function (jasmine) {27 if (!jasmine) {28 throw new Error("[Jasmine JSReporter] 'Jasmine' library not found");29 }30 // ------------------------------------------------------------------------31 // Jasmine JSReporter for Jasmine 1.x32 // ------------------------------------------------------------------------33 /**34 * Calculate elapsed time, in Seconds.35 * @param startMs Start time in Milliseconds36 * @param finishMs Finish time in Milliseconds37 * @return Elapsed time in Seconds */38 function elapsedSec (startMs, finishMs) {39 return (finishMs - startMs) / 1000;40 }41 /**42 * Round an amount to the given number of Digits.43 * If no number of digits is given, than '2' is assumed.44 * @param amount Amount to round45 * @param numOfDecDigits Number of Digits to round to. Default value is '2'.46 * @return Rounded amount */47 function round (amount, numOfDecDigits) {48 numOfDecDigits = numOfDecDigits || 2;49 return Math.round(amount * Math.pow(10, numOfDecDigits)) / Math.pow(10, numOfDecDigits);50 }51 /**52 * Create a new array which contains only the failed items.53 * @param items Items which will be filtered54 * @returns {Array} of failed items */55 function failures (items) {56 var fs = [], i, v;57 for (i = 0; i < items.length; i += 1) {58 v = items[i];59 if (!v.passed_) {60 fs.push(v);61 }62 }63 return fs;64 }65 /**66 * Collect information about a Suite, recursively, and return a JSON result.67 * @param suite The Jasmine Suite to get data from68 */69 function getSuiteData (suite) {70 var suiteData = {71 description : suite.description,72 durationSec : 0,73 specs: [],74 suites: [],75 passed: true76 },77 specs = suite.specs(),78 suites = suite.suites(),79 i, ilen;80 // Loop over all the Suite's Specs81 for (i = 0, ilen = specs.length; i < ilen; ++i) {82 suiteData.specs[i] = {83 description : specs[i].description,84 durationSec : specs[i].durationSec,85 passed : specs[i].results().passedCount === specs[i].results().totalCount,86 skipped : specs[i].results().skipped,87 passedCount : specs[i].results().passedCount,88 failedCount : specs[i].results().failedCount,89 totalCount : specs[i].results().totalCount,90 failures: failures(specs[i].results().getItems())91 };92 suiteData.passed = !suiteData.specs[i].passed ? false : suiteData.passed;93 suiteData.durationSec += suiteData.specs[i].durationSec;94 }95 // Loop over all the Suite's sub-Suites96 for (i = 0, ilen = suites.length; i < ilen; ++i) {97 suiteData.suites[i] = getSuiteData(suites[i]); //< recursive population98 suiteData.passed = !suiteData.suites[i].passed ? false : suiteData.passed;99 suiteData.durationSec += suiteData.suites[i].durationSec;100 }101 // Rounding duration numbers to 3 decimal digits102 suiteData.durationSec = round(suiteData.durationSec, 4);103 return suiteData;104 }105 var JSReporter = function () {106 };107 JSReporter.prototype = {108 reportRunnerStarting: function (runner) {109 // Nothing to do110 },111 reportSpecStarting: function (spec) {112 // Start timing this spec113 spec.startedAt = new Date();114 },115 reportSpecResults: function (spec) {116 // Finish timing this spec and calculate duration/delta (in sec)117 spec.finishedAt = new Date();118 // If the spec was skipped, reportSpecStarting is never called and spec.startedAt is undefined119 spec.durationSec = spec.startedAt ? elapsedSec(spec.startedAt.getTime(), spec.finishedAt.getTime()) : 0;120 },121 reportSuiteResults: function (suite) {122 // Nothing to do123 },124 reportRunnerResults: function (runner) {125 var suites = runner.suites(),126 i, j, ilen;127 // Attach results to the "jasmine" object to make those results easy to scrap/find128 jasmine.runnerResults = {129 suites: [],130 durationSec : 0,131 passed : true132 };133 // Loop over all the Suites134 for (i = 0, ilen = suites.length, j = 0; i < ilen; ++i) {135 if (suites[i].parentSuite === null) {136 jasmine.runnerResults.suites[j] = getSuiteData(suites[i]);137 // If 1 suite fails, the whole runner fails138 jasmine.runnerResults.passed = !jasmine.runnerResults.suites[j].passed ? false : jasmine.runnerResults.passed;139 // Add up all the durations140 jasmine.runnerResults.durationSec += jasmine.runnerResults.suites[j].durationSec;141 j++;142 }143 }144 // Decorate the 'jasmine' object with getters145 jasmine.getJSReport = function () {146 if (jasmine.runnerResults) {147 return jasmine.runnerResults;148 }149 return null;150 };151 jasmine.getJSReportAsString = function () {152 return JSON.stringify(jasmine.getJSReport());153 };154 }155 };156 // export public157 jasmine.JSReporter = JSReporter;158 // ------------------------------------------------------------------------159 // Jasmine JSReporter for Jasmine 2.0160 // ------------------------------------------------------------------------161 /*162 Simple timer implementation163 */164 var Timer = function () {};165 Timer.prototype.start = function () {166 this.startTime = new Date().getTime();167 return this;168 };169 Timer.prototype.elapsed = function () {170 if (this.startTime == null) {171 return -1;172 }173 return new Date().getTime() - this.startTime;174 };175 /*176 Utility methods177 */178 var _extend = function (obj1, obj2) {179 for (var prop in obj2) {180 obj1[prop] = obj2[prop];181 }182 return obj1;183 };184 var _clone = function (obj) {185 if (obj !== Object(obj)) {186 return obj;187 }188 return _extend({}, obj);189 };190 jasmine.JSReporter2 = function () {191 this.specs = {};192 this.suites = {};193 this.rootSuites = [];194 this.suiteStack = [];195 // export methods under jasmine namespace196 jasmine.getJSReport = this.getJSReport;197 jasmine.getJSReportAsString = this.getJSReportAsString;198 };199 var JSR = jasmine.JSReporter2.prototype;200 // Reporter API methods201 // --------------------202 JSR.suiteStarted = function (suite) {203 suite = this._cacheSuite(suite);204 // build up suite tree as we go205 suite.specs = [];206 suite.suites = [];207 suite.passed = true;208 suite.parentId = this.suiteStack.slice(this.suiteStack.length -1)[0];209 if (suite.parentId) {210 this.suites[suite.parentId].suites.push(suite);211 } else {212 this.rootSuites.push(suite.id);213 }214 this.suiteStack.push(suite.id);215 suite.timer = new Timer().start();216 };217 JSR.suiteDone = function (suite) {218 suite = this._cacheSuite(suite);219 suite.duration = suite.timer.elapsed();220 suite.durationSec = suite.duration / 1000;221 this.suiteStack.pop();222 // maintain parent suite state223 var parent = this.suites[suite.parentId];224 if (parent) {225 parent.passed = parent.passed && suite.passed;226 }227 // keep report representation clean228 delete suite.timer;229 delete suite.id;230 delete suite.parentId;231 delete suite.fullName;232 };233 JSR.specStarted = function (spec) {234 spec = this._cacheSpec(spec);235 spec.timer = new Timer().start();236 // build up suites->spec tree as we go237 spec.suiteId = this.suiteStack.slice(this.suiteStack.length -1)[0];238 this.suites[spec.suiteId].specs.push(spec);239 };240 JSR.specDone = function (spec) {241 spec = this._cacheSpec(spec);242 spec.duration = spec.timer.elapsed();243 spec.durationSec = spec.duration / 1000;244 spec.skipped = spec.status === 'pending';245 spec.passed = spec.skipped || spec.status === 'passed';246 spec.totalCount = spec.passedExpectations.length + spec.failedExpectations.length;247 spec.passedCount = spec.passedExpectations.length;248 spec.failedCount = spec.failedExpectations.length;249 spec.failures = [];250 for (var i = 0, j = spec.failedExpectations.length; i < j; i++) {251 var fail = spec.failedExpectations[i];252 spec.failures.push({253 type: 'expect',254 expected: fail.expected,255 passed: false,256 message: fail.message,257 matcherName: fail.matcherName,258 trace: {259 stack: fail.stack260 }261 });262 }263 // maintain parent suite state264 var parent = this.suites[spec.suiteId];265 if (spec.failed) {266 parent.failingSpecs.push(spec);267 }268 parent.passed = parent.passed && spec.passed;269 // keep report representation clean270 delete spec.timer;271 delete spec.totalExpectations;272 delete spec.passedExpectations;273 delete spec.suiteId;274 delete spec.fullName;275 delete spec.id;276 delete spec.status;277 delete spec.failedExpectations;278 };279 JSR.jasmineDone = function () {280 this._buildReport();281 };282 JSR.getJSReport = function () {283 if (jasmine.jsReport) {284 return jasmine.jsReport;285 }286 };287 JSR.getJSReportAsString = function () {288 if (jasmine.jsReport) {289 return JSON.stringify(jasmine.jsReport);290 }291 };292 // Private methods293 // ---------------294 JSR._haveSpec = function (spec) {295 return this.specs[spec.id] != null;296 };297 JSR._cacheSpec = function (spec) {298 var existing = this.specs[spec.id];299 if (existing == null) {300 existing = this.specs[spec.id] = _clone(spec);301 } else {302 _extend(existing, spec);303 }304 return existing;305 };306 JSR._haveSuite = function (suite) {307 return this.suites[suite.id] != null;308 };309 JSR._cacheSuite = function (suite) {310 var existing = this.suites[suite.id];311 if (existing == null) {312 existing = this.suites[suite.id] = _clone(suite);313 } else {314 _extend(existing, suite);315 }316 return existing;317 };318 JSR._buildReport = function () {319 var overallDuration = 0;320 var overallPassed = true;321 var overallSuites = [];322 for (var i = 0, j = this.rootSuites.length; i < j; i++) {323 var suite = this.suites[this.rootSuites[i]];324 overallDuration += suite.duration;325 overallPassed = overallPassed && suite.passed;326 overallSuites.push(suite);327 }328 jasmine.jsReport = {329 passed: overallPassed,330 durationSec: overallDuration / 1000,331 suites: overallSuites332 };333 };...

Full Screen

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:

YouTube

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

Run Lemoncheesecake automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful