page-dots.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. QUnit.test( 'pageDots', function( assert ) {
  2. 'use strict';
  3. var elem = document.querySelector('#page-dots');
  4. var flkty = new Flickity( elem );
  5. var dotsHolder = elem.querySelector('.flickity-page-dots');
  6. var dotsElems = dotsHolder.querySelectorAll('.dot');
  7. assert.ok( dotsHolder, 'dots holder in DOM' );
  8. assert.equal( flkty.pageDots.holder, dotsHolder, 'dots holder element matches flkty.pageDots.holder' );
  9. assert.equal( dotsElems.length, flkty.cells.length, 'number of dots matches number of cells' );
  10. function getSelectedDotIndex() {
  11. var selectedDot = dotsHolder.querySelector('.is-selected');
  12. for ( var i=0, len = dotsElems.length; i < len; i++ ) {
  13. var dotElem = dotsElems[i];
  14. if ( dotElem == selectedDot ) {
  15. return i;
  16. }
  17. }
  18. return -1;
  19. }
  20. assert.equal( getSelectedDotIndex(), 0, 'first dot is selected' );
  21. flkty.select( 2 );
  22. assert.equal( getSelectedDotIndex(), 2, '3rd dot is selected' );
  23. // fake tap
  24. flkty.pageDots.onTap( { target: dotsElems[4] } );
  25. assert.equal( flkty.selectedIndex, 4, 'tap dot selects cell' );
  26. });