import React from 'react';
import { I18nManager, Text, View } from 'react-native';
import { render } from '@testing-library/react-native';
import { SwipeRegistryProvider } from '../../../contexts/swipeableContext/SwipeRegistryContext';
import { SwipableWrapper } from '../SwipableWrapper';
const mockReanimatedSwipeable = jest.fn(({ children }: React.PropsWithChildren) => (
{children}
));
jest.mock('react-native-gesture-handler/ReanimatedSwipeable', () => ({
__esModule: true,
default: (...args: unknown[]) => mockReanimatedSwipeable(...args),
SwipeDirection: {
LEFT: 'left',
RIGHT: 'right',
},
}));
describe('SwipableWrapper', () => {
const originalIsRTL = I18nManager.isRTL;
const setRTL = (value: boolean) => {
Object.defineProperty(I18nManager, 'isRTL', {
configurable: true,
value,
});
};
const renderWithRegistry = (ui: React.ReactElement) =>
render({ui});
beforeEach(() => {
mockReanimatedSwipeable.mockClear();
});
afterEach(() => {
setRTL(originalIsRTL);
});
it('uses right-side overshoot defaults in ltr', () => {
setRTL(false);
renderWithRegistry(
child
,
);
expect(mockReanimatedSwipeable).toHaveBeenCalledWith(
expect.objectContaining({
overshootLeft: false,
overshootRight: true,
}),
undefined,
);
});
it('uses left-side overshoot defaults in rtl', () => {
setRTL(true);
renderWithRegistry(
child
,
);
expect(mockReanimatedSwipeable).toHaveBeenCalledWith(
expect.objectContaining({
overshootLeft: true,
overshootRight: false,
}),
undefined,
);
});
it('maps logical right actions to left actions in rtl', () => {
setRTL(true);
const renderRightActions = jest.fn(() => null);
renderWithRegistry(
child
,
);
expect(mockReanimatedSwipeable).toHaveBeenCalledWith(
expect.objectContaining({
renderLeftActions: renderRightActions,
renderRightActions: undefined,
}),
undefined,
);
});
});