Skip to content

Commit

Permalink
🧪: Tests login y adduser modificados
Browse files Browse the repository at this point in the history
  • Loading branch information
coral2742 committed May 9, 2024
1 parent dc08581 commit d64af0d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions webapp/src/components/AddUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState } from 'react';
import axios from 'axios';
import { Container, Typography, TextField, Button, Snackbar } from '@mui/material';
import { useNavigate } from 'react-router-dom';
import Footer from './Footer';

const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000';

Expand Down Expand Up @@ -58,6 +59,7 @@ const AddUser = ({ onCloseSnackbar }) => {
{error && (
<Snackbar open={!!error} autoHideDuration={6000} onClose={() => setError('')} message={`Error: ${error}`} />
)}
<Footer />
</Container>
);
};
Expand Down
15 changes: 15 additions & 0 deletions webapp/src/components/AddUser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ describe('AddUser component', () => {
await waitFor(() => {
expect(screen.getByText(/Usuario añadido correctamente/i)).toBeInTheDocument();
});

await waitFor(() => {
expect(window.location.pathname).toBe('/');
});


});

it('should display error Snackbar with autoHideDuration', async () => {
Expand All @@ -95,4 +101,13 @@ describe('AddUser component', () => {
expect(screen.getByText(/Error: Error al crear usuario/i)).toBeInTheDocument();
});
});


it('comprobar footer', async () => {
renderAddUserComponent();

const footerText = screen.getByText(/© \d{4} Hecho con ❤️ por/);

expect(footerText).toBeInTheDocument();
});
});
3 changes: 3 additions & 0 deletions webapp/src/components/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState } from 'react';
import axios from 'axios';
import { Container, Typography, TextField, Button, Snackbar } from '@mui/material';
import { useNavigate } from 'react-router-dom';
import Footer from './Footer';

const Login = () => {
const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000';
Expand Down Expand Up @@ -59,6 +60,8 @@ const Login = () => {
)}

</div>

<Footer />
</Container>
);
};
Expand Down
11 changes: 11 additions & 0 deletions webapp/src/components/Login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,15 @@ describe('Login component', () => {
expect(history.location.pathname).toBe('/');
});

it('comprobar footer', async () => {
render(
<Router>
<Login />
</Router>);

const footerText = screen.getByText(/© \d{4} Hecho con ❤️ por/);

expect(footerText).toBeInTheDocument();
});

});

0 comments on commit d64af0d

Please sign in to comment.