From dbe67ff50b1af51d4fa3701badf7a920320ef70d Mon Sep 17 00:00:00 2001 From: sergiorodriguezgarcia <113514397+sergiorodriguezgarcia@users.noreply.github.com> Date: Tue, 23 Apr 2024 16:16:27 +0200 Subject: [PATCH] feat: Adding more tests for the Login page --- webapp/src/tests/Login.test.js | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/webapp/src/tests/Login.test.js b/webapp/src/tests/Login.test.js index 84459963..abf22641 100644 --- a/webapp/src/tests/Login.test.js +++ b/webapp/src/tests/Login.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { render, fireEvent, waitFor, act } from '@testing-library/react'; +import { render, fireEvent, waitFor } from '@testing-library/react'; import '@testing-library/jest-dom/extend-expect'; import { MemoryRouter } from 'react-router'; import Login from '../pages/Login'; @@ -8,7 +8,6 @@ import MockAdapter from 'axios-mock-adapter'; import { HttpStatusCode } from 'axios'; import { ChakraProvider } from '@chakra-ui/react'; import theme from '../styles/theme'; -import Signup from 'pages/Signup'; jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), @@ -87,4 +86,32 @@ describe('Login Component', () => { expect(getByTestId('error-message')).toBeInTheDocument(); }); }); + + it('renders button "GoBack"', () => { + const { getByTestId } = render( + + + + + + ); + const goBackButton = getByTestId('GoBack'); + expect(goBackButton).toBeInTheDocument(); + }); + + it('displays error message on failed format login attempt', async () => { + mockAxios.onPost().replyOnce(HttpStatusCode.BadRequest); + const { getByPlaceholderText, getByTestId } = render(); + const emailInput = getByPlaceholderText('session.email'); + const passwordInput = getByPlaceholderText('session.password'); + const loginButton = getByTestId('Login'); + + fireEvent.change(emailInput, { target: { value: 'test' } }); + fireEvent.change(passwordInput, { target: { value: 'test' } }); + fireEvent.click(loginButton); + + await waitFor(() => { + expect(getByTestId('error-message')).toBeInTheDocument(); + }); + }); }); \ No newline at end of file