UNPKG

react-native-reanimated-carousel

Version:

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

2 lines 5.86 kB
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _react=_interopRequireDefault(require("react"));var _reactNative=require("react-native");var _reactHooks=require("@testing-library/react-hooks");var _useLayoutConfig=require("./useLayoutConfig");var _jsxRuntime=require("react/jsx-runtime");var _this=this,_jsxFileName="/home/runner/work/react-native-reanimated-carousel/react-native-reanimated-carousel/src/hooks/useLayoutConfig.test.tsx";describe("useLayoutConfig",function(){var defaultProps={size:300,vertical:false};it("should return normal layout by default",function(){var _renderHook=(0,_reactHooks.renderHook)(function(){return(0,_useLayoutConfig.useLayoutConfig)(Object.assign({},defaultProps,{data:[],renderItem:function renderItem(){return(0,_jsxRuntime.jsx)(_reactNative.View,{});},loop:false,autoFillData:false,defaultIndex:0,autoPlayInterval:0,scrollAnimationDuration:0,width:0,height:0,rawData:[],dataLength:0,rawDataLength:0}));}),result=_renderHook.result;expect(result.current).toBeDefined();expect(typeof result.current).toBe("function");});it("should handle parallax mode",function(){var props=Object.assign({},defaultProps,{mode:"parallax",modeConfig:{parallaxScrollingScale:0.9,parallaxScrollingOffset:50,parallaxAdjacentItemScale:0.8}});var _renderHook2=(0,_reactHooks.renderHook)(function(){return(0,_useLayoutConfig.useLayoutConfig)(Object.assign({},props,{data:[],renderItem:function renderItem(){return(0,_jsxRuntime.jsx)(_reactNative.View,{});},loop:false,autoFillData:false,defaultIndex:0,autoPlayInterval:0,scrollAnimationDuration:0,width:0,height:0,rawData:[],dataLength:0,rawDataLength:0}));}),result=_renderHook2.result;var style=result.current(0);expect(style.transform).toBeDefined();expect(style.transform).toContainEqual({translateX:0});expect(style.transform).toContainEqual({scale:0.9});});it("should handle horizontal-stack mode",function(){var props=Object.assign({},defaultProps,{mode:"horizontal-stack",modeConfig:{snapDirection:"left",showLength:3}});var _renderHook3=(0,_reactHooks.renderHook)(function(){return(0,_useLayoutConfig.useLayoutConfig)(Object.assign({},props,{data:[],renderItem:function renderItem(){return(0,_jsxRuntime.jsx)(_reactNative.View,{});},loop:false,autoFillData:false,defaultIndex:0,autoPlayInterval:0,scrollAnimationDuration:0,width:0,height:0,rawData:[],dataLength:0,rawDataLength:0}));}),result=_renderHook3.result;var style=result.current(0);expect(style.transform).toBeDefined();expect(style.zIndex).toBeDefined();expect(style.opacity).toBeDefined();});it("should handle vertical-stack mode",function(){var props=Object.assign({},defaultProps,{mode:"vertical-stack",modeConfig:{snapDirection:"left",showLength:3}});var _renderHook4=(0,_reactHooks.renderHook)(function(){return(0,_useLayoutConfig.useLayoutConfig)(Object.assign({},props,{data:[],renderItem:function renderItem(){return(0,_jsxRuntime.jsx)(_reactNative.View,{});},loop:false,autoFillData:false,defaultIndex:0,autoPlayInterval:0,scrollAnimationDuration:0,width:0,height:0,rawData:[],dataLength:0,rawDataLength:0}));}),result=_renderHook4.result;var style=result.current(0);expect(style.transform).toBeDefined();expect(style.zIndex).toBeDefined();expect(style.opacity).toBeDefined();});it("should handle vertical orientation",function(){var props=Object.assign({},defaultProps,{vertical:true});var _renderHook5=(0,_reactHooks.renderHook)(function(){return(0,_useLayoutConfig.useLayoutConfig)(Object.assign({},props,{data:[],renderItem:function renderItem(){return(0,_jsxRuntime.jsx)(_reactNative.View,{});},loop:false,autoFillData:false,defaultIndex:0,autoPlayInterval:0,scrollAnimationDuration:0,width:0,height:0,rawData:[],dataLength:0,rawDataLength:0}));}),result=_renderHook5.result;var style=result.current(0);expect(style.transform).toBeDefined();expect(style.transform).toContainEqual({translateY:0});});it("should handle different offsets",function(){var _renderHook6=(0,_reactHooks.renderHook)(function(){return(0,_useLayoutConfig.useLayoutConfig)(Object.assign({},defaultProps,{data:[],renderItem:function renderItem(){return(0,_jsxRuntime.jsx)(_reactNative.View,{});},loop:false,autoFillData:false,defaultIndex:0,autoPlayInterval:0,scrollAnimationDuration:0,width:0,height:0,rawData:[],dataLength:0,rawDataLength:0}));}),result=_renderHook6.result;var style1=result.current(-1);var style2=result.current(0);var style3=result.current(1);expect(style1.transform).toContainEqual({translateX:-300});expect(style2.transform).toContainEqual({translateX:0});expect(style3.transform).toContainEqual({translateX:300});});it("should memoize layout function",function(){var _renderHook7=(0,_reactHooks.renderHook)(function(){return(0,_useLayoutConfig.useLayoutConfig)(Object.assign({},defaultProps,{data:[],renderItem:function renderItem(){return(0,_jsxRuntime.jsx)(_reactNative.View,{});},loop:false,autoFillData:false,defaultIndex:0,autoPlayInterval:0,scrollAnimationDuration:0,width:0,height:0,rawData:[],dataLength:0,rawDataLength:0}));}),result=_renderHook7.result,rerender=_renderHook7.rerender;var firstResult=result.current;rerender();expect(result.current).toBe(firstResult);});it("should update layout when props change",function(){var _renderHook8=(0,_reactHooks.renderHook)(function(props){return(0,_useLayoutConfig.useLayoutConfig)(Object.assign({},props,{data:[],renderItem:function renderItem(){return(0,_jsxRuntime.jsx)(_reactNative.View,{});},loop:false,autoFillData:false,defaultIndex:0,autoPlayInterval:0,scrollAnimationDuration:0,width:0,height:0,rawData:[],dataLength:0,rawDataLength:0}));},{initialProps:defaultProps}),result=_renderHook8.result,rerender=_renderHook8.rerender;var firstResult=result.current;rerender(Object.assign({},defaultProps,{size:400}));expect(result.current).not.toBe(firstResult);});}); //# sourceMappingURL=useLayoutConfig.test.js.map