Skip to content

Commit

Permalink
🧪: Tests finales añadidos
Browse files Browse the repository at this point in the history
  • Loading branch information
coral2742 committed May 9, 2024
1 parent d64af0d commit 243bf1f
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 30 deletions.
1 change: 0 additions & 1 deletion webapp/src/components/AddUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const AddUser = ({ onCloseSnackbar }) => {
{error && (
<Snackbar open={!!error} autoHideDuration={6000} onClose={() => setError('')} message={`Error: ${error}`} />
)}
<Footer />
</Container>
);
};
Expand Down
7 changes: 0 additions & 7 deletions webapp/src/components/AddUser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,4 @@ describe('AddUser component', () => {
});


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

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

expect(footerText).toBeInTheDocument();
});
});
4 changes: 2 additions & 2 deletions webapp/src/components/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const Login = () => {
</Button>
<Snackbar open={openSnackbar} autoHideDuration={6000} onClose={() => {setOpenSnackbar(false);}} message="Inicio de sesión exitoso" />
{error && (
<Snackbar
<Snackbar data-testid="closeButton"
open={!!error}
autoHideDuration={6000}
onClose={() => { setOpenSnackbar(true); setError('Error: Credenciales inválidas'); }}
Expand All @@ -61,7 +61,7 @@ const Login = () => {

</div>

<Footer />

</Container>
);
};
Expand Down
11 changes: 1 addition & 10 deletions webapp/src/components/Login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,6 @@ 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();
});


});
23 changes: 15 additions & 8 deletions webapp/src/components/RegisteredUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import axios from 'axios';
import React, { useState, useEffect } from 'react';
import { Container, Typography } from '@mui/material';
import Navbar from './Navbar';
import Footer from './Footer';

const RegisteredUsers = () => {
const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000';
Expand All @@ -14,6 +15,18 @@ const RegisteredUsers = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);


const formatDate = (dateString) => {
const date = new Date(dateString);
const day = date.getDate().toString().padStart(2, '0');
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const year = date.getFullYear();
const hours = date.getHours().toString().padStart(2, '0');
const minutes = date.getMinutes().toString().padStart(2, '0');

return `${day}/${month}/${year} ${hours}:${minutes}`;
};

const handleShowHistory = async () => {
try {
const response = await axios.get(`${apiEndpoint}/getregisteredusers`, {});
Expand Down Expand Up @@ -43,24 +56,18 @@ const RegisteredUsers = () => {
</tr>
</thead>
<tbody>
{/* {registeredUsers.map((row, rowIndex) => (
<tr key={rowIndex}>
{row.map((cell, cellIndex) => (
<td key={cellIndex}>{cell}</td>
))}
</tr>
))} */}
{registeredUsers.map((row, rowIndex) => (
<tr key={rowIndex}>
<td>{row[0]}</td>
<td>{row[1]}</td>
<td>{formatDate(row[1])}</td>
</tr>
))}

</tbody>
</table>
</div>
</Container>
<Footer />
</>

);
Expand Down
41 changes: 39 additions & 2 deletions webapp/src/components/RegisteredUsers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Registered Users component', () => {
});

it('muestra todos los usuarios registrados', async () => {
const user1 = ['pablo', '4/23/2024'];
const user1 = ['pablo', '2024-04-03T12:34:56Z'];
const mockUsers = [user1];
mockAxios.onGet("http://localhost:8000/getregisteredusers").reply(200, mockUsers);

Expand All @@ -25,8 +25,45 @@ describe('Registered Users component', () => {
await waitFor(() => {

expect(screen.getByText('pablo')).toBeInTheDocument();
expect(screen.getByText('4/23/2024')).toBeInTheDocument();
expect(screen.getByText('03/04/2024 14:34')).toBeInTheDocument();
});

});




it('should format dates correctly', async () => {
const mockRegisteredUsers = [
['username1', '2024-01-01T12:34:56Z'],
['username2', '2024-02-15T09:30:00Z'],
];

mockAxios.onGet('http://localhost:8000/getregisteredusers').reply(200, mockRegisteredUsers);

render(
<Router>
<RegisteredUsers />
</Router>);


await waitFor(() => {
// Check if dates are formatted correctly
expect(screen.getByText('01/01/2024 13:34')).toBeInTheDocument();
expect(screen.getByText('15/02/2024 10:30')).toBeInTheDocument();
});

});


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

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

expect(footerText).toBeInTheDocument();
});
});
2 changes: 2 additions & 0 deletions webapp/src/components/ScoreBoard.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import axios from 'axios';
import { Container, Typography, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, TablePagination } from '@mui/material';
import Navbar from './Navbar';
import './ScoreBoard.css';
import Footer from './Footer';

const ScoreBoard = () => {
const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000';
Expand Down Expand Up @@ -86,6 +87,7 @@ const ScoreBoard = () => {
/>
</div>
</Container>
<Footer />
</>
);
};
Expand Down
13 changes: 13 additions & 0 deletions webapp/src/components/ScoreBoard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,17 @@ describe('ScoreBoard component', () => {
expect(screen.getByText('Ranking de Puntuaciones')).toBeInTheDocument();
});


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

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

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

});

0 comments on commit 243bf1f

Please sign in to comment.