Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paso a dev el cambio de idioma y el formateo de fechas #183

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions webapp/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ function App() {


<Link name="gotoregister" component="button" variant="body2" onClick={handleToggleView}>
Don't have an account? Register here.
¿No tienes cuenta? Registrate aqui.
</Link>
) : (
<Link component="button" variant="body2" onClick={handleToggleView}>
Already have an account? Login here.
¿Ya tienes cuenta? Inicia sesión aqui.
</Link>
)}
</Typography>
Expand Down
6 changes: 3 additions & 3 deletions webapp/src/components/AddUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const AddUser = () => {
return (
<Container component="main" maxWidth="lg" sx={{ marginTop: 4 }}>
<Typography component="h1" variant="h5">
Add User
Añadir usuario
</Typography>
<TextField
name="username"
Expand All @@ -47,9 +47,9 @@ const AddUser = () => {
onChange={(e) => setPassword(e.target.value)}
/>
<Button variant="contained" color="primary" onClick={addUser}>
Add User
Añadir usuario
</Button>
<Snackbar open={openSnackbar} autoHideDuration={6000} onClose={handleCloseSnackbar} message="User added successfully" />
<Snackbar open={openSnackbar} autoHideDuration={6000} onClose={handleCloseSnackbar} message="Usuario añadido correctamente" />
{error && (
<Snackbar open={!!error} autoHideDuration={6000} onClose={() => setError('')} message={`Error: ${error}`} />
)}
Expand Down
6 changes: 3 additions & 3 deletions webapp/src/components/AddUser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('AddUser component', () => {

const usernameInput = screen.getByLabelText(/Username/i);
const passwordInput = screen.getByLabelText(/Password/i);
const addUserButton = screen.getByRole('button', { name: /Add User/i });
const addUserButton = screen.getByRole('button', { name: /Añadir usuario/i });

// Mock the axios.post request to simulate a successful response
mockAxios.onPost('http://localhost:8000/adduser').reply(200);
Expand All @@ -30,7 +30,7 @@ describe('AddUser component', () => {

// Wait for the Snackbar to be open
await waitFor(() => {
expect(screen.getByText(/User added successfully/i)).toBeInTheDocument();
expect(screen.getByText(/Usuario añadido correctamente/i)).toBeInTheDocument();
});
});

Expand All @@ -39,7 +39,7 @@ describe('AddUser component', () => {

const usernameInput = screen.getByLabelText(/Username/i);
const passwordInput = screen.getByLabelText(/Password/i);
const addUserButton = screen.getByRole('button', { name: /Add User/i });
const addUserButton = screen.getByRole('button', { name: /Añadir usuario/i });

// Mock the axios.post request to simulate an error response
mockAxios.onPost('http://localhost:8000/adduser').reply(500, { error: 'Internal Server Error' });
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/GeneratedQuestionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const GeneratedQuestionsList = () => {

return (
<div>
<h2>Questions List</h2>
<h2>Lista de preguntas</h2>
<table style={{ borderCollapse: 'collapse', width: '100%' }}>
<thead>
<tr style={{ border: '1px solid #ddd', padding: '8px', backgroundColor: '#f2f2f2' }}>
Expand Down
8 changes: 4 additions & 4 deletions webapp/src/components/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ const Login = ({setLogged}) => {

<div>
<Typography component="h1" variant="h5" sx={{ textAlign: 'center' }}>
Hello {username}!
Hola {username}!
</Typography>
<Typography component="p" variant="body1" sx={{ textAlign: 'center', marginTop: 2 }}>
Your account was created on {new Date(createdAt).toLocaleDateString()}.
Tu cuenta fue creada el {new Date(createdAt).toLocaleDateString()}.
</Typography>
<Button variant="contained" color="secondary" onClick={handleShowGame}>
Comenzar a jugar
Expand All @@ -148,7 +148,7 @@ const Login = ({setLogged}) => {
) : (
<div>
<Typography component="h1" variant="h5">
Login
Iniciar sesión
</Typography>
<TextField
margin="normal"
Expand All @@ -166,7 +166,7 @@ const Login = ({setLogged}) => {
onChange={(e) => setPassword(e.target.value)}
/>
<Button variant="contained" color="primary" onClick={loginUser}>
Login
Iniciar sesión
</Button>
<Snackbar open={openSnackbar} autoHideDuration={6000} onClose={handleCloseSnackbar} message="Login successful" />
{error && (
Expand Down
12 changes: 6 additions & 6 deletions webapp/src/components/Login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('Login component', () => {

const usernameInput = screen.getByLabelText(/Username/i);
const passwordInput = screen.getByLabelText(/Password/i);
const loginButton = screen.getByRole('button', { name: /Login/i });
const loginButton = screen.getByRole('button', { name: /Iniciar sesión/i });

// Mock the axios.post request to simulate a successful response
mockAxios.onPost('http://localhost:8000/login').reply(200, { createdAt: '2024-01-01T12:34:56Z' });
Expand All @@ -29,16 +29,16 @@ describe('Login component', () => {
});

// Verify that the user information is displayed
expect(screen.getByText(/Hello testUser!/i)).toBeInTheDocument();
expect(screen.getByText(/Your account was created on 1\/1\/2024/i)).toBeInTheDocument();
expect(screen.getByText(/Hola testUser!/i)).toBeInTheDocument();
expect(screen.getByText(/Tu cuenta fue creada el 1\/1\/2024/i)).toBeInTheDocument();
});

it('should handle error when logging in', async () => {
render(<Login />);

const usernameInput = screen.getByLabelText(/Username/i);
const passwordInput = screen.getByLabelText(/Password/i);
const loginButton = screen.getByRole('button', { name: /Login/i });
const loginButton = screen.getByRole('button', { name: /Iniciar sesión/i });

// Mock the axios.post request to simulate an error response
mockAxios.onPost('http://localhost:8000/login').reply(401, { error: 'Unauthorized' });
Expand All @@ -56,7 +56,7 @@ describe('Login component', () => {
});

// Verify that the user information is not displayed
expect(screen.queryByText(/Hello testUser!/i)).toBeNull();
expect(screen.queryByText(/Your account was created on/i)).toBeNull();
expect(screen.queryByText(/Hola testUser!/i)).toBeNull();
expect(screen.queryByText(/Tu cuenta fue creada el/i)).toBeNull();
});
});
15 changes: 9 additions & 6 deletions webapp/src/components/RecordList.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ const RecordList = ({ username }) => {
const response = await axios.get(`${apiEndpoint}/getRecords/${username}`);

if (response.status === 200) {
const userRecords = response.data;
const userRecords = response.data.map(record => ({
...record,
date: new Date(record.date).toLocaleString(),
}));
setListRecords(userRecords);
} else {
console.error('Error obtaining the user records list');
Expand All @@ -30,11 +33,11 @@ const RecordList = ({ username }) => {
<table style={{ borderCollapse: 'collapse', width: '100%' }}>
<thead>
<tr style={{ border: '1px solid #ddd', padding: '8px', backgroundColor: '#f2f2f2' }}>
<th>Date</th>
<th>Time (seconds)</th>
<th>Money Earned</th>
<th>Correct Questions</th>
<th>Failed Questions</th>
<th>Fecha</th>
<th>Tiempo (segundos)</th>
<th>Dinero conseguido</th>
<th>Respuestas correctas</th>
<th>Respuestas falladas</th>
</tr>
</thead>
<tbody>
Expand Down
8 changes: 5 additions & 3 deletions webapp/src/components/UsersList.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ const UsersList = () => {

const response = await axios.get(`${apiEndpoint}/getAllUsers`);
if (response.status === 200) {

const uList = response.data;
const uList = response.data.map(record => ({
...record,
createdAt: new Date(record.createdAt).toLocaleString(),
}));
setListUsers(uList);

} else {
Expand Down Expand Up @@ -56,7 +58,7 @@ const UsersList = () => {

return (
<div>
<h2>Users List</h2>
<h2>Lista de usuarios</h2>
<table style={{ borderCollapse: 'collapse', width: '100%' }}>
<thead>
<tr style={{ border: '1px solid #ddd', padding: '8px', backgroundColor: '#f2f2f2' }}>
Expand Down
Loading