From 8cbdf36bddda742345a55af441d7b7dc5c90ff6c Mon Sep 17 00:00:00 2001 From: Pavel Mineev Date: Mon, 5 Apr 2021 22:54:56 +0300 Subject: [PATCH] Fix error message on token tab on login --- frontend/app/components/auth/auth.spec.tsx | 6 ++- frontend/app/components/auth/auth.tsx | 44 +++++++++------------- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/frontend/app/components/auth/auth.spec.tsx b/frontend/app/components/auth/auth.spec.tsx index d8e8051d..7f76b474 100644 --- a/frontend/app/components/auth/auth.spec.tsx +++ b/frontend/app/components/auth/auth.spec.tsx @@ -148,6 +148,7 @@ describe('', () => { expect(container.querySelector('.spinner')).toBeInTheDocument(); await waitFor(() => expect(api.emailSignin).toBeCalled()); + expect(api.emailSignin).toBeCalledWith('email@email.com', 'username'); expect(container.querySelector('.auth-back-button')).toBeInTheDocument(); expect(container.querySelector('.auth-close-button')).toBeInTheDocument(); @@ -166,7 +167,7 @@ describe('', () => { StaticStore.config.auth_providers = ['email']; jest.spyOn(api, 'emailSignin').mockImplementationOnce(async () => null); - const { container } = render(); + const { container, getByText } = render(); fireEvent.click(container.querySelector('.auth-button')!); @@ -188,6 +189,9 @@ describe('', () => { await waitFor(() => expect(utils.getTokenInvalidReason).toBeCalled()); expect(utils.getTokenInvalidReason).toBeCalledWith('token'); + + await waitFor(() => expect(getByText('Token is invalid')).toBeInTheDocument()); + expect(getByText('Token is invalid').getAttribute('class')).toContain('auth-error'); }); it('should send anonym form', async () => { diff --git a/frontend/app/components/auth/auth.tsx b/frontend/app/components/auth/auth.tsx index c9090b75..dc0cfa9e 100644 --- a/frontend/app/components/auth/auth.tsx +++ b/frontend/app/components/auth/auth.tsx @@ -103,20 +103,22 @@ const Auth: FunctionComponent = () => { const errorMessage = invalidReason !== null && invalidReason in messages ? intl.formatMessage(messages[invalidReason]) : invalidReason; const isTokenView = view === 'token'; - const submitButton = ( - + const formFooterJSX = ( + <> + errorMessage &&
{errorMessage}
+ + ); - return (
- + {formFooterJSX} ) : ( <> @@ -235,7 +227,6 @@ const Auth: FunctionComponent = () => { ))} )} -
{
)} - {errorMessage &&
{errorMessage}
} - {submitButton} + {formFooterJSX} )}