@@ -104,7 +104,7 @@ describe('MatPaginator', () => {
104
104
} ) ) ;
105
105
} ) ;
106
106
107
- describe ( 'when navigating with the navigation buttons' , ( ) => {
107
+ describe ( 'when navigating with the next and previous buttons' , ( ) => {
108
108
it ( 'should be able to go to the next page' , ( ) => {
109
109
expect ( paginator . pageIndex ) . toBe ( 0 ) ;
110
110
@@ -125,6 +125,58 @@ describe('MatPaginator', () => {
125
125
expect ( component . latestPageEvent ? component . latestPageEvent . pageIndex : null ) . toBe ( 0 ) ;
126
126
} ) ;
127
127
128
+ } ) ;
129
+
130
+ it ( 'should be able to show the first/last buttons' , ( ) => {
131
+ expect ( getFirstButton ( fixture ) )
132
+ . toBeNull ( 'Expected first button to not exist.' ) ;
133
+
134
+ expect ( getLastButton ( fixture ) )
135
+ . toBeNull ( 'Expected last button to not exist.' ) ;
136
+
137
+ fixture . componentInstance . showFirstLastButtons = true ;
138
+ fixture . detectChanges ( ) ;
139
+
140
+ expect ( getFirstButton ( fixture ) )
141
+ . toBeTruthy ( 'Expected first button to be rendered.' ) ;
142
+
143
+ expect ( getLastButton ( fixture ) )
144
+ . toBeTruthy ( 'Expected last button to be rendered.' ) ;
145
+
146
+ } ) ;
147
+
148
+ describe ( 'when showing the first and last button' , ( ) => {
149
+
150
+ beforeEach ( ( ) => {
151
+ component . showFirstLastButtons = true ;
152
+ fixture . detectChanges ( ) ;
153
+ } ) ;
154
+
155
+ it ( 'should show right aria-labels for first/last buttons' , ( ) => {
156
+ expect ( getFirstButton ( fixture ) . getAttribute ( 'aria-label' ) ) . toBe ( 'First page' ) ;
157
+ expect ( getLastButton ( fixture ) . getAttribute ( 'aria-label' ) ) . toBe ( 'Last page' ) ;
158
+ } ) ;
159
+
160
+ it ( 'should be able to go to the last page via the last page button' , ( ) => {
161
+ expect ( paginator . pageIndex ) . toBe ( 0 ) ;
162
+
163
+ dispatchMouseEvent ( getLastButton ( fixture ) , 'click' ) ;
164
+
165
+ expect ( paginator . pageIndex ) . toBe ( 9 ) ;
166
+ expect ( component . latestPageEvent ? component . latestPageEvent . pageIndex : null ) . toBe ( 9 ) ;
167
+ } ) ;
168
+
169
+ it ( 'should be able to go to the first page via the first page button' , ( ) => {
170
+ paginator . pageIndex = 3 ;
171
+ fixture . detectChanges ( ) ;
172
+ expect ( paginator . pageIndex ) . toBe ( 3 ) ;
173
+
174
+ dispatchMouseEvent ( getFirstButton ( fixture ) , 'click' ) ;
175
+
176
+ expect ( paginator . pageIndex ) . toBe ( 0 ) ;
177
+ expect ( component . latestPageEvent ? component . latestPageEvent . pageIndex : null ) . toBe ( 0 ) ;
178
+ } ) ;
179
+
128
180
it ( 'should disable navigating to the next page if at last page' , ( ) => {
129
181
component . goToLastPage ( ) ;
130
182
fixture . detectChanges ( ) ;
@@ -148,6 +200,7 @@ describe('MatPaginator', () => {
148
200
expect ( component . latestPageEvent ) . toBe ( null ) ;
149
201
expect ( paginator . pageIndex ) . toBe ( 0 ) ;
150
202
} ) ;
203
+
151
204
} ) ;
152
205
153
206
it ( 'should mark for check when inputs are changed directly' , ( ) => {
@@ -253,7 +306,7 @@ describe('MatPaginator', () => {
253
306
expect ( fixture . nativeElement . querySelector ( '.mat-select' ) ) . toBeNull ( ) ;
254
307
} ) ;
255
308
256
- it ( 'should handle the number inputs being passed in as strings' , ( ) => {
309
+ it ( 'should handle the number inputs being passed in as strings' , ( ) => {
257
310
const withStringFixture = TestBed . createComponent ( MatPaginatorWithStringValues ) ;
258
311
const withStringPaginator = withStringFixture . componentInstance . paginator ;
259
312
@@ -277,6 +330,7 @@ describe('MatPaginator', () => {
277
330
expect ( element . querySelector ( '.mat-paginator-page-size' ) )
278
331
. toBeNull ( 'Expected select to be removed.' ) ;
279
332
} ) ;
333
+
280
334
} ) ;
281
335
282
336
function getPreviousButton ( fixture : ComponentFixture < any > ) {
@@ -287,12 +341,21 @@ function getNextButton(fixture: ComponentFixture<any>) {
287
341
return fixture . nativeElement . querySelector ( '.mat-paginator-navigation-next' ) ;
288
342
}
289
343
344
+ function getFirstButton ( fixture : ComponentFixture < any > ) {
345
+ return fixture . nativeElement . querySelector ( '.mat-paginator-navigation-first' ) ;
346
+ }
347
+
348
+ function getLastButton ( fixture : ComponentFixture < any > ) {
349
+ return fixture . nativeElement . querySelector ( '.mat-paginator-navigation-last' ) ;
350
+ }
351
+
290
352
@Component ( {
291
353
template : `
292
354
<mat-paginator [pageIndex]="pageIndex"
293
355
[pageSize]="pageSize"
294
356
[pageSizeOptions]="pageSizeOptions"
295
357
[hidePageSize]="hidePageSize"
358
+ [showFirstLastButtons]="showFirstLastButtons"
296
359
[length]="length"
297
360
(page)="latestPageEvent = $event">
298
361
</mat-paginator>
@@ -303,6 +366,7 @@ class MatPaginatorApp {
303
366
pageSize = 10 ;
304
367
pageSizeOptions = [ 5 , 10 , 25 , 100 ] ;
305
368
hidePageSize = false ;
369
+ showFirstLastButtons = false ;
306
370
length = 100 ;
307
371
308
372
latestPageEvent : PageEvent | null ;
0 commit comments