layout.test.js 2.7 KB

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