Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Neuteboom committed Jul 1, 2024
1 parent d42e9af commit 2956801
Show file tree
Hide file tree
Showing 4 changed files with 458 additions and 12 deletions.
6 changes: 2 additions & 4 deletions src/components/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@ export type IconAppearanceProps = {
color?: string
size?: number
testID?: string
rotation?: number
}

export type IconProps = IconAppearanceProps & {
name: IconName
}

export const Icon = ({ name, color, size, testID, style, rotation }: IconProps): JSX.Element => {
export const Icon = ({ name, color, size, testID, style }: IconProps): JSX.Element => {
const iconStyle = style ?? 'light'
const icon = iconStyle === 'light' ? Icons[name].light : Icons[name].solid
const iconColor = color ?? theme.color.primary
const iconSize = size ?? theme.icon.size.large
const transform = rotation ? { rotate: rotation } : undefined

return <FontAwesomeIcon icon={icon} color={iconColor} size={iconSize} testID={testID} transform={transform} />
return <FontAwesomeIcon icon={icon} color={iconColor} size={iconSize} testID={testID} />
}
21 changes: 21 additions & 0 deletions src/components/__tests__/Lightbox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ describe('Lightbox', () => {
expect(queryByTestId('delete-photo')).not.toBeNull()
expect(toJSON()).toMatchSnapshot()
})

test('With a crop button', () => {
const { toJSON, queryByTestId } = render(
<Lightbox photos={photos} index={0} onClose={onClose} onCrop={() => {}} />,
)

expect(queryByTestId('crop-photo')).not.toBeNull()
expect(toJSON()).toMatchSnapshot()
})
})

describe('Interaction', () => {
Expand All @@ -103,6 +112,18 @@ describe('Lightbox', () => {
expect(onDelete).toHaveBeenCalledWith(0)
})

test('Press crop button calls onCrop', async () => {
// GIVEN
const onCrop = jest.fn()
const { getByTestId } = render(<Lightbox photos={photos} index={0} onClose={onClose} onCrop={onCrop} />)

// WHEN
await fireEvent.press(getByTestId('crop-photo'))

// THEN
expect(onCrop).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')
Expand Down
Loading

0 comments on commit 2956801

Please sign in to comment.