Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 31 additions & 29 deletions src/components/AppNumPad/KeyPadButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { StyleSheet, TouchableOpacity, Animated } from 'react-native';
import { StyleSheet, TouchableOpacity, Animated, Text as NativeText } from 'react-native';
import React, { useState } from 'react';
import Text from 'src/components/KeeperText';
import ScaleSpring from '../Animations/ScaleSpring';
import ThemedColor from '../ThemedColor/ThemedColor';

Expand All @@ -23,35 +22,38 @@ const KeyPadButton: React.FC<Props> = ({ title, onPressNumber, keyColor, bubbleE
setPressed(false);
};

return (
<ScaleSpring>
<TouchableOpacity
activeOpacity={1}
onPressIn={handlePressIn}
onPressOut={handlePressOut}
onPress={() => onPressNumber(title)}
style={styles.keyPadElementTouchable}
testID={`key_${title}`}
>
{bubbleEffect && (
<Animated.View
pointerEvents="none"
style={[
styles.circleEffect,
pressed && styles.circleEffectActive,
{
backgroundColor: keyPad_colors,
},
]}
/>
)}
const button = (
<TouchableOpacity
activeOpacity={1}
onPressIn={handlePressIn}
onPressOut={handlePressOut}
onPress={() => onPressNumber(title)}
style={styles.keyPadElementTouchable}
testID={`key_${title}`}
accessibilityRole="button"
accessibilityLabel={title}
>
{bubbleEffect && (
<Animated.View
pointerEvents="none"
style={[
styles.circleEffect,
pressed && styles.circleEffectActive,
{
backgroundColor: keyPad_colors,
},
]}
/>
)}

<Text style={styles.keyPadElementText} color={keyColor}>
{title}
</Text>
</TouchableOpacity>
</ScaleSpring>
<NativeText allowFontScaling={false} style={[styles.keyPadElementText, { color: keyColor }]}>
{title}
</NativeText>
</TouchableOpacity>
);

// The passcode keypad already has press feedback; keep its touch target outside a second gesture.
return bubbleEffect ? button : <ScaleSpring>{button}</ScaleSpring>;
};

const styles = StyleSheet.create({
Expand Down
34 changes: 18 additions & 16 deletions src/components/AppNumPad/KeyPadView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Box, useColorMode } from '@gluestack-ui/themed-native-base';
import { StyleSheet, TouchableOpacity } from 'react-native';
import { useColorMode } from '@gluestack-ui/themed-native-base';
import { StyleSheet, TouchableOpacity, View } from 'react-native';
import DeleteIcon from 'src/assets/images/deleteLight.svg';
import DeleteDarkIcon from 'src/assets/images/delete.svg';
import React from 'react';
Expand Down Expand Up @@ -28,9 +28,10 @@ const KeyPadView: React.FC<Props> = ({
}: Props) => {
const { colorMode } = useColorMode();

// Keep keypad rows native so digit targets mount consistently in the iOS renderer.
return (
<Box pointerEvents={disabled ? 'none' : 'auto'} mt="auto">
<Box style={styles.keyWrapperView}>
<View collapsable={false} pointerEvents={disabled ? 'none' : 'auto'} style={styles.container}>
<View collapsable={false} style={styles.keyWrapperView}>
<KeyPadButton
title="1"
onPressNumber={() => onPressNumber('1')}
Expand All @@ -49,8 +50,8 @@ const KeyPadView: React.FC<Props> = ({
keyColor={keyColor}
bubbleEffect={bubbleEffect}
/>
</Box>
<Box style={styles.keyWrapperView}>
</View>
<View collapsable={false} style={styles.keyWrapperView}>
<KeyPadButton
title="4"
onPressNumber={() => onPressNumber('4')}
Expand All @@ -69,8 +70,8 @@ const KeyPadView: React.FC<Props> = ({
keyColor={keyColor}
bubbleEffect={bubbleEffect}
/>
</Box>
<Box style={styles.keyWrapperView}>
</View>
<View collapsable={false} style={styles.keyWrapperView}>
<KeyPadButton
title="7"
onPressNumber={() => onPressNumber('7')}
Expand All @@ -89,9 +90,9 @@ const KeyPadView: React.FC<Props> = ({
keyColor={keyColor}
bubbleEffect={bubbleEffect}
/>
</Box>
<Box style={styles.keyWrapperView}>
<Box style={styles.emptyBtnView}>
</View>
<View collapsable={false} style={styles.keyWrapperView}>
<View collapsable={false} style={styles.emptyBtnView}>
{enableDecimal ? (
<TouchableOpacity
onPress={() => onPressNumber('.')}
Expand All @@ -104,11 +105,11 @@ const KeyPadView: React.FC<Props> = ({
</Text>
</TouchableOpacity>
) : (
<Box style={styles.emptyBtnView}>
<View collapsable={false} style={styles.emptyBtnView}>
<Text style={{ padding: 15 }} />
</Box>
</View>
)}
</Box>
</View>
<KeyPadButton
title="0"
onPressNumber={() => onPressNumber('0')}
Expand All @@ -123,12 +124,13 @@ const KeyPadView: React.FC<Props> = ({
>
{ClearIcon ? ClearIcon : colorMode === 'dark' ? <DeleteIcon /> : <DeleteDarkIcon />}
</TouchableOpacity>
</Box>
</Box>
</View>
</View>
);
};

const styles = StyleSheet.create({
container: { marginTop: 'auto' },
keyPadElementTouchable: {
flex: 1,
height: hp('8%'),
Expand Down
74 changes: 74 additions & 0 deletions tests/components/KeyPadView.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React from 'react';
import { fireEvent, render } from '@testing-library/react-native';
import { View } from 'react-native';
import KeyPadView from 'src/components/AppNumPad/KeyPadView';

jest.mock(
'src/components/Animations/ScaleSpring',
() =>
({ children }: React.PropsWithChildren) =>
children
);
jest.mock('src/components/ThemedColor/ThemedColor', () => jest.fn(() => '#ffffff'));

describe('authentication keypad', () => {
it('renders all ten digits and delivers digit and delete taps', () => {
const onPressNumber = jest.fn();
const onDeletePressed = jest.fn();
const { getByText, getByTestId } = render(
<KeyPadView
onPressNumber={onPressNumber}
onDeletePressed={onDeletePressed}
bubbleEffect
ClearIcon={<View />}
/>
);

['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'].forEach((digit) => {
expect(getByText(digit)).toBeTruthy();
fireEvent.press(getByTestId(`key_${digit}`));
});
fireEvent.press(getByTestId('btn_clear'));

expect(onPressNumber.mock.calls.map(([digit]) => digit)).toEqual([
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
]);
expect(onDeletePressed).toHaveBeenCalledTimes(1);
});

it('preserves decimal amount entry and delete when passcode feedback is disabled', () => {
const onPressNumber = jest.fn();
const onDeletePressed = jest.fn();
const { getByTestId, queryByTestId, rerender } = render(
<KeyPadView
onPressNumber={onPressNumber}
onDeletePressed={onDeletePressed}
enableDecimal
ClearIcon={<View />}
/>
);
fireEvent.press(getByTestId('key_1'));
fireEvent.press(getByTestId('btn-decimal'));
fireEvent.press(getByTestId('key_0'));
fireEvent.press(getByTestId('btn_clear'));
expect(onPressNumber.mock.calls.map(([value]) => value)).toEqual(['1', '.', '0']);
expect(onDeletePressed).toHaveBeenCalledTimes(1);
rerender(
<KeyPadView
onPressNumber={onPressNumber}
onDeletePressed={onDeletePressed}
ClearIcon={<View />}
/>
);
expect(queryByTestId('btn-decimal')).toBeNull();
});
});
Loading