Skip to content

Commit

Permalink
fix(react): Hide loading spinner on CompleteResetPassword only when c…
Browse files Browse the repository at this point in the history
…hecks complete

Because:
* Users with a recovery key see a flash of CompleteResetPassword before being redirected to AccountRecoveryConfirmKey

This commit:
* Adjusts the loading spinner state to only hide when recovery key checks have completed

Fixes FXA-7170
  • Loading branch information
LZoog committed May 26, 2023
1 parent e306d68 commit 9aaa39f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ describe('CompleteResetPassword page', () => {
jest.clearAllMocks();
});

it('renders the component as expected', () => {
it('renders the component as expected', async () => {
renderSubject(account);
// testAllL10n(screen, bundle);

screen.getByRole('heading', {
await screen.findByRole('heading', {
name: 'Create new password',
});
screen.getByLabelText('New password');
Expand All @@ -112,7 +112,9 @@ describe('CompleteResetPassword page', () => {
it('displays password requirements when the new password field is in focus', async () => {
renderSubject(account);

const newPasswordField = screen.getByTestId('new-password-input-field');
const newPasswordField = await screen.findByTestId(
'new-password-input-field'
);

expect(screen.queryByText('Password requirements')).not.toBeInTheDocument();

Expand Down Expand Up @@ -192,8 +194,10 @@ describe('CompleteResetPassword page', () => {

renderSubject(account);

fireEvent.input(screen.getByTestId('new-password-input-field'), {
target: { value: PASSWORD },
await waitFor(() => {
fireEvent.input(screen.getByTestId('new-password-input-field'), {
target: { value: PASSWORD },
});
});

fireEvent.input(screen.getByTestId('verify-password-input-field'), {
Expand Down Expand Up @@ -246,7 +250,7 @@ describe('CompleteResetPassword page', () => {
hasRecoveryKey: jest.fn().mockResolvedValue(true),
} as unknown as Account;

it('redirects as expected', () => {
it('redirects as expected', async () => {
account = {
resetPasswordStatus: jest.fn().mockResolvedValue(true),
completeResetPassword: jest.fn().mockResolvedValue(true),
Expand All @@ -255,6 +259,8 @@ describe('CompleteResetPassword page', () => {

renderSubject(account);

screen.getByLabelText('Loading…');

expect(account.hasRecoveryKey).toHaveBeenCalledWith(
mockCompleteResetPasswordParams.email
);
Expand Down Expand Up @@ -285,8 +291,10 @@ describe('CompleteResetPassword page', () => {

describe('can submit', () => {
async function enterPasswordAndSubmit() {
fireEvent.input(screen.getByTestId('new-password-input-field'), {
target: { value: PASSWORD },
await waitFor(() => {
fireEvent.input(screen.getByTestId('new-password-input-field'), {
target: { value: PASSWORD },
});
});
fireEvent.input(screen.getByTestId('verify-password-input-field'), {
target: { value: PASSWORD },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,14 @@ const CompleteResetPassword = ({
}
};

if (!location.state?.lostRecoveryKey) {
checkForRecoveryKeyAndNavigate(params.email);
}
const handleRecoveryKeyStatus = async () => {
if (!location.state?.lostRecoveryKey) {
await checkForRecoveryKeyAndNavigate(params.email);
}
setShowLoadingSpinner(false);
};

setShowLoadingSpinner(false);
handleRecoveryKeyStatus();
}, [
account,
navigate,
Expand All @@ -142,8 +145,6 @@ const CompleteResetPassword = ({
};

checkPasswordForgotToken(params.token);

setShowLoadingSpinner(false);
}, [params.token, account, setLinkStatus]);

const alertSuccessAndNavigate = useCallback(() => {
Expand Down

0 comments on commit 9aaa39f

Please sign in to comment.