focus.test.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { minimum } from '../data/html';
  2. import Splide from '../../src/js/splide';
  3. import { COMPLETE } from '../../src/js/components';
  4. describe( 'Splide with "focus" option', () => {
  5. let splide;
  6. beforeEach( () => {
  7. document.body.innerHTML = minimum;
  8. splide = new Splide( '#splide' ).mount( COMPLETE );
  9. } );
  10. test( 'should locate the active slide on the center of the slider if the value is "center".', () => {
  11. const { Track, Elements: { track } } = splide.Components;
  12. const width = 900;
  13. const perView = 3;
  14. const slideWidth = width / perView;
  15. Object.defineProperty( track, 'clientWidth', { value: width } );
  16. splide.options = { focus: 'center', perView };
  17. expect( Track.offset ).toBe( - ( width / 2 - slideWidth / 2 ) );
  18. } );
  19. test( 'should locate the active slide according to the focus index.', () => {
  20. const { Track, Elements: { track } } = splide.Components;
  21. const width = 900;
  22. const perView = 3;
  23. const focus = 2;
  24. const slideWidth = width / perView;
  25. Object.defineProperty( track, 'clientWidth', { value: width } );
  26. splide.options = { focus, perView };
  27. expect( Track.offset ).toBe( - slideWidth * focus );
  28. } );
  29. } );