Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react): Hide loading spinner on CompleteResetPassword only when checks complete #15386

Merged
merged 1 commit into from
May 31, 2023
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
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