import React from 'react';
import { fireEvent, render } from '@testing-library/react-native';
import { authenticatorTextUtil } from '@aws-amplify/ui';
import { ConfirmSignUp } from '..';
const props = {
codeDeliveryDetails: {
AttributeName: 'email',
DeliveryMedium: 'EMAIL',
Destination: 'a***@e***.com',
},
fields: [],
Footer: ConfirmSignUp.Footer,
FormFields: ConfirmSignUp.FormFields,
handleBlur: jest.fn(),
handleChange: jest.fn(),
handleSubmit: jest.fn(),
hasValidationErrors: false,
Header: ConfirmSignUp.Header,
isPending: false,
resendCode: jest.fn(),
socialProviders: undefined,
};
const { getConfirmingText, getDeliveryMethodText, getResendCodeText } =
authenticatorTextUtil;
describe('ConfirmSignUp', () => {
it('renders as expected', () => {
const { toJSON } = render();
expect(toJSON()).toMatchSnapshot();
expect(getDeliveryMethodText(props.codeDeliveryDetails)).toBeDefined();
});
it('resends the code', () => {
const { getByText } = render();
const button = getByText(getResendCodeText());
fireEvent.press(button);
expect(props.resendCode).toHaveBeenCalledTimes(1);
});
it('renders as expected with an error', () => {
const error = 'An error!';
const { getByRole, getByText, toJSON } = render(
);
expect(toJSON()).toMatchSnapshot();
expect(getByRole('alert')).toBeDefined();
expect(getByText(error)).toBeDefined();
});
it('renders as expected when isPending is true', () => {
const { toJSON, getByText } = render(
);
expect(toJSON()).toMatchSnapshot();
expect(getByText(getConfirmingText())).toBeDefined();
});
});