@@ -15,6 +15,12 @@ describe('gridstack', function() {
15
15
' </div>' +
16
16
' </div>' +
17
17
'</div>' ;
18
+ // empty grid
19
+ var gridstackEmptyHTML =
20
+ '<div style="width: 992px; height: 800px" id="gs-cont">' +
21
+ ' <div class="grid-stack">' +
22
+ ' </div>' +
23
+ '</div>' ;
18
24
// generic widget with no param
19
25
var widgetHTML = '<div class="grid-stack-item" id="item3"><div class="grid-stack-item-content"> hello </div></div>' ;
20
26
@@ -441,6 +447,104 @@ describe('gridstack', function() {
441
447
} ) ;
442
448
} ) ;
443
449
450
+ describe ( 'oneColumnModeDomSort' , function ( ) {
451
+ beforeEach ( function ( ) {
452
+ document . body . insertAdjacentHTML ( 'afterbegin' , gridstackEmptyHTML ) ;
453
+ } ) ;
454
+ afterEach ( function ( ) {
455
+ document . body . removeChild ( document . getElementById ( 'gs-cont' ) ) ;
456
+ } ) ;
457
+ it ( 'should support default going to 1 column' , function ( ) {
458
+ var options = {
459
+ column : 12 ,
460
+ float : true
461
+ } ;
462
+ $ ( '.grid-stack' ) . gridstack ( options ) ;
463
+ var grid = $ ( '.grid-stack' ) . data ( 'gridstack' ) ;
464
+ var el1 = grid . addWidget ( widgetHTML , { width :1 , height :1 } ) ;
465
+ var el2 = grid . addWidget ( widgetHTML , { x :2 , y :0 , width :2 , height :1 } ) ;
466
+ var el3 = grid . addWidget ( widgetHTML , { x :1 , y :0 , width :1 , height :2 } ) ;
467
+
468
+ // items are item1[1x1], item3[1x1], item2[2x1]
469
+ expect ( parseInt ( el1 . attr ( 'data-gs-x' ) ) ) . toBe ( 0 ) ;
470
+ expect ( parseInt ( el1 . attr ( 'data-gs-y' ) ) ) . toBe ( 0 ) ;
471
+ expect ( parseInt ( el1 . attr ( 'data-gs-width' ) ) ) . toBe ( 1 ) ;
472
+ expect ( parseInt ( el1 . attr ( 'data-gs-height' ) ) ) . toBe ( 1 ) ;
473
+
474
+ expect ( parseInt ( el3 . attr ( 'data-gs-x' ) ) ) . toBe ( 1 ) ;
475
+ expect ( parseInt ( el3 . attr ( 'data-gs-y' ) ) ) . toBe ( 0 ) ;
476
+ expect ( parseInt ( el3 . attr ( 'data-gs-width' ) ) ) . toBe ( 1 ) ;
477
+ expect ( parseInt ( el3 . attr ( 'data-gs-height' ) ) ) . toBe ( 2 ) ;
478
+
479
+ expect ( parseInt ( el2 . attr ( 'data-gs-x' ) ) ) . toBe ( 2 ) ;
480
+ expect ( parseInt ( el2 . attr ( 'data-gs-y' ) ) ) . toBe ( 0 ) ;
481
+ expect ( parseInt ( el2 . attr ( 'data-gs-width' ) ) ) . toBe ( 2 ) ;
482
+ expect ( parseInt ( el2 . attr ( 'data-gs-height' ) ) ) . toBe ( 1 ) ;
483
+
484
+ // items are item1[1x1], item3[1x2], item2[1x1] in 1 column
485
+ grid . setColumn ( 1 ) ;
486
+ expect ( parseInt ( el1 . attr ( 'data-gs-x' ) ) ) . toBe ( 0 ) ;
487
+ expect ( parseInt ( el1 . attr ( 'data-gs-y' ) ) ) . toBe ( 0 ) ;
488
+ expect ( parseInt ( el1 . attr ( 'data-gs-width' ) ) ) . toBe ( 1 ) ;
489
+ expect ( parseInt ( el1 . attr ( 'data-gs-height' ) ) ) . toBe ( 1 ) ;
490
+
491
+ expect ( parseInt ( el3 . attr ( 'data-gs-x' ) ) ) . toBe ( 0 ) ;
492
+ expect ( parseInt ( el3 . attr ( 'data-gs-y' ) ) ) . toBe ( 1 ) ;
493
+ expect ( parseInt ( el3 . attr ( 'data-gs-width' ) ) ) . toBe ( 1 ) ;
494
+ expect ( parseInt ( el3 . attr ( 'data-gs-height' ) ) ) . toBe ( 2 ) ;
495
+
496
+ expect ( parseInt ( el2 . attr ( 'data-gs-x' ) ) ) . toBe ( 0 ) ;
497
+ expect ( parseInt ( el2 . attr ( 'data-gs-y' ) ) ) . toBe ( 3 ) ;
498
+ expect ( parseInt ( el2 . attr ( 'data-gs-width' ) ) ) . toBe ( 1 ) ;
499
+ expect ( parseInt ( el2 . attr ( 'data-gs-height' ) ) ) . toBe ( 1 ) ;
500
+ } ) ;
501
+ it ( 'should support oneColumnModeDomSort ON going to 1 column' , function ( ) {
502
+ var options = {
503
+ column : 12 ,
504
+ oneColumnModeDomSort : true ,
505
+ float : true
506
+ } ;
507
+ $ ( '.grid-stack' ) . gridstack ( options ) ;
508
+ var grid = $ ( '.grid-stack' ) . data ( 'gridstack' ) ;
509
+ var el1 = grid . addWidget ( widgetHTML , { width :1 , height :1 } ) ;
510
+ var el2 = grid . addWidget ( widgetHTML , { x :2 , y :0 , width :2 , height :1 } ) ;
511
+ var el3 = grid . addWidget ( widgetHTML , { x :1 , y :0 , width :1 , height :2 } ) ;
512
+
513
+ // items are item1[1x1], item3[1x1], item2[2x1]
514
+ expect ( parseInt ( el1 . attr ( 'data-gs-x' ) ) ) . toBe ( 0 ) ;
515
+ expect ( parseInt ( el1 . attr ( 'data-gs-y' ) ) ) . toBe ( 0 ) ;
516
+ expect ( parseInt ( el1 . attr ( 'data-gs-width' ) ) ) . toBe ( 1 ) ;
517
+ expect ( parseInt ( el1 . attr ( 'data-gs-height' ) ) ) . toBe ( 1 ) ;
518
+
519
+ expect ( parseInt ( el3 . attr ( 'data-gs-x' ) ) ) . toBe ( 1 ) ;
520
+ expect ( parseInt ( el3 . attr ( 'data-gs-y' ) ) ) . toBe ( 0 ) ;
521
+ expect ( parseInt ( el3 . attr ( 'data-gs-width' ) ) ) . toBe ( 1 ) ;
522
+ expect ( parseInt ( el3 . attr ( 'data-gs-height' ) ) ) . toBe ( 2 ) ;
523
+
524
+ expect ( parseInt ( el2 . attr ( 'data-gs-x' ) ) ) . toBe ( 2 ) ;
525
+ expect ( parseInt ( el2 . attr ( 'data-gs-y' ) ) ) . toBe ( 0 ) ;
526
+ expect ( parseInt ( el2 . attr ( 'data-gs-width' ) ) ) . toBe ( 2 ) ;
527
+ expect ( parseInt ( el2 . attr ( 'data-gs-height' ) ) ) . toBe ( 1 ) ;
528
+
529
+ // items are item1[1x1], item2[1x1], item3[1x2] in 1 column dom ordered
530
+ grid . setColumn ( 1 ) ;
531
+ expect ( parseInt ( el1 . attr ( 'data-gs-x' ) ) ) . toBe ( 0 ) ;
532
+ expect ( parseInt ( el1 . attr ( 'data-gs-y' ) ) ) . toBe ( 0 ) ;
533
+ expect ( parseInt ( el1 . attr ( 'data-gs-width' ) ) ) . toBe ( 1 ) ;
534
+ expect ( parseInt ( el1 . attr ( 'data-gs-height' ) ) ) . toBe ( 1 ) ;
535
+
536
+ expect ( parseInt ( el2 . attr ( 'data-gs-x' ) ) ) . toBe ( 0 ) ;
537
+ expect ( parseInt ( el2 . attr ( 'data-gs-y' ) ) ) . toBe ( 1 ) ;
538
+ expect ( parseInt ( el2 . attr ( 'data-gs-width' ) ) ) . toBe ( 1 ) ;
539
+ expect ( parseInt ( el2 . attr ( 'data-gs-height' ) ) ) . toBe ( 1 ) ;
540
+
541
+ expect ( parseInt ( el3 . attr ( 'data-gs-x' ) ) ) . toBe ( 0 ) ;
542
+ expect ( parseInt ( el3 . attr ( 'data-gs-y' ) ) ) . toBe ( 2 ) ;
543
+ expect ( parseInt ( el3 . attr ( 'data-gs-width' ) ) ) . toBe ( 1 ) ;
544
+ expect ( parseInt ( el3 . attr ( 'data-gs-height' ) ) ) . toBe ( 2 ) ;
545
+ } ) ;
546
+ } ) ;
547
+
444
548
describe ( 'grid.minWidth' , function ( ) {
445
549
beforeEach ( function ( ) {
446
550
document . body . insertAdjacentHTML ( 'afterbegin' , gridstackHTML ) ;
0 commit comments