sync.test.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { sync } from '../data/html';
  2. import Splide from '../../src/js/splide';
  3. import { COMPLETE } from '../../src/js/components';
  4. describe( 'Sub Splide synchronized to a main one', () => {
  5. let main, sub;
  6. beforeEach( () => {
  7. document.body.innerHTML = sync;
  8. sub = new Splide( '#sub', { isNavigation: true }, COMPLETE ).mount();
  9. main = new Splide( '#splide', {}, COMPLETE ).sync( sub ).mount();
  10. } );
  11. test( 'should update index of a main slider when changing its active index, and vise versa.', () => {
  12. sub.go( 1 );
  13. expect( main.index ).toBe( 1 );
  14. expect( sub.index ).toBe( 1 );
  15. main.go( 2 );
  16. expect( main.index ).toBe( 2 );
  17. expect( sub.index ).toBe( 2 );
  18. } );
  19. test( 'should update index of a main slider when a slide of a sub with isNavigation option is clicked.', () => {
  20. const slides = sub.Components.Elements.slides;
  21. const secondSlide = slides[ 1 ];
  22. const thirdSlide = slides[ 2 ];
  23. // Simulate a mouseup event with a left click.
  24. secondSlide.dispatchEvent( new Event( 'mouseup', { button: 0 } ) );
  25. expect( main.index ).toBe( 1 );
  26. expect( sub.index ).toBe( 1 );
  27. // Simulate a touchend event.
  28. thirdSlide.dispatchEvent( new Event( 'touchend' ) );
  29. expect( main.index ).toBe( 2 );
  30. expect( sub.index ).toBe( 2 );
  31. } );
  32. } );