diff --git a/src/components/AppNumPad/KeyPadButton.tsx b/src/components/AppNumPad/KeyPadButton.tsx index decf9e0b2..d34fa28d9 100644 --- a/src/components/AppNumPad/KeyPadButton.tsx +++ b/src/components/AppNumPad/KeyPadButton.tsx @@ -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'; @@ -23,35 +22,38 @@ const KeyPadButton: React.FC = ({ title, onPressNumber, keyColor, bubbleE setPressed(false); }; - return ( - - onPressNumber(title)} - style={styles.keyPadElementTouchable} - testID={`key_${title}`} - > - {bubbleEffect && ( - - )} + const button = ( + onPressNumber(title)} + style={styles.keyPadElementTouchable} + testID={`key_${title}`} + accessibilityRole="button" + accessibilityLabel={title} + > + {bubbleEffect && ( + + )} - - {title} - - - + + {title} + + ); + + // The passcode keypad already has press feedback; keep its touch target outside a second gesture. + return bubbleEffect ? button : {button}; }; const styles = StyleSheet.create({ diff --git a/src/components/AppNumPad/KeyPadView.tsx b/src/components/AppNumPad/KeyPadView.tsx index efe8d6012..ac29ca4df 100644 --- a/src/components/AppNumPad/KeyPadView.tsx +++ b/src/components/AppNumPad/KeyPadView.tsx @@ -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'; @@ -28,9 +28,10 @@ const KeyPadView: React.FC = ({ }: Props) => { const { colorMode } = useColorMode(); + // Keep keypad rows native so digit targets mount consistently in the iOS renderer. return ( - - + + onPressNumber('1')} @@ -49,8 +50,8 @@ const KeyPadView: React.FC = ({ keyColor={keyColor} bubbleEffect={bubbleEffect} /> - - + + onPressNumber('4')} @@ -69,8 +70,8 @@ const KeyPadView: React.FC = ({ keyColor={keyColor} bubbleEffect={bubbleEffect} /> - - + + onPressNumber('7')} @@ -89,9 +90,9 @@ const KeyPadView: React.FC = ({ keyColor={keyColor} bubbleEffect={bubbleEffect} /> - - - + + + {enableDecimal ? ( onPressNumber('.')} @@ -104,11 +105,11 @@ const KeyPadView: React.FC = ({ ) : ( - + - + )} - + onPressNumber('0')} @@ -123,12 +124,13 @@ const KeyPadView: React.FC = ({ > {ClearIcon ? ClearIcon : colorMode === 'dark' ? : } - - + + ); }; const styles = StyleSheet.create({ + container: { marginTop: 'auto' }, keyPadElementTouchable: { flex: 1, height: hp('8%'), diff --git a/tests/components/KeyPadView.test.tsx b/tests/components/KeyPadView.test.tsx new file mode 100644 index 000000000..b65ae638f --- /dev/null +++ b/tests/components/KeyPadView.test.tsx @@ -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( + } + /> + ); + + ['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( + } + /> + ); + 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( + } + /> + ); + expect(queryByTestId('btn-decimal')).toBeNull(); + }); +});