@@ -407,61 +407,101 @@ describe('pagination-nav', () => {
407407 } )
408408
409409 it ( 'clicking buttons updates the v-model' , async ( ) => {
410- const wrapper = mount ( BPaginationNav , {
411- propsData : {
412- baseUrl : '#' , // needed to prevent JSDOM errors
413- numberOfPages : 3 ,
414- value : 1 ,
415- limit : 10
410+ const App = {
411+ methods : {
412+ onPageClick ( bvEvt , page ) {
413+ // Prevent 3rd page from being selected
414+ if ( page === 3 ) {
415+ bvEvt . preventDefault ( )
416+ }
417+ }
418+ } ,
419+ render ( h ) {
420+ return h ( BPaginationNav , {
421+ props : {
422+ baseUrl : '#' , // Needed to prevent JSDOM errors
423+ numberOfPages : 5 ,
424+ value : 1 ,
425+ limit : 10
426+ } ,
427+ on : { 'page-click' : this . onPageClick }
428+ } )
416429 }
417- } )
418- expect ( wrapper . element . tagName ) . toBe ( 'NAV' )
430+ }
431+
432+ const wrapper = mount ( App )
433+ expect ( wrapper ) . toBeDefined ( )
419434
420- expect ( wrapper . findAll ( 'li' ) . length ) . toBe ( 7 )
435+ const paginationNav = wrapper . findComponent ( BPaginationNav )
436+ expect ( paginationNav ) . toBeDefined ( )
437+ expect ( paginationNav . element . tagName ) . toBe ( 'NAV' )
421438
422- expect ( wrapper . vm . computedCurrentPage ) . toBe ( 1 )
423- expect ( wrapper . emitted ( 'input' ) ) . not . toBeDefined ( )
439+ // Grab the page links
440+ const lis = paginationNav . findAll ( 'li' )
441+ expect ( lis . length ) . toBe ( 9 )
424442
425- // Click on current page button (does nothing)
426- await wrapper
427- . findAll ( 'li' )
443+ expect ( paginationNav . vm . computedCurrentPage ) . toBe ( 1 )
444+ expect ( paginationNav . emitted ( 'input' ) ) . not . toBeDefined ( )
445+ expect ( paginationNav . emitted ( 'change' ) ) . not . toBeDefined ( )
446+ expect ( paginationNav . emitted ( 'page-click' ) ) . not . toBeDefined ( )
447+
448+ // Click on current (1st) page link (does nothing)
449+ await lis
428450 . at ( 2 )
429451 . find ( 'a' )
430452 . trigger ( 'click' )
431453 await waitRAF ( )
432- expect ( wrapper . vm . computedCurrentPage ) . toBe ( 1 )
433- expect ( wrapper . emitted ( 'input' ) ) . not . toBeDefined ( )
454+ expect ( paginationNav . vm . computedCurrentPage ) . toBe ( 1 )
455+ expect ( paginationNav . emitted ( 'input' ) ) . not . toBeDefined ( )
456+ expect ( paginationNav . emitted ( 'change' ) ) . not . toBeDefined ( )
457+ expect ( paginationNav . emitted ( 'page-click' ) ) . not . toBeDefined ( )
434458
435- // Click on 2nd page button
436- await wrapper
437- . findAll ( 'li' )
459+ // Click on 2nd page link
460+ await lis
438461 . at ( 3 )
439462 . find ( 'a' )
440463 . trigger ( 'click' )
441464 await waitRAF ( )
442- expect ( wrapper . vm . computedCurrentPage ) . toBe ( 2 )
443- expect ( wrapper . emitted ( 'input' ) ) . toBeDefined ( )
444- expect ( wrapper . emitted ( 'input' ) [ 0 ] [ 0 ] ) . toBe ( 2 )
445-
446- // Click goto last button
447- await wrapper
448- . findAll ( 'li' )
449- . at ( 6 )
465+ expect ( paginationNav . vm . computedCurrentPage ) . toBe ( 2 )
466+ expect ( paginationNav . emitted ( 'input' ) ) . toBeDefined ( )
467+ expect ( paginationNav . emitted ( 'change' ) ) . toBeDefined ( )
468+ expect ( paginationNav . emitted ( 'page-click' ) ) . toBeDefined ( )
469+ expect ( paginationNav . emitted ( 'input' ) [ 0 ] [ 0 ] ) . toBe ( 2 )
470+ expect ( paginationNav . emitted ( 'change' ) [ 0 ] [ 0 ] ) . toBe ( 2 )
471+ expect ( paginationNav . emitted ( 'page-click' ) . length ) . toBe ( 1 )
472+
473+ // Click goto last page link
474+ await lis
475+ . at ( 8 )
450476 . find ( 'a' )
451- . trigger ( 'keydown.space' ) // Generates a click event
477+ . trigger ( 'click' )
452478 await waitRAF ( )
453- expect ( wrapper . vm . computedCurrentPage ) . toBe ( 3 )
454- expect ( wrapper . emitted ( 'input' ) [ 1 ] [ 0 ] ) . toBe ( 3 )
479+ expect ( paginationNav . vm . computedCurrentPage ) . toBe ( 5 )
480+ expect ( paginationNav . emitted ( 'input' ) [ 1 ] [ 0 ] ) . toBe ( 5 )
481+ expect ( paginationNav . emitted ( 'change' ) [ 1 ] [ 0 ] ) . toBe ( 5 )
482+ expect ( paginationNav . emitted ( 'page-click' ) . length ) . toBe ( 2 )
455483
456- // Click prev button
457- await wrapper
458- . findAll ( 'li' )
484+ // Click prev page link
485+ await lis
459486 . at ( 1 )
460487 . find ( 'a' )
461488 . trigger ( 'click' )
462489 await waitRAF ( )
463- expect ( wrapper . vm . computedCurrentPage ) . toBe ( 2 )
464- expect ( wrapper . emitted ( 'input' ) [ 2 ] [ 0 ] ) . toBe ( 2 )
490+ expect ( paginationNav . vm . computedCurrentPage ) . toBe ( 4 )
491+ expect ( paginationNav . emitted ( 'input' ) [ 2 ] [ 0 ] ) . toBe ( 4 )
492+ expect ( paginationNav . emitted ( 'change' ) [ 2 ] [ 0 ] ) . toBe ( 4 )
493+ expect ( paginationNav . emitted ( 'page-click' ) . length ) . toBe ( 3 )
494+
495+ // Click on 3rd page link (prevented)
496+ await lis
497+ . at ( 4 )
498+ . find ( 'a' )
499+ . trigger ( 'click' )
500+ await waitRAF ( )
501+ expect ( paginationNav . vm . computedCurrentPage ) . toBe ( 4 )
502+ expect ( paginationNav . emitted ( 'input' ) . length ) . toBe ( 3 )
503+ expect ( paginationNav . emitted ( 'change' ) . length ) . toBe ( 3 )
504+ expect ( paginationNav . emitted ( 'page-click' ) . length ) . toBe ( 4 )
465505
466506 wrapper . destroy ( )
467507 } )
0 commit comments