@@ -2,10 +2,13 @@ import { fakeAsync, TestBed } from '@angular/core/testing';
2
2
import { By } from '@angular/platform-browser' ;
3
3
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
4
4
import { IgxPivotDateDimension , IgxPivotGridModule } from 'igniteui-angular' ;
5
+ import { IgxChipsAreaComponent } from '../../chips/chips-area.component' ;
5
6
import { configureTestSuite } from '../../test-utils/configure-suite' ;
6
7
import { GridFunctions , GridSelectionFunctions } from '../../test-utils/grid-functions.spec' ;
7
8
import { IgxPivotGridTestBaseComponent , IgxPivotGridTestComplexHierarchyComponent , IgxTotalSaleAggregate } from '../../test-utils/pivot-grid-samples.spec' ;
8
9
import { UIInteractions } from '../../test-utils/ui-interactions.spec' ;
10
+ import { PivotDimensionType } from './pivot-grid.interface' ;
11
+ import { IgxPivotHeaderRowComponent } from './pivot-header-row.component' ;
9
12
const CSS_CLASS_DROP_DOWN_BASE = 'igx-drop-down' ;
10
13
const CSS_CLASS_LIST = 'igx-drop-down__list' ;
11
14
const CSS_CLASS_ITEM = 'igx-drop-down__item' ;
@@ -476,6 +479,156 @@ describe('Basic IgxPivotGrid #pivotGrid', () => {
476
479
expect ( pivotGrid . gridAPI . get_cell_by_index ( 0 , 'USA' ) . value ) . toBe ( 0 ) ;
477
480
expect ( pivotGrid . gridAPI . get_cell_by_index ( 0 , 'Uruguay' ) . value ) . toBe ( 242.08 ) ;
478
481
} ) ;
482
+
483
+ it ( 'should allow reorder in row chip area.' , ( ) => {
484
+ const pivotGrid = fixture . componentInstance . pivotGrid ;
485
+ pivotGrid . pivotConfiguration . rows = [
486
+ {
487
+ memberName : 'ProductCategory' ,
488
+ enabled : true
489
+ } ,
490
+ {
491
+ memberName : 'SellerName' ,
492
+ enabled : true
493
+ }
494
+ ] ;
495
+ pivotGrid . pipeTrigger ++ ;
496
+ pivotGrid . setupColumns ( ) ;
497
+ fixture . detectChanges ( ) ;
498
+
499
+ const headerRow : IgxPivotHeaderRowComponent = fixture . debugElement . query ( By . directive ( IgxPivotHeaderRowComponent ) ) . componentInstance ;
500
+ const chipAreas = fixture . debugElement . queryAll ( By . directive ( IgxChipsAreaComponent ) ) ;
501
+ const rowChipArea : IgxChipsAreaComponent = chipAreas [ 3 ] . componentInstance ;
502
+ const rowChip1 = rowChipArea . chipsList . toArray ( ) [ 0 ] ;
503
+ const rowChip2 = rowChipArea . chipsList . toArray ( ) [ 1 ] ;
504
+
505
+ // start drag in row chip area.
506
+ headerRow . onDimDragStart ( { } , rowChipArea ) ;
507
+ fixture . detectChanges ( ) ;
508
+
509
+ // move first chip over the second one
510
+ headerRow . onDimDragOver ( {
511
+ dragChip : {
512
+ id : 'ProductCategory'
513
+ } ,
514
+ owner : rowChip2 ,
515
+ originalEvent : {
516
+ offsetX : 100
517
+ }
518
+ } , PivotDimensionType . Row ) ;
519
+ fixture . detectChanges ( ) ;
520
+
521
+ // check drop indicator has shown after the second chip
522
+ expect ( ( rowChip2 . nativeElement . nextElementSibling as any ) . style . visibility ) . toBe ( '' ) ;
523
+
524
+ // drop chip
525
+ headerRow . onDimDrop ( {
526
+ dragChip : {
527
+ id : 'ProductCategory'
528
+ } ,
529
+ owner : rowChip2
530
+ } , rowChipArea , PivotDimensionType . Row ) ;
531
+ pivotGrid . cdr . detectChanges ( ) ;
532
+ //check chip order is updated.
533
+ expect ( rowChipArea . chipsList . toArray ( ) [ 0 ] ) . toBe ( rowChip2 ) ;
534
+ expect ( rowChipArea . chipsList . toArray ( ) [ 1 ] ) . toBe ( rowChip1 ) ;
535
+ // check dimension order is updated.
536
+ expect ( pivotGrid . pivotConfiguration . rows . map ( x => x . memberName ) ) . toEqual ( [ 'SellerName' , 'ProductCategory' ] ) ;
537
+ // check rows reflect new order of dims
538
+ expect ( pivotGrid . gridAPI . get_row_by_index ( 0 ) . rowDimensionData . map ( x => x . dimension . memberName ) )
539
+ . toEqual ( [ 'SellerName' , 'ProductCategory' ] ) ;
540
+ } ) ;
541
+
542
+ it ( 'should allow reorder in column chip area.' , ( ) => {
543
+ const pivotGrid = fixture . componentInstance . pivotGrid ;
544
+ pivotGrid . pivotConfiguration . columns . push ( {
545
+ memberName : 'SellerName' ,
546
+ enabled : true
547
+ } ) ;
548
+ pivotGrid . pipeTrigger ++ ;
549
+ pivotGrid . setupColumns ( ) ;
550
+ fixture . detectChanges ( ) ;
551
+
552
+ const headerRow : IgxPivotHeaderRowComponent = fixture . debugElement . query ( By . directive ( IgxPivotHeaderRowComponent ) ) . componentInstance ;
553
+ const chipAreas = fixture . debugElement . queryAll ( By . directive ( IgxChipsAreaComponent ) ) ;
554
+ const colChipArea : IgxChipsAreaComponent = chipAreas [ 1 ] . componentInstance ;
555
+ const colChip1 = colChipArea . chipsList . toArray ( ) [ 0 ] ;
556
+ const colChip2 = colChipArea . chipsList . toArray ( ) [ 1 ] ;
557
+
558
+ // start drag in col chip area.
559
+ headerRow . onDimDragStart ( { } , colChipArea ) ;
560
+ fixture . detectChanges ( ) ;
561
+
562
+ // move first chip over the second one
563
+ headerRow . onDimDragOver ( {
564
+ dragChip : {
565
+ id : 'Country'
566
+ } ,
567
+ owner : colChip2 ,
568
+ originalEvent : {
569
+ offsetX : 100
570
+ }
571
+ } , PivotDimensionType . Column ) ;
572
+ fixture . detectChanges ( ) ;
573
+
574
+ // check drop indicator has shown after the second chip
575
+ expect ( ( colChip2 . nativeElement . nextElementSibling as any ) . style . visibility ) . toBe ( '' ) ;
576
+
577
+ // drop chip
578
+ headerRow . onDimDrop ( {
579
+ dragChip : {
580
+ id : 'Country'
581
+ } ,
582
+ owner : colChip2
583
+ } , colChipArea , PivotDimensionType . Column ) ;
584
+ pivotGrid . cdr . detectChanges ( ) ;
585
+ //check chip order is updated.
586
+ expect ( colChipArea . chipsList . toArray ( ) [ 0 ] ) . toBe ( colChip2 ) ;
587
+ expect ( colChipArea . chipsList . toArray ( ) [ 1 ] ) . toBe ( colChip1 ) ;
588
+ // check dimension order is updated.
589
+ expect ( pivotGrid . pivotConfiguration . columns . map ( x => x . memberName ) ) . toEqual ( [ 'SellerName' , 'Country' ] ) ;
590
+ // check columns reflect new order of dims
591
+ const cols = pivotGrid . columns ;
592
+ expect ( cols . filter ( x => x . level === 0 ) . map ( x => x . field ) ) . toEqual ( [ 'Stanley' , 'Elisa' , 'Lydia' , 'David' , 'John' , 'Larry' , 'Walter' ] ) ;
593
+ } ) ;
594
+ it ( 'should allow reorder in the value chip area' , ( ) => {
595
+ const pivotGrid = fixture . componentInstance . pivotGrid ;
596
+ fixture . detectChanges ( ) ;
597
+ const headerRow : IgxPivotHeaderRowComponent = fixture . debugElement . query ( By . directive ( IgxPivotHeaderRowComponent ) ) . componentInstance ;
598
+ const chipAreas = fixture . debugElement . queryAll ( By . directive ( IgxChipsAreaComponent ) ) ;
599
+ const valuesChipArea : IgxChipsAreaComponent = chipAreas [ 2 ] . componentInstance ;
600
+ const valChip1 = valuesChipArea . chipsList . toArray ( ) [ 0 ] ;
601
+ const valChip2 = valuesChipArea . chipsList . toArray ( ) [ 1 ] ;
602
+
603
+ // move first chip over the second one
604
+ headerRow . onDimDragOver ( {
605
+ dragChip : {
606
+ id : 'UnitsSold'
607
+ } ,
608
+ owner : valChip2 ,
609
+ originalEvent : {
610
+ offsetX : 100
611
+ }
612
+ } ) ;
613
+ fixture . detectChanges ( ) ;
614
+
615
+ // check drop indicator has shown after the second chip
616
+ expect ( ( valChip2 . nativeElement . nextElementSibling as any ) . style . visibility ) . toBe ( '' ) ;
617
+
618
+ // drop chip
619
+ headerRow . onValueDrop ( {
620
+ dragChip : valChip1 ,
621
+ owner : valChip2
622
+ } , valuesChipArea ) ;
623
+ pivotGrid . cdr . detectChanges ( ) ;
624
+ //check chip order is updated.
625
+ expect ( valuesChipArea . chipsList . toArray ( ) [ 0 ] ) . toBe ( valChip2 ) ;
626
+ expect ( valuesChipArea . chipsList . toArray ( ) [ 1 ] ) . toBe ( valChip1 ) ;
627
+ // check dimension order is updated.
628
+ expect ( pivotGrid . pivotConfiguration . values . map ( x => x . member ) ) . toEqual ( [ 'UnitPrice' , 'UnitsSold' ] ) ;
629
+
630
+ } ) ;
631
+ // fit('should allow moving dimension between rows, columns and filters.', () => {});
479
632
} ) ;
480
633
} ) ;
481
634
0 commit comments