1
1
import { Component , DebugElement , ViewChild } from "@angular/core" ;
2
2
import { async , fakeAsync , TestBed , tick } from "@angular/core/testing" ;
3
3
import { By } from "@angular/platform-browser" ;
4
+ import { BrowserAnimationsModule } from "@angular/platform-browser/animations" ;
5
+ import { IgxInputDirective } from "../directives/input/input.directive" ;
4
6
import { IgxDateSummaryOperand , IgxNumberSummaryOperand } from "./grid-summary" ;
5
7
import { IgxGridComponent } from "./grid.component" ;
6
8
import { IgxGridModule } from "./index" ;
7
9
8
10
describe ( "IgxGrid - Summaries" , ( ) => {
9
11
const SUMMARY_CLASS = ".igx-grid-summary" ;
10
12
const SUMMARY_LABEL_CLASS = ".igx-grid-summary__label" ;
11
- const SUMMARY_VALUE_CLASS = "igx-grid-summary__result" ;
13
+ const SUMMARY_VALUE_CLASS = ". igx-grid-summary__result" ;
12
14
const ITEM_CLASS = "igx-grid-summary__item" ;
13
15
const HIDDEN_ITEM_CLASS = "igx-grid-summary__item--inactive" ;
14
16
@@ -18,7 +20,7 @@ describe("IgxGrid - Summaries", () => {
18
20
NoActiveSummariesComponent ,
19
21
SummaryColumnComponent
20
22
] ,
21
- imports : [ IgxGridModule . forRoot ( ) ]
23
+ imports : [ BrowserAnimationsModule , IgxGridModule . forRoot ( ) ]
22
24
} )
23
25
. compileComponents ( ) ;
24
26
} ) ) ;
@@ -270,10 +272,12 @@ describe("IgxGrid - Summaries", () => {
270
272
it ( "should calc tfoot height according number of summary functions" , ( ) => {
271
273
const fixture = TestBed . createComponent ( SummaryColumnComponent ) ;
272
274
fixture . detectChanges ( ) ;
273
-
275
+ const initialSummarySize = 36.36 ;
274
276
const grid = fixture . componentInstance . grid1 ;
275
277
const summaries = fixture . debugElement . queryAll ( By . css ( "igx-grid-summary" ) ) ;
276
- const tfootSize = fixture . debugElement . query ( By . css ( ".igx-grid__tfoot" ) ) . query ( By . css ( ".igx-grid__tr" ) ) . nativeElement . clientHeight ;
278
+ const footerRow = fixture . debugElement . query ( By . css ( ".igx-grid__tfoot" ) ) . query ( By . css ( ".igx-grid__tr" ) )
279
+ . nativeElement . style [ "height" ] . match ( / \d + \. + \d / ) ;
280
+ const tfootSize = + footerRow ;
277
281
278
282
let maxSummaryLength = 0 ;
279
283
let index = 0 ;
@@ -284,7 +288,7 @@ describe("IgxGrid - Summaries", () => {
284
288
}
285
289
index ++ ;
286
290
} ) ;
287
- const expectedHeight = maxSummaryLength * 36 ;
291
+ const expectedHeight = maxSummaryLength * initialSummarySize ;
288
292
expect ( tfootSize ) . toBe ( expectedHeight ) ;
289
293
} ) ;
290
294
it ( "should calculate summaries for 'number' dataType or return if no data is provided" , ( ) => {
@@ -325,6 +329,47 @@ describe("IgxGrid - Summaries", () => {
325
329
expect ( emptySummaries [ 1 ] . summaryResult ) . toBe ( undefined ) ;
326
330
expect ( emptySummaries [ 2 ] . summaryResult ) . toBe ( undefined ) ;
327
331
} ) ;
332
+ it ( "should calculate summaries only over filteredData" , ( done ) => {
333
+ const fixture = TestBed . createComponent ( SummaryColumnComponent ) ;
334
+ fixture . detectChanges ( ) ;
335
+
336
+ const grid = fixture . componentInstance . grid1 ;
337
+ const filterUIContainer = fixture . debugElement . query ( By . css ( "igx-grid-filter" ) ) ;
338
+ const filterIcon = filterUIContainer . query ( By . css ( "igx-icon" ) ) ;
339
+ const input = filterUIContainer . query ( By . directive ( IgxInputDirective ) ) ;
340
+ const select = filterUIContainer . query ( By . css ( "div > select" ) ) ;
341
+ const summaries = fixture . debugElement . queryAll ( By . css ( "igx-grid-summary" ) ) ;
342
+
343
+ filterIcon . nativeElement . click ( ) ;
344
+ fixture . detectChanges ( ) ;
345
+ select . nativeElement . value = "equals" ;
346
+ select . nativeElement . dispatchEvent ( new Event ( "change" ) ) ;
347
+
348
+ sendInput ( input , "0" , fixture ) . then ( ( ) => {
349
+ fixture . detectChanges ( ) ;
350
+ const filterResult = grid . rowList . length ;
351
+ expect ( filterResult ) . toEqual ( 3 ) ;
352
+ let index = 0 ;
353
+ grid . columnList . forEach ( ( col ) => {
354
+ if ( col . hasSummary ) {
355
+ const values = summaries [ index ] . queryAll ( By . css ( SUMMARY_VALUE_CLASS ) ) ;
356
+ expect ( + values [ 0 ] . nativeElement . innerText ) . toBe ( filterResult ) ;
357
+ if ( col . field === "UnitsInStock" ) {
358
+ expect ( values [ 1 ] . nativeElement . innerText ) . toBe ( "0" ) ;
359
+ expect ( values [ 2 ] . nativeElement . innerText ) . toBe ( "0" ) ;
360
+ }
361
+ }
362
+ index ++ ;
363
+ } ) ;
364
+ done ( ) ;
365
+ } ) ;
366
+ } ) ;
367
+ function sendInput ( element , text : string , fix ) {
368
+ element . nativeElement . value = text ;
369
+ element . nativeElement . dispatchEvent ( new Event ( "input" ) ) ;
370
+ fix . detectChanges ( ) ;
371
+ return fix . whenStable ( ) ;
372
+ }
328
373
329
374
} ) ;
330
375
@@ -372,7 +417,7 @@ export class NoActiveSummariesComponent {
372
417
</igx-column>
373
418
<igx-column field="InStock" [dataType]="'boolean'" [hasSummary]="true">
374
419
</igx-column>
375
- <igx-column field="UnitsInStock" [dataType]="'number'" [hasSummary]="true">
420
+ <igx-column field="UnitsInStock" [dataType]="'number'" [hasSummary]="true" [filterable]="true" >
376
421
</igx-column>
377
422
<igx-column field="OrderDate" width="200px" [dataType]="'date'" [sortable]="true" [hasSummary]="true">
378
423
</igx-column>
0 commit comments