cell-selector.js 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. QUnit.test( 'cellSelector', function( assert ) {
  2. 'use strict';
  3. var elem = document.querySelector('#cell-selector');
  4. var notCell1 = elem.querySelector('.not-cell1');
  5. var notCell2 = elem.querySelector('.not-cell2');
  6. var flkty = new Flickity( elem, {
  7. cellSelector: '.cell'
  8. });
  9. var cellsMatchSelector = true;
  10. for ( var i=0, len = flkty.cells.length; i < len; i++ ) {
  11. var cell = flkty.cells[i];
  12. var isMatch = matchesSelector( cell.element, flkty.options.cellSelector );
  13. cellsMatchSelector = cellsMatchSelector && isMatch;
  14. }
  15. // getCellElements()
  16. var cellElems = flkty.getCellElements();
  17. var queriedCellElems = elem.querySelectorAll( flkty.options.cellSelector );
  18. assert.equal( cellElems.length, flkty.cells.length, 'getCellElements returns corrent number of elements' );
  19. for( i=0, len = cellElems.length; i < len; i++ ) {
  20. assert.equal( cellElems[i], queriedCellElems[i], 'cell element same as queried cell element' );
  21. }
  22. assert.ok( cellsMatchSelector, 'all cell elements match cellSelector' );
  23. assert.equal( notCell1.parentNode, elem, 'notCell1 parent node is still gallery' );
  24. assert.equal( notCell2.parentNode, elem, 'notCell2 parent node is still gallery' );
  25. });