Skip to content

Commit

Permalink
fix(clerk-js): Add full stop if needed in password feedback messages
Browse files Browse the repository at this point in the history
fix(clerk-js): Fix falling tests

fix(clerk-js): Fix falling tests
  • Loading branch information
raptisj committed Jul 14, 2023
1 parent b26fe80 commit f94096f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ describe('SignInFactorOne', () => {
const { userEvent } = render(<SignInFactorOne />, { wrapper });
await userEvent.type(screen.getByLabelText('Password'), '123456');
await userEvent.click(screen.getByText('Continue'));
await waitFor(() => expect(screen.getByText('Incorrect Password')).toBeDefined());
await waitFor(() => expect(screen.getByText('Incorrect Password.')).toBeDefined());
});
});
});
Expand Down Expand Up @@ -402,7 +402,7 @@ describe('SignInFactorOne', () => {
await runFakeTimers(async () => {
const { userEvent } = render(<SignInFactorOne />, { wrapper });
await userEvent.type(screen.getByLabelText(/Enter verification code/i), '123456');
await waitFor(() => expect(screen.getByText('Incorrect code')).toBeDefined());
await waitFor(() => expect(screen.getByText('Incorrect code.')).toBeDefined());
});
});
});
Expand Down Expand Up @@ -481,7 +481,7 @@ describe('SignInFactorOne', () => {
await runFakeTimers(async () => {
const { userEvent } = render(<SignInFactorOne />, { wrapper });
await userEvent.type(screen.getByLabelText(/Enter verification code/i), '123456');
await waitFor(() => expect(screen.getByText('Incorrect phone code')).toBeDefined());
await waitFor(() => expect(screen.getByText('Incorrect phone code.')).toBeDefined());
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ describe('SignInFactorTwo', () => {
await runFakeTimers(async () => {
const { userEvent } = render(<SignInFactorTwo />, { wrapper });
await userEvent.type(screen.getByLabelText(/Enter verification code/i), '123456');
await waitFor(() => expect(screen.getByText('Incorrect phone code')).toBeDefined());
await waitFor(() => expect(screen.getByText('Incorrect phone code.')).toBeDefined());
});
}, 10000);
});
Expand Down Expand Up @@ -255,7 +255,7 @@ describe('SignInFactorTwo', () => {
await runFakeTimers(async () => {
const { userEvent } = render(<SignInFactorTwo />, { wrapper });
await userEvent.type(screen.getByLabelText(/Enter verification code/i), '123456');
await waitFor(() => expect(screen.getByText('Incorrect authenticator code')).toBeDefined());
await waitFor(() => expect(screen.getByText('Incorrect authenticator code.')).toBeDefined());
});
}, 10000);
});
Expand Down Expand Up @@ -346,7 +346,7 @@ describe('SignInFactorTwo', () => {
const { userEvent, getByLabelText, getByText } = render(<SignInFactorTwo />, { wrapper });
await userEvent.type(getByLabelText('Backup code'), '123456');
await userEvent.click(getByText('Continue'));
await waitFor(() => expect(screen.getByText('Incorrect backup code')).toBeDefined());
await waitFor(() => expect(screen.getByText('Incorrect backup code.')).toBeDefined());
});
}, 10000);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ describe('PasswordPage', () => {
screen.getByText(/or more/i);
});
});
}, 10000);
});

it('results in error if the passwords do not match and persists', async () => {
const { wrapper } = await createFixtures(initConfig);
Expand Down
18 changes: 13 additions & 5 deletions packages/clerk-js/src/ui/elements/FormControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ const useCalculateErrorTextHeight = (config: CalculateConfigProps) => {
};
};

const addFullStop = (string: string | undefined) => {
if (!string) {
return '';
}
const hasFullStop = string?.split(' ').slice(-1)[0].includes('.') || '';
return hasFullStop ? string : string + '.';
};

type FormFeedbackDescriptorsKeys = 'error' | 'warning' | 'info' | 'success';

type FormFeedbackProps = Partial<ReturnType<typeof useFormControlFeedback>['debounced'] & { id: FieldId }> & {
Expand All @@ -137,7 +145,7 @@ export const FormFeedback = (props: FormFeedbackProps) => {
const messageToDisplay = informationMessage || successMessage || errorMessage || warningMessage;
const isSomeMessageVisible = !!messageToDisplay;

const { calculateHeight, height } = useCalculateErrorTextHeight({ recalculate: warningMessage });
const { calculateHeight, height } = useCalculateErrorTextHeight({ recalculate: warningMessage || errorMessage });
const { getFormTextAnimation } = useFormTextAnimation();
const defaultElementDescriptors = {
error: descriptors.formFieldErrorText,
Expand Down Expand Up @@ -176,7 +184,7 @@ export const FormFeedback = (props: FormFeedbackProps) => {
ref={calculateHeight}
sx={getFormTextAnimation(!!props.informationText && !props?.successfulText && !props.warningText)}
>
{informationMessage}
{addFullStop(informationMessage)}
</FormInfoText>
)}
{/* Display the error message after the directions is unmounted*/}
Expand All @@ -186,7 +194,7 @@ export const FormFeedback = (props: FormFeedbackProps) => {
ref={calculateHeight}
sx={getFormTextAnimation(!!props?.errorText)}
>
{errorMessage}
{addFullStop(errorMessage)}
</FormErrorText>
)}

Expand All @@ -197,7 +205,7 @@ export const FormFeedback = (props: FormFeedbackProps) => {
ref={calculateHeight}
sx={getFormTextAnimation(!!props?.successfulText)}
>
{successMessage}
{addFullStop(successMessage)}
</FormSuccessText>
)}

Expand All @@ -207,7 +215,7 @@ export const FormFeedback = (props: FormFeedbackProps) => {
ref={calculateHeight}
sx={getFormTextAnimation(!!props.warningText)}
>
{warningMessage}
{addFullStop(warningMessage)}
</FormWarningText>
)}
</Box>
Expand Down

0 comments on commit f94096f

Please sign in to comment.