Skip to content

Commit

Permalink
Add pressIn handler to LargeButton component
Browse files Browse the repository at this point in the history
  • Loading branch information
SjaakSchilperoort committed Oct 25, 2023
1 parent b430184 commit 252e14d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/components/LargeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import theme from '../styles/theme'
type LargeButtonProps = {
title: string
onPress?: () => void
onPressIn?: () => void
iconName?: IconName
disabled?: boolean
secondary?: boolean
Expand Down Expand Up @@ -51,6 +52,7 @@ const LargeButton = ({
title,
iconName,
onPress,
onPressIn,
testID = 'touchable-opacity',
}: LargeButtonProps) => {
const { textStyle, buttonStyle, iconColor } = getStyle(secondary, disabled, danger)
Expand All @@ -61,6 +63,7 @@ const LargeButton = ({
style={[styles.container, style, buttonStyle]}
disabled={disabled}
onPress={onPress}
onPressIn={onPressIn}
activeOpacity={0.5}
>
<View style={styles.titleContainer}>
Expand Down
9 changes: 9 additions & 0 deletions src/components/__tests__/LargeButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { render, fireEvent } from '@testing-library/react-native'
import LargeButton from '../LargeButton'

const onPress = jest.fn()
const onPressIn = jest.fn()

describe('LargeButton', () => {
test('Rendering, enabled, primary', () => {
Expand Down Expand Up @@ -51,4 +52,12 @@ describe('LargeButton', () => {
await fireEvent.press(getByTestId('touchable-opacity'))
expect(onPress).toBeCalled()
})

test('onPressIn', async () => {
const { getByTestId } = render(
<LargeButton title="Press me" onPress={onPress} onPressIn={onPressIn} style={{ flex: 1 }} />,
)
await fireEvent(getByTestId('touchable-opacity'), 'pressIn')
expect(onPressIn).toBeCalled()
})
})

0 comments on commit 252e14d

Please sign in to comment.