layout.test.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { minimum } from '../data/html';
  2. import Splide from '../../src/js/splide';
  3. import { COMPLETE } from '../../src/js/components';
  4. describe( 'The Layout ', () => {
  5. beforeEach( () => {
  6. document.body.innerHTML = minimum;
  7. } );
  8. test( 'should apply max-width to a root element when a "width" option is provided.', () => {
  9. const splide = new Splide( '#splide', { width: 800 }, COMPLETE );
  10. splide.mount();
  11. expect( splide.root.style.maxWidth ).toBe( '800px' );
  12. } );
  13. test( 'should apply height to a slide element when a "height" option is provided.', () => {
  14. const splide = new Splide( '#splide', { fixedHeight: '40em' }, COMPLETE );
  15. splide.mount();
  16. const slide = splide.Components.Elements.slides.pop();
  17. expect( slide.style.height ).toBe( '40em' );
  18. } );
  19. test( 'should set proper width of a slide element according to a perView option in horizontal mode.', () => {
  20. const splide = new Splide( '#splide', { perView: 2 }, COMPLETE );
  21. splide.mount();
  22. const track = splide.Components.Elements.track;
  23. // Force to set clientWidth of a track.
  24. Object.defineProperty( track, 'clientWidth', { value: 800 } );
  25. splide.emit( 'resize' );
  26. const slide = splide.Components.Elements.slides.pop();
  27. expect( slide.style.width ).toBe( '400px' );
  28. // Is the width updated correctly after perView option is updated?
  29. splide.options = { perView: 4 };
  30. expect( slide.style.width ).toBe( '200px' );
  31. } );
  32. test( 'should set proper height of a slide element according to a perView option in vertical mode.', () => {
  33. const splide = new Splide( '#splide', { direction: 'ttb', perView: 2, height: 400 }, COMPLETE );
  34. splide.mount();
  35. const track = splide.Components.Elements.track;
  36. Object.defineProperty( track, 'clientWidth', { value: 800 } );
  37. const slide = splide.Components.Elements.slides.pop();
  38. expect( slide.style.height ).toBe( '200px' );
  39. splide.options = { perView: 4 };
  40. expect( slide.style.height ).toBe( '100px' );
  41. } );
  42. test( 'should set margin according to a gap size.', () => {
  43. const splide = new Splide( '#splide', { gap: 10 }, COMPLETE );
  44. splide.mount();
  45. const slide = splide.Components.Elements.slides.pop();
  46. expect( slide.style.marginRight ).toBe( '10px' );
  47. } );
  48. } );