1
- import { ComponentFixture , TestBed , tick , fakeAsync } from '@angular/core/testing' ;
2
- import { Component , ViewChild , Type , Provider } from '@angular/core' ;
1
+ import { ComponentFixture , fakeAsync , TestBed , tick } from '@angular/core/testing' ;
2
+ import { Component , Provider , Type , ViewChild } from '@angular/core' ;
3
3
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
4
4
import { dispatchMouseEvent } from '../../cdk/testing/private' ;
5
5
import { ThemePalette } from '@angular/material/core' ;
6
6
import { MatSelect } from '@angular/material/select' ;
7
7
import { By } from '@angular/platform-browser' ;
8
- import { MatPaginatorModule , MatPaginator , MatPaginatorIntl } from './index' ;
8
+ import { MatPaginator , MatPaginatorIntl , MatPaginatorModule } from './index' ;
9
9
import { MAT_PAGINATOR_DEFAULT_OPTIONS , MatPaginatorDefaultOptions } from './paginator' ;
10
10
11
11
@@ -23,52 +23,72 @@ describe('MatPaginator', () => {
23
23
}
24
24
25
25
describe ( 'with the default internationalization provider' , ( ) => {
26
- it ( 'should show the right range text' , ( ) => {
27
- const fixture = createComponent ( MatPaginatorApp ) ;
28
- const component = fixture . componentInstance ;
29
- const rangeElement = fixture . nativeElement . querySelector ( '.mat-paginator-range-label' ) ;
30
-
31
- // View second page of list of 100, each page contains 10 items.
32
- component . length = 100 ;
33
- component . pageSize = 10 ;
34
- component . pageIndex = 1 ;
35
- fixture . detectChanges ( ) ;
36
- expect ( rangeElement . innerText . trim ( ) ) . toBe ( '11 – 20 of 100' ) ;
37
-
38
- // View third page of list of 200, each page contains 20 items.
39
- component . length = 200 ;
40
- component . pageSize = 20 ;
41
- component . pageIndex = 2 ;
42
- fixture . detectChanges ( ) ;
43
- expect ( rangeElement . innerText . trim ( ) ) . toBe ( '41 – 60 of 200' ) ;
44
-
45
- // View first page of list of 0, each page contains 5 items.
46
- component . length = 0 ;
47
- component . pageSize = 5 ;
48
- component . pageIndex = 2 ;
49
- fixture . detectChanges ( ) ;
50
- expect ( rangeElement . innerText . trim ( ) ) . toBe ( '0 of 0' ) ;
51
-
52
- // View third page of list of 12, each page contains 5 items.
53
- component . length = 12 ;
54
- component . pageSize = 5 ;
55
- component . pageIndex = 2 ;
56
- fixture . detectChanges ( ) ;
57
- expect ( rangeElement . innerText . trim ( ) ) . toBe ( '11 – 12 of 12' ) ;
58
-
59
- // View third page of list of 10, each page contains 5 items.
60
- component . length = 10 ;
61
- component . pageSize = 5 ;
62
- component . pageIndex = 2 ;
63
- fixture . detectChanges ( ) ;
64
- expect ( rangeElement . innerText . trim ( ) ) . toBe ( '11 – 15 of 10' ) ;
65
-
66
- // View third page of list of -5, each page contains 5 items.
67
- component . length = - 5 ;
68
- component . pageSize = 5 ;
69
- component . pageIndex = 2 ;
70
- fixture . detectChanges ( ) ;
71
- expect ( rangeElement . innerText . trim ( ) ) . toBe ( '11 – 15 of 0' ) ;
26
+ describe ( 'showing the right range text' , ( ) => {
27
+ it ( 'should show second page of list of 100, each page contains 10 items' , ( ) => {
28
+ const fixture = createComponent ( MatPaginatorApp ) ;
29
+ const component = fixture . componentInstance ;
30
+ const rangeElement = fixture . nativeElement . querySelector ( '.mat-paginator-range-label' ) ;
31
+ component . length = 100 ;
32
+ component . pageSize = 10 ;
33
+ component . pageIndex = 1 ;
34
+ fixture . detectChanges ( ) ;
35
+ expect ( rangeElement . textContent ! . trim ( ) ) . toBe ( '11 – 20 of 100' ) ;
36
+ } ) ;
37
+
38
+ it ( 'should show third page of list of 200, each page contains 20 items' , ( ) => {
39
+ const fixture = createComponent ( MatPaginatorApp ) ;
40
+ const component = fixture . componentInstance ;
41
+ const rangeElement = fixture . nativeElement . querySelector ( '.mat-paginator-range-label' ) ;
42
+ component . length = 200 ;
43
+ component . pageSize = 20 ;
44
+ component . pageIndex = 2 ;
45
+ fixture . detectChanges ( ) ;
46
+ expect ( rangeElement . textContent ! . trim ( ) ) . toBe ( '41 – 60 of 200' ) ;
47
+ } ) ;
48
+
49
+ it ( 'should show first page of list of 0, each page contains 5 items' , ( ) => {
50
+ const fixture = createComponent ( MatPaginatorApp ) ;
51
+ const component = fixture . componentInstance ;
52
+ const rangeElement = fixture . nativeElement . querySelector ( '.mat-paginator-range-label' ) ;
53
+ component . length = 0 ;
54
+ component . pageSize = 5 ;
55
+ component . pageIndex = 2 ;
56
+ fixture . detectChanges ( ) ;
57
+ expect ( rangeElement . textContent ! . trim ( ) ) . toBe ( '0 of 0' ) ;
58
+ } ) ;
59
+
60
+ it ( 'should show third page of list of 12, each page contains 5 items' , ( ) => {
61
+ const fixture = createComponent ( MatPaginatorApp ) ;
62
+ const component = fixture . componentInstance ;
63
+ const rangeElement = fixture . nativeElement . querySelector ( '.mat-paginator-range-label' ) ;
64
+ component . length = 12 ;
65
+ component . pageSize = 5 ;
66
+ component . pageIndex = 2 ;
67
+ fixture . detectChanges ( ) ;
68
+ expect ( rangeElement . textContent ! . trim ( ) ) . toBe ( '11 – 12 of 12' ) ;
69
+ } ) ;
70
+
71
+ it ( 'should show third page of list of 10, each page contains 5 items' , ( ) => {
72
+ const fixture = createComponent ( MatPaginatorApp ) ;
73
+ const component = fixture . componentInstance ;
74
+ const rangeElement = fixture . nativeElement . querySelector ( '.mat-paginator-range-label' ) ;
75
+ component . length = 10 ;
76
+ component . pageSize = 5 ;
77
+ component . pageIndex = 2 ;
78
+ fixture . detectChanges ( ) ;
79
+ expect ( rangeElement . textContent ! . trim ( ) ) . toBe ( '11 – 15 of 10' ) ;
80
+ } ) ;
81
+
82
+ it ( 'should show third page of list of -5, each page contains 5 items' , ( ) => {
83
+ const fixture = createComponent ( MatPaginatorApp ) ;
84
+ const component = fixture . componentInstance ;
85
+ const rangeElement = fixture . nativeElement . querySelector ( '.mat-paginator-range-label' ) ;
86
+ component . length = - 5 ;
87
+ component . pageSize = 5 ;
88
+ component . pageIndex = 2 ;
89
+ fixture . detectChanges ( ) ;
90
+ expect ( rangeElement . textContent ! . trim ( ) ) . toBe ( '11 – 15 of 0' ) ;
91
+ } ) ;
72
92
} ) ;
73
93
74
94
it ( 'should show right aria-labels for select and buttons' , ( ) => {
0 commit comments