UNPKG

react-native-reanimated-carousel

Version:

Simple carousel component.fully implemented using Reanimated 2.Infinitely scrolling, very smooth.

2 lines 2.56 kB
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _computeNewIndexWhenDataChanges=require("./computeNewIndexWhenDataChanges");describe("should work as expected",function(){var size=375;var positive=-1;var negative=1;var params=function params(_params){var currentIndex=_params.currentIndex,_direction=_params.direction,previousLength=_params.previousLength,currentLength=_params.currentLength;var direction=_direction==="negative"?negative:positive;return{direction:direction,handlerOffset:size*currentIndex*direction,size:size,previousLength:previousLength,currentLength:currentLength};};it("The direction is negative, And changing length of data set from 4 to 3, the new index will to be 2.",(0,_asyncToGenerator2.default)(function*(){var currentIndex=1;var handlerOffset=(0,_computeNewIndexWhenDataChanges.computeNewIndexWhenDataChanges)(params({currentIndex:currentIndex,direction:"negative",previousLength:4,currentLength:3}));expect(handlerOffset/size).toBe(2*positive);}));it("The direction is negative, Changing length of data set from 4 to 3, the index remains original.",(0,_asyncToGenerator2.default)(function*(){var handlerOffset=(0,_computeNewIndexWhenDataChanges.computeNewIndexWhenDataChanges)(params({currentIndex:2,direction:"negative",previousLength:4,currentLength:3}));expect(handlerOffset/size).toBe(1*negative);}));it("The direction is positive, Changing length of data set from 4 to 5, the index remains original.",(0,_asyncToGenerator2.default)(function*(){var handlerOffset=(0,_computeNewIndexWhenDataChanges.computeNewIndexWhenDataChanges)(params({currentIndex:3,direction:"positive",previousLength:4,currentLength:5}));expect(handlerOffset/size).toBe(3*positive);}));it("The direction is negative, Changing length of data set from 4 to 5, the index remains original.",(0,_asyncToGenerator2.default)(function*(){var handlerOffset=(0,_computeNewIndexWhenDataChanges.computeNewIndexWhenDataChanges)(params({currentIndex:3,direction:"negative",previousLength:4,currentLength:5}));expect(handlerOffset/size).toBe(4*negative);}));it("Changing length of data set from 0 to 3, the index remains original.",(0,_asyncToGenerator2.default)(function*(){var handlerOffset=(0,_computeNewIndexWhenDataChanges.computeNewIndexWhenDataChanges)(params({currentIndex:0,direction:"positive",previousLength:0,currentLength:3}));expect(handlerOffset/size).toBe(0*positive);}));}); //# sourceMappingURL=index.test.js.map