Skip to content
Merged
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
56 changes: 56 additions & 0 deletions app/containers/Passcode/Base/Base.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React, { useRef } from 'react';
import { View } from 'react-native';

import Base, { type IBase } from '.';
import { TYPE } from '../constants';

export default {
title: 'Passcode/Base'
};

const PasscodeBase = ({ ...props }) => {
const ref = useRef<IBase>(null);
return <Base ref={ref} type={TYPE.CHOOSE} title='Create Passcode' onEndProcess={() => {}} {...props} />;
};
Comment thread
Rohit3523 marked this conversation as resolved.

export const ChooseType = () => (
<View style={{ flex: 1 }}>
<PasscodeBase type={TYPE.CHOOSE} title='Create Passcode' />
</View>
);

export const ConfirmType = () => (
<View style={{ flex: 1 }}>
<PasscodeBase type={TYPE.CONFIRM} title='Confirm Passcode' previousPasscode='123456' onError={() => {}} />
</View>
);

export const EnterType = () => (
<View style={{ flex: 1 }}>
<PasscodeBase type={TYPE.ENTER} title='Enter Passcode' />
</View>
);

export const WithSubtitle = () => (
<View style={{ flex: 1 }}>
<PasscodeBase type={TYPE.CHOOSE} title='Create Passcode' subtitle='This passcode will protect your data' />
</View>
);

export const WithBiometry = () => (
<View style={{ flex: 1 }}>
<PasscodeBase type={TYPE.ENTER} title='Enter Passcode' showBiometry onBiometryPress={() => {}} />
</View>
);

export const EnterWithSubtitleAndBiometry = () => (
<View style={{ flex: 1 }}>
<PasscodeBase
type={TYPE.ENTER}
title='Unlock App'
subtitle='Authentication required'
showBiometry
onBiometryPress={() => {}}
/>
</View>
);
60 changes: 60 additions & 0 deletions app/containers/Passcode/Base/Base.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React, { createRef } from 'react';
import { render } from '@testing-library/react-native';

import { generateSnapshots } from '../../../../.rnstorybook/generateSnapshots';
import Base, { type IBase } from '.';
import { TYPE } from '../constants';
import * as stories from './Base.stories';

const onEndProcessMock = jest.fn();

const TestBase = ({ ...props }) => {
const ref = createRef<IBase>();
return <Base ref={ref} type={TYPE.ENTER} title='Test Title' onEndProcess={onEndProcessMock} {...props} />;
};

describe('Base Passcode Component', () => {
beforeEach(() => {
onEndProcessMock.mockClear();
});

test('should render with title', () => {
const { getByText } = render(<TestBase title='Enter Passcode' />);
expect(getByText('Enter Passcode')).toBeTruthy();
});

test('should render with subtitle when provided', () => {
const { getByText } = render(<TestBase title='Enter Passcode' subtitle='Authentication required' />);
expect(getByText('Authentication required')).toBeTruthy();
});

test('should not render subtitle when not provided', () => {
const { queryByText } = render(<TestBase title='Enter Passcode' />);
expect(queryByText('Authentication required')).toBeNull();
});

test('should expose ref methods', () => {
const ref = createRef<IBase>();
render(<Base ref={ref} type={TYPE.ENTER} title='Enter Passcode' onEndProcess={onEndProcessMock} />);
expect(ref.current?.clearPasscode).toBeDefined();
expect(ref.current?.wrongPasscode).toBeDefined();
expect(ref.current?.animate).toBeDefined();
});

test('should render biometry button when showBiometry is true', () => {
const { getByTestId } = render(<TestBase type={TYPE.ENTER} title='Enter Passcode' showBiometry onBiometryPress={() => {}} />);
expect(getByTestId('biometry-button')).toBeTruthy();
});

test('should render all passcode buttons with testIDs', () => {
const { getByTestId } = render(<TestBase type={TYPE.ENTER} title='Enter Passcode' />);
// Number buttons 0-9
for (let i = 0; i <= 9; i++) {
expect(getByTestId(`passcode-button-${i}`)).toBeTruthy();
}
// backspace button
expect(getByTestId('passcode-button-backspace')).toBeTruthy();
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
});

generateSnapshots(stories);
4 changes: 3 additions & 1 deletion app/containers/Passcode/Base/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ interface IPasscodeButton {
disabled?: boolean;
onPress?: Function;
style?: StyleProp<ViewStyle>;
testID?: string;
}

const Button = React.memo(({ style, text, disabled, onPress, icon }: IPasscodeButton) => {
const Button = React.memo(({ style, text, disabled, onPress, icon, testID }: IPasscodeButton) => {
const { colors } = useTheme();

const press = () => onPress && onPress(text);

return (
<Touch
testID={testID}
style={[styles.buttonView, { backgroundColor: 'transparent' }, style]}
underlayColor={colors.buttonBackgroundSecondaryDefault}
rippleColor={colors.buttonBackgroundSecondaryPress}
Expand Down
Loading
Loading