get-parent-cell.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. QUnit.test( 'getParentCell', function( assert ) {
  2. 'use strict';
  3. var gallery = document.querySelector('#get-parent-cell');
  4. var flkty = new Flickity( gallery );
  5. // cell1
  6. var cell = flkty.getParentCell( gallery.querySelector('.cell1') );
  7. assert.ok( cell, 'getParentCell( cell ) ok' );
  8. assert.ok( cell instanceof Flickity.Cell, 'cell is Flickity.Cell' );
  9. var index = flkty.cells.indexOf( cell );
  10. assert.equal( index, 0, 'cell is index 0' );
  11. // cell3
  12. cell = flkty.getParentCell( gallery.querySelector('.cell3') );
  13. assert.ok( cell, 'getParentCell( cell ) ok' );
  14. assert.ok( cell instanceof Flickity.Cell, 'cell is Flickity.Cell' );
  15. index = flkty.cells.indexOf( cell );
  16. assert.equal( index, 2, 'cell is index 2' );
  17. // child1
  18. cell = flkty.getParentCell( gallery.querySelector('.child1') );
  19. assert.ok( cell, 'getParentCell( cell ) ok' );
  20. assert.ok( cell instanceof Flickity.Cell, 'cell is Flickity.Cell' );
  21. index = flkty.cells.indexOf( cell );
  22. assert.equal( index, 0, 'cell is index 0' );
  23. // child2
  24. cell = flkty.getParentCell( gallery.querySelector('.child2') );
  25. assert.ok( cell, 'getParentCell( cell ) ok' );
  26. assert.ok( cell instanceof Flickity.Cell, 'cell is Flickity.Cell' );
  27. index = flkty.cells.indexOf( cell );
  28. assert.equal( index, 1, 'cell is index 1' );
  29. // outside
  30. cell = flkty.getParentCell( document.querySelector('.outside') );
  31. assert.ok( !cell, 'getParentCell( notCell ) not ok' );
  32. index = flkty.cells.indexOf( cell );
  33. assert.equal( index, -1, 'not cell is index -1' );
  34. });