@@ -7,10 +7,12 @@ import { IgxGridComponent } from './grid.component';
7
7
import { IgxGridModule } from './index' ;
8
8
import { configureTestSuite } from '../../test-utils/configure-suite' ;
9
9
import { IgxChipComponent } from '../../chips' ;
10
- import { IgxStringFilteringOperand ,
10
+ import {
11
+ IgxStringFilteringOperand ,
11
12
IgxNumberFilteringOperand ,
12
13
IgxBooleanFilteringOperand ,
13
- IgxDateFilteringOperand } from '../../data-operations/filtering-condition' ;
14
+ IgxDateFilteringOperand
15
+ } from '../../data-operations/filtering-condition' ;
14
16
import { FilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree' ;
15
17
import { SampleTestData } from '../../test-utils/sample-test-data.spec' ;
16
18
import { GridFunctions , GridSummaryFunctions } from '../../test-utils/grid-functions.spec' ;
@@ -29,7 +31,7 @@ describe('IgxGrid - Filtering actions #grid', () => {
29
31
BrowserAnimationsModule ,
30
32
IgxGridModule ]
31
33
} )
32
- . compileComponents ( ) ;
34
+ . compileComponents ( ) ;
33
35
} ) ) ;
34
36
35
37
let fix , grid ;
@@ -89,7 +91,7 @@ describe('IgxGrid - Filtering actions #grid', () => {
89
91
// Null filter
90
92
grid . clearFilter ( 'ProductName' ) ;
91
93
fix . detectChanges ( ) ;
92
- grid . filter ( 'ProductName' , null , IgxStringFilteringOperand . instance ( ) . condition ( 'null' ) , true ) ;
94
+ grid . filter ( 'ProductName' , null , IgxStringFilteringOperand . instance ( ) . condition ( 'null' ) , true ) ;
93
95
fix . detectChanges ( ) ;
94
96
expect ( grid . rowList . length ) . toEqual ( 3 ) ;
95
97
@@ -248,11 +250,11 @@ describe('IgxGrid - Filtering actions #grid', () => {
248
250
const today = SampleTestData . today ;
249
251
250
252
// Fill expected results based on the current date
251
- fillExpectedResults ( grid , cal , today ) ;
253
+ const expectedResults = GridFunctions . createDateFilterConditions ( grid , today ) ;
252
254
253
255
// After filter
254
256
grid . filter ( 'ReleaseDate' , cal . timedelta ( today , 'day' , 4 ) ,
255
- IgxDateFilteringOperand . instance ( ) . condition ( 'after' ) ) ;
257
+ IgxDateFilteringOperand . instance ( ) . condition ( 'after' ) ) ;
256
258
fix . detectChanges ( ) ;
257
259
expect ( grid . rowList . length ) . toEqual ( 2 ) ;
258
260
@@ -261,23 +263,23 @@ describe('IgxGrid - Filtering actions #grid', () => {
261
263
fix . detectChanges ( ) ;
262
264
expect ( grid . rowList . length ) . toEqual ( 8 ) ;
263
265
grid . filter ( 'ReleaseDate' , cal . timedelta ( today , 'day' , 4 ) ,
264
- IgxDateFilteringOperand . instance ( ) . condition ( 'before' ) ) ;
266
+ IgxDateFilteringOperand . instance ( ) . condition ( 'before' ) ) ;
265
267
fix . detectChanges ( ) ;
266
268
expect ( grid . rowList . length ) . toEqual ( 4 ) ;
267
269
268
270
// DoesNotEqual filter
269
271
grid . clearFilter ( 'ReleaseDate' ) ;
270
272
fix . detectChanges ( ) ;
271
273
grid . filter ( 'ReleaseDate' , cal . timedelta ( today , 'day' , 15 ) ,
272
- IgxDateFilteringOperand . instance ( ) . condition ( 'doesNotEqual' ) ) ;
274
+ IgxDateFilteringOperand . instance ( ) . condition ( 'doesNotEqual' ) ) ;
273
275
fix . detectChanges ( ) ;
274
276
expect ( grid . rowList . length ) . toEqual ( 7 ) ;
275
277
276
278
// Equals filter
277
279
grid . clearFilter ( 'ReleaseDate' ) ;
278
280
fix . detectChanges ( ) ;
279
281
grid . filter ( 'ReleaseDate' , cal . timedelta ( today , 'day' , 15 ) ,
280
- IgxDateFilteringOperand . instance ( ) . condition ( 'equals' ) ) ;
282
+ IgxDateFilteringOperand . instance ( ) . condition ( 'equals' ) ) ;
281
283
fix . detectChanges ( ) ;
282
284
expect ( grid . rowList . length ) . toEqual ( 1 ) ;
283
285
@@ -428,7 +430,7 @@ describe('IgxGrid - Filtering actions #grid', () => {
428
430
] ;
429
431
430
432
const gridExpressionsTree = new FilteringExpressionsTree ( FilteringLogic . And ) ;
431
- gridExpressionsTree . filteringOperands = [ colDownloadsExprTree , colIdExprTree ] ;
433
+ gridExpressionsTree . filteringOperands = [ colDownloadsExprTree , colIdExprTree ] ;
432
434
433
435
grid . filteringExpressionsTree = gridExpressionsTree ;
434
436
fix . detectChanges ( ) ;
@@ -468,9 +470,9 @@ describe('IgxGrid - Filtering actions #grid', () => {
468
470
it ( 'Should correctly apply two conditions to string column.' , fakeAsync ( ( ) => {
469
471
const filteringExpressionsTree = new FilteringExpressionsTree ( FilteringLogic . And , 'ProductName' ) ;
470
472
const expression = {
471
- fieldName : 'ProductName' ,
472
- searchVal : 'Ignite' ,
473
- condition : IgxStringFilteringOperand . instance ( ) . condition ( 'startsWith' )
473
+ fieldName : 'ProductName' ,
474
+ searchVal : 'Ignite' ,
475
+ condition : IgxStringFilteringOperand . instance ( ) . condition ( 'startsWith' )
474
476
} ;
475
477
const expression1 = {
476
478
fieldName : 'ProductName' ,
@@ -554,9 +556,9 @@ describe('IgxGrid - Filtering actions #grid', () => {
554
556
it ( 'Should generate the expressions UI list correctly.' , fakeAsync ( ( ) => {
555
557
const filteringExpressionsTree = new FilteringExpressionsTree ( FilteringLogic . Or , 'ProductName' ) ;
556
558
const expression = {
557
- fieldName : 'ProductName' ,
558
- searchVal : 'Ignite' ,
559
- condition : IgxStringFilteringOperand . instance ( ) . condition ( 'startsWith' )
559
+ fieldName : 'ProductName' ,
560
+ searchVal : 'Ignite' ,
561
+ condition : IgxStringFilteringOperand . instance ( ) . condition ( 'startsWith' )
560
562
} ;
561
563
const expression1 = new FilteringExpressionsTree ( FilteringLogic . And , 'ProductName' ) ;
562
564
const expression11 = {
@@ -668,7 +670,7 @@ describe('IgxGrid - Filtering actions #grid', () => {
668
670
grid . filterStrategy = NoopFilteringStrategy . instance ( ) ;
669
671
fix . detectChanges ( ) ;
670
672
671
- grid . filter ( 'ProductName' , 'some value' , IgxStringFilteringOperand . instance ( ) . condition ( 'contains' ) ) ;
673
+ grid . filter ( 'ProductName' , 'some value' , IgxStringFilteringOperand . instance ( ) . condition ( 'contains' ) ) ;
672
674
fix . detectChanges ( ) ;
673
675
674
676
// Verify the grid is not filtered, because of the noop filter strategy.
@@ -689,7 +691,7 @@ describe('IgxGrid - Filtering expression tree bindings #grid', () => {
689
691
BrowserAnimationsModule ,
690
692
IgxGridModule ]
691
693
} )
692
- . compileComponents ( ) ;
694
+ . compileComponents ( ) ;
693
695
} ) ) ;
694
696
695
697
let fix , grid : IgxGridComponent ;
@@ -720,160 +722,6 @@ describe('IgxGrid - Filtering expression tree bindings #grid', () => {
720
722
} ) ) ;
721
723
} ) ;
722
724
723
- const expectedResults = [ ] ;
724
-
725
- // Fill expected results for 'date' filtering conditions based on the current date
726
- function fillExpectedResults ( grid : IgxGridComponent , calendar : Calendar , today ) {
727
- // day + 15
728
- const dateItem0 = generateICalendarDate ( grid . data [ 0 ] . ReleaseDate ,
729
- today . getFullYear ( ) , today . getMonth ( ) ) ;
730
- // month - 1
731
- const dateItem1 = generateICalendarDate ( grid . data [ 1 ] . ReleaseDate ,
732
- today . getFullYear ( ) , today . getMonth ( ) ) ;
733
- // day - 1
734
- const dateItem3 = generateICalendarDate ( grid . data [ 3 ] . ReleaseDate ,
735
- today . getFullYear ( ) , today . getMonth ( ) ) ;
736
- // day + 1
737
- const dateItem5 = generateICalendarDate ( grid . data [ 5 ] . ReleaseDate ,
738
- today . getFullYear ( ) , today . getMonth ( ) ) ;
739
- // month + 1
740
- const dateItem6 = generateICalendarDate ( grid . data [ 6 ] . ReleaseDate ,
741
- today . getFullYear ( ) , today . getMonth ( ) ) ;
742
-
743
- let thisMonthCountItems = 1 ;
744
- let nextMonthCountItems = 1 ;
745
- let lastMonthCountItems = 1 ;
746
- let thisYearCountItems = 6 ;
747
- let nextYearCountItems = 0 ;
748
- let lastYearCountItems = 0 ;
749
-
750
- // LastMonth filter
751
- if ( dateItem3 . isPrevMonth ) {
752
- lastMonthCountItems ++ ;
753
- }
754
- expectedResults [ 0 ] = lastMonthCountItems ;
755
-
756
- // thisMonth filter
757
- if ( dateItem0 . isCurrentMonth ) {
758
- thisMonthCountItems ++ ;
759
- }
760
-
761
- if ( dateItem3 . isCurrentMonth ) {
762
- thisMonthCountItems ++ ;
763
- }
764
-
765
- if ( dateItem5 . isCurrentMonth ) {
766
- thisMonthCountItems ++ ;
767
- }
768
-
769
- // NextMonth filter
770
- if ( dateItem0 . isNextMonth ) {
771
- nextMonthCountItems ++ ;
772
- }
773
-
774
- if ( dateItem5 . isNextMonth ) {
775
- nextMonthCountItems ++ ;
776
- }
777
- expectedResults [ 1 ] = nextMonthCountItems ;
778
-
779
- // ThisYear, NextYear, PreviousYear filter
780
-
781
- // day + 15
782
- if ( ! dateItem0 . isThisYear ) {
783
- thisYearCountItems -- ;
784
- }
785
-
786
- if ( dateItem0 . isNextYear ) {
787
- nextYearCountItems ++ ;
788
- }
789
-
790
- // month - 1
791
- if ( ! dateItem1 . isThisYear ) {
792
- thisYearCountItems -- ;
793
- }
794
-
795
- if ( dateItem1 . isLastYear ) {
796
- lastYearCountItems ++ ;
797
- }
798
-
799
- // day - 1
800
- if ( ! dateItem3 . isThisYear ) {
801
- thisYearCountItems -- ;
802
- }
803
-
804
- if ( dateItem3 . isLastYear ) {
805
- lastYearCountItems ++ ;
806
- }
807
-
808
- // day + 1
809
- if ( ! dateItem5 . isThisYear ) {
810
- thisYearCountItems -- ;
811
- }
812
-
813
- if ( dateItem5 . isNextYear ) {
814
- nextYearCountItems ++ ;
815
- }
816
-
817
- // month + 1
818
- if ( ! dateItem6 . isThisYear ) {
819
- thisYearCountItems -- ;
820
- }
821
-
822
- if ( dateItem6 . isNextYear ) {
823
- nextYearCountItems ++ ;
824
- }
825
-
826
- // ThisYear filter result
827
- expectedResults [ 2 ] = thisYearCountItems ;
828
-
829
- // NextYear filter result
830
- expectedResults [ 3 ] = nextYearCountItems ;
831
-
832
- // PreviousYear filter result
833
- expectedResults [ 4 ] = lastYearCountItems ;
834
-
835
- // ThisMonth filter result
836
- expectedResults [ 5 ] = thisMonthCountItems ;
837
- }
838
-
839
- function generateICalendarDate ( date : Date , year : number , month : number ) {
840
- return {
841
- date,
842
- isCurrentMonth : date . getFullYear ( ) === year && date . getMonth ( ) === month ,
843
- isLastYear : isLastYear ( date , year ) ,
844
- isNextMonth : isNextMonth ( date , year , month ) ,
845
- isNextYear : isNextYear ( date , year ) ,
846
- isPrevMonth : isPreviousMonth ( date , year , month ) ,
847
- isThisYear : isThisYear ( date , year )
848
- } ;
849
- }
850
-
851
- function isPreviousMonth ( date : Date , year : number , month : number ) : boolean {
852
- if ( date . getFullYear ( ) === year ) {
853
- return date . getMonth ( ) < month ;
854
- }
855
- return date . getFullYear ( ) < year ;
856
- }
857
-
858
- function isNextMonth ( date : Date , year : number , month : number ) : boolean {
859
- if ( date . getFullYear ( ) === year ) {
860
- return date . getMonth ( ) > month ;
861
- }
862
- return date . getFullYear ( ) > year ;
863
- }
864
-
865
- function isThisYear ( date : Date , year : number ) : boolean {
866
- return date . getFullYear ( ) === year ;
867
- }
868
-
869
- function isLastYear ( date : Date , year : number ) : boolean {
870
- return date . getFullYear ( ) < year ;
871
- }
872
-
873
- function isNextYear ( date : Date , year : number ) : boolean {
874
- return date . getFullYear ( ) > year ;
875
- }
876
-
877
725
function verifyExpressionUI ( expressionUI : ExpressionUI , expression : IFilteringExpression ,
878
726
afterOperator : FilteringLogic , beforeOperator : FilteringLogic ) {
879
727
expect ( expressionUI . expression ) . toBe ( expression ) ;
0 commit comments