diff --git a/webapp/src/tests/Login.test.js b/webapp/src/tests/Login.test.js index abf22641..a2fa1a88 100644 --- a/webapp/src/tests/Login.test.js +++ b/webapp/src/tests/Login.test.js @@ -114,4 +114,20 @@ describe('Login Component', () => { expect(getByTestId('error-message')).toBeInTheDocument(); }); }); + + it('displays error message on unauthorized login attempt', async () => { + mockAxios.onPost().replyOnce(HttpStatusCode.Unauthorized); + const { getByPlaceholderText, getByTestId } = render(); + const emailInput = getByPlaceholderText('session.email'); + const passwordInput = getByPlaceholderText('session.password'); + const loginButton = getByTestId('Login'); + + fireEvent.change(emailInput, { target: { value: 'test@example.com' } }); + fireEvent.change(passwordInput, { target: { value: 'test' } }); + fireEvent.click(loginButton); + + await waitFor(() => { + expect(getByTestId('error-message')).toBeInTheDocument(); + }); + }); }); \ No newline at end of file diff --git a/webapp/src/tests/Signup.test.js b/webapp/src/tests/Signup.test.js index 550fe67a..18f91ecf 100644 --- a/webapp/src/tests/Signup.test.js +++ b/webapp/src/tests/Signup.test.js @@ -88,31 +88,35 @@ describe('Signup Component', () => { expect(confirmPasswordInput.value).toBe('newPassword'); }); - it('displays error message on failed login attempt', async () => { + it('displays error message on failed register attempt', async () => { mockAxios.onPost().replyOnce(HttpStatusCode.BadRequest); const { getByPlaceholderText, getByTestId } = render(); const emailInput = getByPlaceholderText('session.email'); const passwordInput = getByPlaceholderText('session.password'); - const loginButton = getByTestId('Sign up'); + const registerButton = getByTestId('Sign up'); fireEvent.change(emailInput, { target: { value: 'test@example.com' } }); fireEvent.change(passwordInput, { target: { value: 'password123' } }); - fireEvent.click(loginButton); + fireEvent.click(registerButton); await waitFor(() => { expect(getByTestId('error-message')).toBeInTheDocument(); }); }); - it('renders button "GoBack"', () => { - const { getByTestId } = render( - - - - - - ); - const goBackButton = getByTestId('GoBack'); - expect(goBackButton).toBeInTheDocument(); + it('displays error message on unauthorized register attempt', async () => { + mockAxios.onPost().replyOnce(HttpStatusCode.Unauthorized); + const { getByPlaceholderText, getByTestId } = render(); + const emailInput = getByPlaceholderText('session.email'); + const passwordInput = getByPlaceholderText('session.password'); + const registerButton = getByTestId('Sign up'); + + fireEvent.change(emailInput, { target: { value: 'test@example.com' } }); + fireEvent.change(passwordInput, { target: { value: 'test' } }); + fireEvent.click(registerButton); + + await waitFor(() => { + expect(getByTestId('error-message')).toBeInTheDocument(); + }); }); }); \ No newline at end of file