react-native-reanimated-carousel
Version:
Simple carousel component.fully implemented using Reanimated 2.Infinitely scrolling, very smooth.
2 lines • 6.44 kB
JavaScript
var _stack=require("./stack");jest.mock("react-native-reanimated",function(){return{interpolate:jest.fn(function(value,inputRange,outputRange){var inputMin=inputRange[0];var inputMax=inputRange[inputRange.length-1];var outputMin=outputRange[0];var outputMax=outputRange[outputRange.length-1];if(value<=inputMin)return outputMin;if(value>=inputMax)return outputMax;var progress=(value-inputMin)/(inputMax-inputMin);return outputMin+progress*(outputMax-outputMin);}),Extrapolation:{CLAMP:"clamp"}};});jest.mock("react",function(){return{useMemo:jest.fn(function(fn){return fn();})};});jest.mock("react-native",function(){return{Dimensions:{get:jest.fn(function(){return{width:375,height:812};})}};});describe("horizontalStackLayout",function(){it("should make the rotateZDeg works properly when it is passed in horizontal-stack mode through modeConfig",function(){var screenWidth=375;var calculator=(0,_stack.horizontalStackLayout)({showLength:3,snapDirection:"left",moveSize:screenWidth,stackInterval:18,scaleInterval:0.04,opacityInterval:0.1,rotateZDeg:30});var result1=calculator(-0.5);expect(result1).toHaveProperty("transform");expect(result1).toHaveProperty("zIndex");expect(result1).toHaveProperty("opacity");expect(result1.transform).toHaveLength(3);var result2=calculator(-1);expect(result2).toHaveProperty("transform");expect(result2).toHaveProperty("zIndex");expect(result2).toHaveProperty("opacity");expect(result2.transform).toHaveLength(3);});it("should handle right snap direction",function(){var calculator=(0,_stack.horizontalStackLayout)({showLength:3,snapDirection:"right",moveSize:375,stackInterval:18,scaleInterval:0.04,opacityInterval:0.1,rotateZDeg:30});var result=calculator(0);expect(result).toHaveProperty("transform");expect(result).toHaveProperty("zIndex");expect(result).toHaveProperty("opacity");expect(result.transform).toHaveLength(3);});it("should handle default config",function(){var calculator=(0,_stack.horizontalStackLayout)();var result=calculator(0);expect(result).toHaveProperty("transform");expect(result).toHaveProperty("zIndex");expect(result).toHaveProperty("opacity");});it("should handle edge values",function(){var calculator=(0,_stack.horizontalStackLayout)({showLength:5,snapDirection:"left"});var extremeLeftResult=calculator(-2);var extremeRightResult=calculator(4);expect(extremeLeftResult).toHaveProperty("transform");expect(extremeRightResult).toHaveProperty("transform");});it("should handle custom parameters",function(){var _result$transform;var calculator=(0,_stack.horizontalStackLayout)({showLength:4,snapDirection:"right",moveSize:400,stackInterval:25,scaleInterval:0.06,opacityInterval:0.15,rotateZDeg:45});var result=calculator(1);expect(result).toHaveProperty("transform");expect(result.transform).toHaveLength(3);expect((_result$transform=result.transform)==null?void 0:_result$transform[2]).toHaveProperty("rotateZ");});});describe("verticalStackLayout",function(){it("should handle left snap direction",function(){var _result$transform2;var calculator=(0,_stack.verticalStackLayout)({showLength:3,snapDirection:"left",moveSize:375,stackInterval:18,scaleInterval:0.04,opacityInterval:0.1,rotateZDeg:30});var result=calculator(0);expect(result).toHaveProperty("transform");expect(result).toHaveProperty("zIndex");expect(result).toHaveProperty("opacity");expect(result.transform).toHaveLength(4);expect((_result$transform2=result.transform)==null?void 0:_result$transform2[3]).toHaveProperty("translateY");});it("should handle right snap direction",function(){var _result$transform3;var calculator=(0,_stack.verticalStackLayout)({showLength:3,snapDirection:"right",moveSize:375,stackInterval:18,scaleInterval:0.04,opacityInterval:0.1,rotateZDeg:30});var result=calculator(0);expect(result).toHaveProperty("transform");expect(result.transform).toHaveLength(4);expect((_result$transform3=result.transform)==null?void 0:_result$transform3[3]).toHaveProperty("translateY");});it("should handle default config",function(){var calculator=(0,_stack.verticalStackLayout)();var result=calculator(0);expect(result).toHaveProperty("transform");expect(result).toHaveProperty("zIndex");expect(result).toHaveProperty("opacity");expect(result.transform).toHaveLength(4);});it("should handle different values",function(){var calculator=(0,_stack.verticalStackLayout)({showLength:4,snapDirection:"left"});var leftResult=calculator(-1);var centerResult=calculator(0);var rightResult=calculator(1);expect(leftResult).toHaveProperty("transform");expect(centerResult).toHaveProperty("transform");expect(rightResult).toHaveProperty("transform");});it("should handle fractional values",function(){var calculator=(0,_stack.verticalStackLayout)({showLength:3,snapDirection:"right"});var result=calculator(0.5);expect(result).toHaveProperty("transform");expect(result.transform).toHaveLength(4);});});describe("useHorizontalStackLayout",function(){it("should return layout and config for left snap direction",function(){var customAnimationConfig={snapDirection:"left",showLength:3};var result=(0,_stack.useHorizontalStackLayout)(customAnimationConfig);expect(result).toHaveProperty("layout");expect(result).toHaveProperty("config");expect(typeof result.layout).toBe("function");expect(result.config.type).toBe("positive");expect(result.config.viewCount).toBe(3);});it("should return layout and config for right snap direction",function(){var customAnimationConfig={snapDirection:"right",showLength:4};var result=(0,_stack.useHorizontalStackLayout)(customAnimationConfig);expect(result).toHaveProperty("layout");expect(result).toHaveProperty("config");expect(result.config.type).toBe("negative");expect(result.config.viewCount).toBe(4);});it("should handle default config",function(){var result=(0,_stack.useHorizontalStackLayout)();expect(result).toHaveProperty("layout");expect(result).toHaveProperty("config");expect(typeof result.layout).toBe("function");expect(result.config.type).toBe("positive");});it("should handle empty custom config",function(){var result=(0,_stack.useHorizontalStackLayout)({},{});expect(result).toHaveProperty("layout");expect(result).toHaveProperty("config");});it("should merge custom config correctly",function(){var customAnimationConfig={snapDirection:"right",showLength:2};var result=(0,_stack.useHorizontalStackLayout)(customAnimationConfig);expect(result.config.type).toBe("negative");expect(result.config.viewCount).toBe(2);});});
//# sourceMappingURL=stack.test.js.map