@@ -104,7 +104,7 @@ describe('MatPaginator', () => {
104104 } ) ) ;
105105 } ) ;
106106
107- describe ( 'when navigating with the navigation buttons' , ( ) => {
107+ describe ( 'when navigating with the next and previous buttons' , ( ) => {
108108 it ( 'should be able to go to the next page' , ( ) => {
109109 expect ( paginator . pageIndex ) . toBe ( 0 ) ;
110110
@@ -125,6 +125,58 @@ describe('MatPaginator', () => {
125125 expect ( component . latestPageEvent ? component . latestPageEvent . pageIndex : null ) . toBe ( 0 ) ;
126126 } ) ;
127127
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+
128180 it ( 'should disable navigating to the next page if at last page' , ( ) => {
129181 component . goToLastPage ( ) ;
130182 fixture . detectChanges ( ) ;
@@ -148,6 +200,7 @@ describe('MatPaginator', () => {
148200 expect ( component . latestPageEvent ) . toBe ( null ) ;
149201 expect ( paginator . pageIndex ) . toBe ( 0 ) ;
150202 } ) ;
203+
151204 } ) ;
152205
153206 it ( 'should mark for check when inputs are changed directly' , ( ) => {
@@ -253,7 +306,7 @@ describe('MatPaginator', () => {
253306 expect ( fixture . nativeElement . querySelector ( '.mat-select' ) ) . toBeNull ( ) ;
254307 } ) ;
255308
256- it ( 'should handle the number inputs being passed in as strings' , ( ) => {
309+ it ( 'should handle the number inputs being passed in as strings' , ( ) => {
257310 const withStringFixture = TestBed . createComponent ( MatPaginatorWithStringValues ) ;
258311 const withStringPaginator = withStringFixture . componentInstance . paginator ;
259312
@@ -277,6 +330,7 @@ describe('MatPaginator', () => {
277330 expect ( element . querySelector ( '.mat-paginator-page-size' ) )
278331 . toBeNull ( 'Expected select to be removed.' ) ;
279332 } ) ;
333+
280334} ) ;
281335
282336function getPreviousButton ( fixture : ComponentFixture < any > ) {
@@ -287,12 +341,21 @@ function getNextButton(fixture: ComponentFixture<any>) {
287341 return fixture . nativeElement . querySelector ( '.mat-paginator-navigation-next' ) ;
288342}
289343
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+
290352@Component ( {
291353 template : `
292354 <mat-paginator [pageIndex]="pageIndex"
293355 [pageSize]="pageSize"
294356 [pageSizeOptions]="pageSizeOptions"
295357 [hidePageSize]="hidePageSize"
358+ [showFirstLastButtons]="showFirstLastButtons"
296359 [length]="length"
297360 (page)="latestPageEvent = $event">
298361 </mat-paginator>
@@ -303,6 +366,7 @@ class MatPaginatorApp {
303366 pageSize = 10 ;
304367 pageSizeOptions = [ 5 , 10 , 25 , 100 ] ;
305368 hidePageSize = false ;
369+ showFirstLastButtons = false ;
306370 length = 100 ;
307371
308372 latestPageEvent : PageEvent | null ;
0 commit comments