@@ -7,10 +7,12 @@ import { IgxGridComponent } from './grid.component';
77import { IgxGridModule } from './index' ;
88import { configureTestSuite } from '../../test-utils/configure-suite' ;
99import { IgxChipComponent } from '../../chips' ;
10- import { IgxStringFilteringOperand ,
10+ import {
11+ IgxStringFilteringOperand ,
1112 IgxNumberFilteringOperand ,
1213 IgxBooleanFilteringOperand ,
13- IgxDateFilteringOperand } from '../../data-operations/filtering-condition' ;
14+ IgxDateFilteringOperand
15+ } from '../../data-operations/filtering-condition' ;
1416import { FilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree' ;
1517import { SampleTestData } from '../../test-utils/sample-test-data.spec' ;
1618import { GridFunctions , GridSummaryFunctions } from '../../test-utils/grid-functions.spec' ;
@@ -29,7 +31,7 @@ describe('IgxGrid - Filtering actions #grid', () => {
2931 BrowserAnimationsModule ,
3032 IgxGridModule ]
3133 } )
32- . compileComponents ( ) ;
34+ . compileComponents ( ) ;
3335 } ) ) ;
3436
3537 let fix , grid ;
@@ -89,7 +91,7 @@ describe('IgxGrid - Filtering actions #grid', () => {
8991 // Null filter
9092 grid . clearFilter ( 'ProductName' ) ;
9193 fix . detectChanges ( ) ;
92- grid . filter ( 'ProductName' , null , IgxStringFilteringOperand . instance ( ) . condition ( 'null' ) , true ) ;
94+ grid . filter ( 'ProductName' , null , IgxStringFilteringOperand . instance ( ) . condition ( 'null' ) , true ) ;
9395 fix . detectChanges ( ) ;
9496 expect ( grid . rowList . length ) . toEqual ( 3 ) ;
9597
@@ -248,11 +250,11 @@ describe('IgxGrid - Filtering actions #grid', () => {
248250 const today = SampleTestData . today ;
249251
250252 // Fill expected results based on the current date
251- fillExpectedResults ( grid , cal , today ) ;
253+ const expectedResults = GridFunctions . createDateFilterConditions ( grid , today ) ;
252254
253255 // After filter
254256 grid . filter ( 'ReleaseDate' , cal . timedelta ( today , 'day' , 4 ) ,
255- IgxDateFilteringOperand . instance ( ) . condition ( 'after' ) ) ;
257+ IgxDateFilteringOperand . instance ( ) . condition ( 'after' ) ) ;
256258 fix . detectChanges ( ) ;
257259 expect ( grid . rowList . length ) . toEqual ( 2 ) ;
258260
@@ -261,23 +263,23 @@ describe('IgxGrid - Filtering actions #grid', () => {
261263 fix . detectChanges ( ) ;
262264 expect ( grid . rowList . length ) . toEqual ( 8 ) ;
263265 grid . filter ( 'ReleaseDate' , cal . timedelta ( today , 'day' , 4 ) ,
264- IgxDateFilteringOperand . instance ( ) . condition ( 'before' ) ) ;
266+ IgxDateFilteringOperand . instance ( ) . condition ( 'before' ) ) ;
265267 fix . detectChanges ( ) ;
266268 expect ( grid . rowList . length ) . toEqual ( 4 ) ;
267269
268270 // DoesNotEqual filter
269271 grid . clearFilter ( 'ReleaseDate' ) ;
270272 fix . detectChanges ( ) ;
271273 grid . filter ( 'ReleaseDate' , cal . timedelta ( today , 'day' , 15 ) ,
272- IgxDateFilteringOperand . instance ( ) . condition ( 'doesNotEqual' ) ) ;
274+ IgxDateFilteringOperand . instance ( ) . condition ( 'doesNotEqual' ) ) ;
273275 fix . detectChanges ( ) ;
274276 expect ( grid . rowList . length ) . toEqual ( 7 ) ;
275277
276278 // Equals filter
277279 grid . clearFilter ( 'ReleaseDate' ) ;
278280 fix . detectChanges ( ) ;
279281 grid . filter ( 'ReleaseDate' , cal . timedelta ( today , 'day' , 15 ) ,
280- IgxDateFilteringOperand . instance ( ) . condition ( 'equals' ) ) ;
282+ IgxDateFilteringOperand . instance ( ) . condition ( 'equals' ) ) ;
281283 fix . detectChanges ( ) ;
282284 expect ( grid . rowList . length ) . toEqual ( 1 ) ;
283285
@@ -428,7 +430,7 @@ describe('IgxGrid - Filtering actions #grid', () => {
428430 ] ;
429431
430432 const gridExpressionsTree = new FilteringExpressionsTree ( FilteringLogic . And ) ;
431- gridExpressionsTree . filteringOperands = [ colDownloadsExprTree , colIdExprTree ] ;
433+ gridExpressionsTree . filteringOperands = [ colDownloadsExprTree , colIdExprTree ] ;
432434
433435 grid . filteringExpressionsTree = gridExpressionsTree ;
434436 fix . detectChanges ( ) ;
@@ -468,9 +470,9 @@ describe('IgxGrid - Filtering actions #grid', () => {
468470 it ( 'Should correctly apply two conditions to string column.' , fakeAsync ( ( ) => {
469471 const filteringExpressionsTree = new FilteringExpressionsTree ( FilteringLogic . And , 'ProductName' ) ;
470472 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' )
474476 } ;
475477 const expression1 = {
476478 fieldName : 'ProductName' ,
@@ -554,9 +556,9 @@ describe('IgxGrid - Filtering actions #grid', () => {
554556 it ( 'Should generate the expressions UI list correctly.' , fakeAsync ( ( ) => {
555557 const filteringExpressionsTree = new FilteringExpressionsTree ( FilteringLogic . Or , 'ProductName' ) ;
556558 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' )
560562 } ;
561563 const expression1 = new FilteringExpressionsTree ( FilteringLogic . And , 'ProductName' ) ;
562564 const expression11 = {
@@ -668,7 +670,7 @@ describe('IgxGrid - Filtering actions #grid', () => {
668670 grid . filterStrategy = NoopFilteringStrategy . instance ( ) ;
669671 fix . detectChanges ( ) ;
670672
671- grid . filter ( 'ProductName' , 'some value' , IgxStringFilteringOperand . instance ( ) . condition ( 'contains' ) ) ;
673+ grid . filter ( 'ProductName' , 'some value' , IgxStringFilteringOperand . instance ( ) . condition ( 'contains' ) ) ;
672674 fix . detectChanges ( ) ;
673675
674676 // Verify the grid is not filtered, because of the noop filter strategy.
@@ -689,7 +691,7 @@ describe('IgxGrid - Filtering expression tree bindings #grid', () => {
689691 BrowserAnimationsModule ,
690692 IgxGridModule ]
691693 } )
692- . compileComponents ( ) ;
694+ . compileComponents ( ) ;
693695 } ) ) ;
694696
695697 let fix , grid : IgxGridComponent ;
@@ -720,160 +722,6 @@ describe('IgxGrid - Filtering expression tree bindings #grid', () => {
720722 } ) ) ;
721723} ) ;
722724
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-
877725function verifyExpressionUI ( expressionUI : ExpressionUI , expression : IFilteringExpression ,
878726 afterOperator : FilteringLogic , beforeOperator : FilteringLogic ) {
879727 expect ( expressionUI . expression ) . toBe ( expression ) ;
0 commit comments