Skip to content

Commit

Permalink
feat: Adding more tests for the Login page
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiorodriguezgarcia committed Apr 23, 2024
1 parent a502223 commit dbe67ff
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions webapp/src/tests/Login.test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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'),
Expand Down Expand Up @@ -87,4 +86,32 @@ describe('Login Component', () => {
expect(getByTestId('error-message')).toBeInTheDocument();
});
});

it('renders button "GoBack"', () => {
const { getByTestId } = render(
<ChakraProvider theme={theme}>
<MemoryRouter initialEntries={['/signup']}>
<Login />
</MemoryRouter>
</ChakraProvider>
);
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(<ChakraProvider theme={theme}><MemoryRouter><Login /></MemoryRouter></ChakraProvider>);
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();
});
});
});

0 comments on commit dbe67ff

Please sign in to comment.