layout.test.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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', { height: 400 }, COMPLETE );
  15. splide.mount();
  16. const slide = splide.Components.Elements.slides[ 0 ];
  17. expect( slide.style.height ).toBe( '400px' );
  18. global.innerHeight = 100;
  19. splide.options = { height: '10vh' };
  20. expect( slide.style.height ).toBe( 100 / 10 + 'px' ); // window height / 10.
  21. } );
  22. test( 'should apply height to a slide element when a "fixedHeight" option is provided.', () => {
  23. const splide = new Splide( '#splide', { fixedHeight: 400 }, COMPLETE );
  24. splide.mount();
  25. const slide = splide.Components.Elements.slides[ 0 ];
  26. expect( slide.style.height ).toBe( '400px' );
  27. } );
  28. test( 'should set proper width of a slide element according to a perPage option in horizontal mode.', () => {
  29. const splide = new Splide( '#splide', { perPage: 2 }, COMPLETE );
  30. splide.mount();
  31. const track = splide.Components.Elements.track;
  32. // Force to set clientWidth of a track.
  33. Object.defineProperty( track, 'clientWidth', { value: 800 } );
  34. splide.emit( 'resize' );
  35. const slide = splide.Components.Elements.slides[ 0 ];
  36. expect( slide.style.width ).toBe( '400px' );
  37. // Is the width updated correctly after perPage option is updated?
  38. splide.options = { perPage: 4 };
  39. expect( slide.style.width ).toBe( '200px' );
  40. } );
  41. test( 'should set proper height of a slide element according to a perPage option in vertical mode.', () => {
  42. const splide = new Splide( '#splide', { direction: 'ttb', perPage: 2, height: 400 }, COMPLETE );
  43. splide.mount();
  44. const track = splide.Components.Elements.track;
  45. Object.defineProperty( track, 'clientWidth', { value: 800 } );
  46. const slide = splide.Components.Elements.slides[ 0 ];
  47. expect( slide.style.height ).toBe( '200px' );
  48. splide.options = { perPage: 4 };
  49. expect( slide.style.height ).toBe( '100px' );
  50. } );
  51. test( 'should set margin according to a gap size.', () => {
  52. const splide = new Splide( '#splide', { gap: 10 }, COMPLETE );
  53. splide.mount();
  54. const slide = splide.Components.Elements.slides[ 0 ];
  55. expect( slide.style.marginRight ).toBe( '10px' );
  56. } );
  57. } );