import React from 'react';
import { renderHook } from '@testing-library/react-native';
import { useDragAnimatedStyle } from '../../hooks/drag/useDragAnimatedStyle';
import { DragStateProvider } from '../../contexts/DragStateContext';
import { createMockSharedValue } from '../utils/test-utils';
describe('useDragAnimatedStyle', () => {
const createWrapper = () => {
const Wrapper = ({ children }: { children: React.ReactNode }) => (
{children}
);
return Wrapper;
};
it('returns dragAnimatedStyle', async () => {
const isDragging = createMockSharedValue(false);
const translateY = createMockSharedValue(0);
const shiftY = createMockSharedValue(0);
const { result } = await renderHook(
() => useDragAnimatedStyle('item-1', isDragging as any, translateY as any, shiftY as any),
{ wrapper: createWrapper() },
);
expect(result.current.dragAnimatedStyle).toBeDefined();
});
it('uses itemId to identify the dragged item', async () => {
const isDragging = createMockSharedValue(false);
const translateY = createMockSharedValue(0);
const shiftY = createMockSharedValue(0);
const { result } = await renderHook(
() => useDragAnimatedStyle('test-item', isDragging as any, translateY as any, shiftY as any),
{ wrapper: createWrapper() },
);
expect(result.current.dragAnimatedStyle).toBeDefined();
});
it('works with different isDragging states', async () => {
const isDraggingFalse = createMockSharedValue(false);
const isDraggingTrue = createMockSharedValue(true);
const translateY = createMockSharedValue(0);
const shiftY = createMockSharedValue(0);
const { result: resultFalse } = await renderHook(
() => useDragAnimatedStyle('item-1', isDraggingFalse as any, translateY as any, shiftY as any),
{ wrapper: createWrapper() },
);
const { result: resultTrue } = await renderHook(
() => useDragAnimatedStyle('item-1', isDraggingTrue as any, translateY as any, shiftY as any),
{ wrapper: createWrapper() },
);
expect(resultFalse.current.dragAnimatedStyle).toBeDefined();
expect(resultTrue.current.dragAnimatedStyle).toBeDefined();
});
it('handles translateY values', async () => {
const isDragging = createMockSharedValue(true);
const translateY = createMockSharedValue(100);
const shiftY = createMockSharedValue(0);
const { result } = await renderHook(
() => useDragAnimatedStyle('item-1', isDragging as any, translateY as any, shiftY as any),
{ wrapper: createWrapper() },
);
expect(result.current.dragAnimatedStyle).toBeDefined();
});
it('handles shiftY values', async () => {
const isDragging = createMockSharedValue(false);
const translateY = createMockSharedValue(0);
const shiftY = createMockSharedValue(-80);
const { result } = await renderHook(
() => useDragAnimatedStyle('item-1', isDragging as any, translateY as any, shiftY as any),
{ wrapper: createWrapper() },
);
expect(result.current.dragAnimatedStyle).toBeDefined();
});
it('handles negative translateY', async () => {
const isDragging = createMockSharedValue(true);
const translateY = createMockSharedValue(-50);
const shiftY = createMockSharedValue(0);
const { result } = await renderHook(
() => useDragAnimatedStyle('item-1', isDragging as any, translateY as any, shiftY as any),
{ wrapper: createWrapper() },
);
expect(result.current.dragAnimatedStyle).toBeDefined();
});
it('works with custom drag config from provider', async () => {
const Wrapper = ({ children }: { children: React.ReactNode }) => (
{children}
);
const isDragging = createMockSharedValue(true);
const translateY = createMockSharedValue(50);
const shiftY = createMockSharedValue(0);
const { result } = await renderHook(
() => useDragAnimatedStyle('item-1', isDragging as any, translateY as any, shiftY as any),
{ wrapper: Wrapper },
);
expect(result.current.dragAnimatedStyle).toBeDefined();
});
});