123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- import { findRuleBy, fire, init } from '../../../test';
- describe( 'Move', () => {
- test( 'can jump to the specific slide.', () => {
- const splide = init( { width: 200, height: 100 } );
- const { Move } = splide.Components;
- const { list } = splide.Components.Elements;
- Move.jump( 2 );
- expect( list.style.transform ).toBe( 'translateX(-400px)' );
- Move.jump( 4 );
- expect( list.style.transform ).toBe( 'translateX(-800px)' );
- splide.destroy();
- } );
- test( 'can set transform to the list element.', () => {
- const splide = init( { width: 200, height: 100 } );
- const { Move } = splide.Components;
- const { list } = splide.Components.Elements;
- Move.translate( 100 );
- expect( list.style.transform ).toBe( 'translateX(100px)' );
- Move.translate( 500 );
- expect( list.style.transform ).toBe( 'translateX(500px)' );
- splide.destroy();
- } );
- test( 'can loop the slider if it exceeds bounds.', () => {
- // Note: All clones do not have dimensions.
- const width = 200;
- const splide = init( { type: 'loop', width, height: 100 } );
- const { Move } = splide.Components;
- const { list } = splide.Components.Elements;
- Move.translate( width );
- expect( list.style.transform ).toBe( `translateX(${ -width * ( splide.length - 1 ) }px)` );
- splide.destroy();
- } );
- test( 'can cancel the transition.', () => {
- const splide = init( { width: 200, height: 100 } );
- const { Move } = splide.Components;
- const { list } = splide.Components.Elements;
- Move.move( 1, 1, -1 );
- const rule = findRuleBy( list );
- expect( rule.style.transition ).not.toBe( '' );
- Move.cancel();
- expect( rule.style.transition ).toBe( '' );
- splide.destroy();
- } );
- test( 'can convert the position to the closest index.', () => {
- const splide = init( { width: 200, height: 100 } );
- const { Move } = splide.Components;
- expect( Move.toIndex( 0 ) ).toBe( 0 );
- expect( Move.toIndex( -99 ) ).toBe( 0 );
- expect( Move.toIndex( -100 ) ).toBe( 1 );
- expect( Move.toIndex( -200 ) ).toBe( 1 );
- expect( Move.toIndex( -299 ) ).toBe( 1 );
- expect( Move.toIndex( -300 ) ).toBe( 2 );
- splide.destroy();
- } );
- test( 'can convert the index to the position.', () => {
- const splide = init( { width: 200, height: 100 } );
- const { Move } = splide.Components;
- expect( Move.toPosition( 0 ) ).toBe( -0 );
- expect( Move.toPosition( 1 ) ).toBe( -200 );
- expect( Move.toPosition( 2 ) ).toBe( -400 );
- expect( Move.toPosition( 3 ) ).toBe( -600 );
- splide.destroy();
- } );
- test( 'can check the position exceeds bounds or not.', () => {
- const width = 200;
- const splide = init( { width, height: 100 } );
- const totalSize = width * splide.length;
- const { Move } = splide.Components;
- expect( Move.exceededLimit( false, -10 ) ).toBe( false );
- expect( Move.exceededLimit( false, 10 ) ).toBe( true );
- expect( Move.exceededLimit( true, - ( totalSize - width ) + 10 ) ).toBe( false );
- expect( Move.exceededLimit( true, - ( totalSize - width ) - 10 ) ).toBe( true );
- Move.translate( 10 );
- expect( Move.exceededLimit() ).toBe( true );
- splide.destroy();
- } );
- test( 'can check if the slider can move or not.', () => {
- const splide = init( { width: 200, height: 100 } );
- const { Move } = splide.Components;
- expect( Move.isBusy() ).toBe( false );
- Move.move( 1, 1, -1 );
- expect( Move.isBusy() ).toBe( true );
- fire( splide.Components.Elements.list, 'transitionend' );
- expect( Move.isBusy() ).toBe( false );
- splide.destroy();
- } );
- test( 'should not move the slider while looping.', () => {
- const splide = init( { type: 'loop', width: 200, height: 100, waitForTransition: false } );
- const { Move } = splide.Components;
- expect( Move.isBusy() ).toBe( false );
- // Designates the clone index.
- Move.move( splide.length, 0, -1 );
- expect( Move.isBusy() ).toBe( true );
- fire( splide.Components.Elements.list, 'transitionend' );
- expect( Move.isBusy() ).toBe( false );
- splide.destroy();
- } );
- } );
|