diff --git a/src/components/Lightbox.tsx b/src/components/Lightbox.tsx index cc10861..b392e69 100644 --- a/src/components/Lightbox.tsx +++ b/src/components/Lightbox.tsx @@ -5,7 +5,6 @@ import ImageView from '@observation.org/react-native-image-viewing' import Color from 'color' import { Icon } from './Icon' -import IconButton from './IconButton' import PageIndicator from './PageIndicator' import font from '../styles/font' import textStyle from '../styles/text' @@ -62,7 +61,7 @@ const getLightboxFooterComponent = - + diff --git a/src/components/__tests__/Lightbox.test.tsx b/src/components/__tests__/Lightbox.test.tsx index 6cc8765..1d58f26 100644 --- a/src/components/__tests__/Lightbox.test.tsx +++ b/src/components/__tests__/Lightbox.test.tsx @@ -15,6 +15,15 @@ const content = Jan de Vogelaar let onClose: () => void +let mockOnImageIndexChange = jest.fn() +jest.mock('@observation.org/react-native-image-viewing', () => { + const actualModule = jest.requireActual('@observation.org/react-native-image-viewing') + return (props: any) => { + mockOnImageIndexChange = props.onImageIndexChange as any + return actualModule.default(props) + } +}) + describe('Lightbox', () => { beforeEach(() => { onClose = jest.fn() @@ -85,13 +94,28 @@ describe('Lightbox', () => { test('Press delete button calls onDelete', async () => { // GIVEN const onDelete = jest.fn() - const { getByTestId } = render() + const { getByTestId } = render() + + // WHEN + await fireEvent.press(getByTestId('delete-photo')) + + // THEN + expect(onDelete).toHaveBeenCalledWith(0) + }) + + test('When swiping to the second photo and pressing the delete button, onDelete is called with the second photo', async () => { + // GIVEN + jest.mock('@observation.org/react-native-image-viewing', () => 'ImageCarousel') + + const onDelete = jest.fn() + const { getByTestId } = render() // WHEN + mockOnImageIndexChange(1) await fireEvent.press(getByTestId('delete-photo')) // THEN - expect(onDelete).toHaveBeenCalled() + expect(onDelete).toHaveBeenCalledWith(1) }) }) }) diff --git a/src/components/__tests__/__snapshots__/Lightbox.test.tsx.snap b/src/components/__tests__/__snapshots__/Lightbox.test.tsx.snap index 4dca15a..db1f603 100644 --- a/src/components/__tests__/__snapshots__/Lightbox.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/Lightbox.test.tsx.snap @@ -2013,48 +2013,13 @@ exports[`Lightbox Rendering With a delete button 1`] = ` } } > - - - + type="light" + />