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
4 changes: 2 additions & 2 deletions packages/components/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jmstechnologiesinc/react-native-components",
"version": "0.7.0",
"version": "0.7.1",
"description": "Biblioteca de componentes de interfaz compartida por las aplicaciones de Daxir.",
"author": "yerloveraaa <yerloveraaa@gmail.com>",
"homepage": "https://github.com/jmstechnologiesinc/react-native-components#readme",
Expand Down
6 changes: 5 additions & 1 deletion packages/components/src/Form/FormPhoneNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const FormPhoneNumber = ({
showSubmitButton = true,
showPhoneNumberValidationError = true,
showPhoneVerificationCodeAgreement = true,
// The number is shown, not asked: a code sent to the number the account already has (the app's step-up). The
// field takes no typing and its flag opens no country list.
readOnly = false,
isLoading,
vereficationCodeError,
onPhoneNumberLoginPress,
Expand Down Expand Up @@ -75,8 +78,9 @@ const FormPhoneNumber = ({
error={showPhoneNumberValidationError && !value}
initialCountry="us"
initialValue={value}
disabled={readOnly}
onChangePhoneNumber={onChangeText}
onPressFlag={onFlagPress}
onPressFlag={readOnly ? undefined : onFlagPress}
/>
{showPhoneNumberValidationError && !value ? (
<HelperText type="error" padding="none" visible={true}>
Expand Down
48 changes: 48 additions & 0 deletions packages/components/src/Form/__tests__/FormPhoneNumber.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Form.PhoneNumber asks for a number by default; `readOnly` shows the one it is given (the app's step-up sends its
// code to the account's own phone): no typing, and the flag opens no country list.
jest.mock('react-native-localize', () => ({
findBestLanguageTag: jest.fn(() => ({ languageTag: 'en', isRTL: false })),
}));
jest.mock('@jmstechnologiesinc/react-native-phone-input', () => ({ PhoneInput: 'PhoneInput' }));
jest.mock('../FormVerificationCode', () => 'FormVerificationCode');
jest.mock('../CountryPicker', () => 'CountryPicker');
// The section frame alone: the package's ScreenWrapper entry also loads the camera's native modules.
jest.mock('../../ScreenWrapper', () => ({ __esModule: true, default: { Section: 'ScreenWrapper.Section' } }));

import React from 'react';
import renderer, { act } from 'react-test-renderer';

import { MD3LightTheme, Provider } from '@jmstechnologiesinc/react-native-paper';

import FormPhoneNumber from '../FormPhoneNumber';

const phoneInputOf = (props) => {
let tree;
act(() => {
tree = renderer.create(
<Provider theme={MD3LightTheme}>
<FormPhoneNumber value="+15555550100" showSubmitButton={false} onChangeText={() => {}} {...props} />
</Provider>
);
});
const { props: phoneInput } = tree.root.findByType('PhoneInput');
act(() => tree.unmount());
return phoneInput;
};

describe('Form.PhoneNumber', () => {
it('asks for the number by default: it can be typed and its country chosen', () => {
const phoneInput = phoneInputOf();

expect(phoneInput.disabled).toBe(false);
expect(typeof phoneInput.onPressFlag).toBe('function');
});

it('only shows the number when read-only', () => {
const phoneInput = phoneInputOf({ readOnly: true });

expect(phoneInput.disabled).toBe(true);
expect(phoneInput.onPressFlag).toBeUndefined();
expect(phoneInput.initialValue).toBe('+15555550100');
});
});
14 changes: 14 additions & 0 deletions packages/components/src/StripeForm/StripeFormAccountBank.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,71 @@ import React from 'react';
import { TextInput } from '@jmstechnologiesinc/react-native-paper';
import ScreenWrapper from '../ScreenWrapper';
import { localized } from '../Localization/Localization';
import { FieldErrorText, errorsOf } from '../Form/FormField';

const StripeFormAccountBank = ({
accountHolder,
bankAccountNumber,
reenterAccountNumber,
routingNumber,
inputActionHandler,
// The host's errors (`{ field, code, message }`, as the package's forms take them), each under its input. The
// form validates nothing by itself.
errors,
}) => {
const hasError = (field) => errorsOf(errors, field).length > 0;

return (
<>
<ScreenWrapper.Section>
<TextInput
mode="outlined"
label={localized('accountHolder')}
value={accountHolder}
error={hasError('accountHolder')}
autoCapitalize="words"
onChangeText={(text) => inputActionHandler('accountHolder', text)}
/>
<FieldErrorText field="accountHolder" errors={errors} />
</ScreenWrapper.Section>
<ScreenWrapper.Section>
<TextInput
mode="outlined"
label={localized('routingNumber')}
value={routingNumber}
error={hasError('routingNumber')}
autoCapitalize="none"
autoCorrect={false}
keyboardType="number-pad"
onChangeText={(text) => inputActionHandler('routingNumber', text)}
/>
<FieldErrorText field="routingNumber" errors={errors} />
</ScreenWrapper.Section>
<ScreenWrapper.Section>
<TextInput
mode="outlined"
label={localized('bankAccountNumber')}
value={bankAccountNumber}
error={hasError('bankAccountNumber')}
autoCapitalize="none"
autoCorrect={false}
keyboardType="number-pad"
onChangeText={(text) => inputActionHandler('bankAccountNumber', text)}
/>
<FieldErrorText field="bankAccountNumber" errors={errors} />
</ScreenWrapper.Section>
<ScreenWrapper.Section>
<TextInput
mode="outlined"
label={localized('re-enterAccountNumber')}
value={reenterAccountNumber}
error={hasError('reenterAccountNumber')}
autoCapitalize="none"
autoCorrect={false}
keyboardType="number-pad"
onChangeText={(text) => inputActionHandler('reenterAccountNumber', text)}
/>
<FieldErrorText field="reenterAccountNumber" errors={errors} />
</ScreenWrapper.Section>
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// StripeForm.AccountBank shows the host's errors under their inputs, as the package's forms do, and validates
// nothing by itself: without `errors` it is the form it always was.
jest.mock('react-native-localize', () => ({
findBestLanguageTag: jest.fn(() => ({ languageTag: 'en', isRTL: false })),
}));
// The section frame alone: the package's ScreenWrapper entry also loads the camera's native modules.
jest.mock('../../ScreenWrapper', () => ({ __esModule: true, default: { Section: 'ScreenWrapper.Section' } }));

import React from 'react';
import renderer, { act } from 'react-test-renderer';

import { MD3LightTheme, Provider, TextInput } from '@jmstechnologiesinc/react-native-paper';

import { setI18nConfig } from '../../Localization/Localization';
import AccountBank from '../StripeFormAccountBank';

jest.useFakeTimers();

const mounted = [];
const render = (props) => {
let tree;
act(() => {
tree = renderer.create(
<Provider theme={MD3LightTheme}>
<AccountBank inputActionHandler={() => {}} {...props} />
</Provider>
);
});
mounted.push(tree);
return tree;
};
afterEach(() => {
act(() => {
mounted.splice(0).forEach((tree) => tree.unmount());
jest.runOnlyPendingTimers();
});
});

beforeAll(() => setI18nConfig());

const inputs = (tree) => tree.root.findAllByType(TextInput);
const errorLines = (tree) => tree.root.findAll((node) => typeof node.type === 'string' && /^error\./.test(node.props.testID));

describe('StripeForm.AccountBank', () => {
it('marks no input and shows no error line without errors', () => {
const tree = render({});

expect(inputs(tree).map((input) => input.props.error)).toEqual([false, false, false, false]);
expect(errorLines(tree)).toHaveLength(0);
});

it('shows each of the host\'s errors under its own input', () => {
const tree = render({
errors: [
{ field: 'routingNumber', code: 'invalid', message: 'Nine digits.' },
{ field: 'reenterAccountNumber', code: 'mismatch', message: 'They do not match.' },
],
});

expect(inputs(tree).map((input) => input.props.error)).toEqual([false, true, false, true]);
expect(errorLines(tree).map((line) => line.props.testID)).toEqual([
'error.routingNumber',
'error.reenterAccountNumber',
]);
expect(JSON.stringify(tree.toJSON())).toContain('Nine digits.');
});
});
Loading