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

login y registro en español #67

Merged
merged 1 commit into from
Apr 28, 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
16 changes: 8 additions & 8 deletions webapp/e2e/steps/game-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ defineFeature(feature, test => {
given('An authenticated user', async () => {
username = "game1";
password = "game";
await expect(page).toClick('button', { text: 'SignUp' });
await expect(page).toClick('button', { text: 'Registrarse' });
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toClick('button', { text: 'Add User' });
await expect(page).toClick('a', { text: 'Already have an account? Login here.' });
await expect(page).toClick('button', { text: 'Registrarse' });
await expect(page).toClick('a', { text: '¿Ya tienes una cuenta? Inicia sesión aquí.' });
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toClick('button', { text: 'Login' });
await expect(page).toClick('button', { text: 'Iniciar sesión' });
});

when('I navigate to the game page and I click the correct answer', async () => {
Expand Down Expand Up @@ -65,14 +65,14 @@ defineFeature(feature, test => {
given('An authenticated user', async () => {
username = "game2";
password = "game";
await expect(page).toClick('button', { text: 'SignUp' });
await expect(page).toClick('button', { text: 'Registrarse' });
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toClick('button', { text: 'Add User' });
await expect(page).toClick('a', { text: 'Already have an account? Login here.' });
await expect(page).toClick('button', { text: 'Registrarse' });
await expect(page).toClick('a', { text: '¿Ya tienes una cuenta? Inicia sesión aquí.' });
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toClick('button', { text: 'Login' });
await expect(page).toClick('button', { text: 'Iniciar sesión' });
});

when('I navigate to the game page and I click an incorrect answer', async () => {
Expand Down
10 changes: 5 additions & 5 deletions webapp/e2e/steps/login-form.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ defineFeature(feature, test => {
given('A registered user', async () => {
username = "login1"
password = "test"
await expect(page).toClick('button', { text: 'SignUp' })
await expect(page).toClick('button', { text: 'Registrarse' })
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toClick('button', { text: 'Add User' });
await expect(page).toClick('a', { text: 'Already have an account? Login here.' });
await expect(page).toClick('button', { text: 'Login' })
await expect(page).toClick('button', { text: 'Registrarse' });
await expect(page).toClick('a', { text: '¿Ya tienes una cuenta? Inicia sesión aquí.' });
await expect(page).toClick('button', { text: 'Iniciar sesión' })
});

when('I fill the data in the form and press submit', async () => {
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toClick('button', { text: 'Login' })
await expect(page).toClick('button', { text: 'Iniciar sesión' })
});

then('Home should be shown in the screen', async () => {
Expand Down
10 changes: 5 additions & 5 deletions webapp/e2e/steps/record-button.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ defineFeature(feature, test => {
given('An authenticated user', async () => {
username = "record2";
password = "record1";
await expect(page).toClick('button', { text: 'SignUp' });
await expect(page).toClick('button', { text: 'Registrarse' });
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toClick('button', { text: 'Add User' });
await expect(page).toClick('a', { text: 'Already have an account? Login here.' });
await expect(page).toClick('button', { text: 'Login' });
await expect(page).toClick('button', { text: 'Registrarse' });
await expect(page).toClick('a', { text: '¿Ya tienes una cuenta? Inicia sesión aquí.' });
await expect(page).toClick('button', { text: 'Iniciar sesión' });
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toClick('button', { text: 'Login' });
await expect(page).toClick('button', { text: 'Iniciar sesión' });
});

when('I navigate to the records page', async () => {
Expand Down
6 changes: 3 additions & 3 deletions webapp/e2e/steps/register-form.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ defineFeature(feature, test => {
given('An unregistered user', async () => {
username = "register1"
password = "test"
await expect(page).toClick('button', { text: 'SignUp' })
await expect(page).toClick('button', { text: 'Registrarse' })
});

when('I fill the data in the form and press submit', async () => {
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toClick('button', { text: 'Add User' })
await expect(page).toClick('button', { text: 'Registrarse' })
});

then('A confirmation message should be shown in the screen', async () => {
await expect(page).toMatchElement("div", { text: "User added successfully" });
await expect(page).toMatchElement("div", { text: "Usuario añadido con éxito" });
});
})

Expand Down
12 changes: 6 additions & 6 deletions webapp/src/components/AddUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,36 @@ const AddUser = () => {
return (
<Container component="main" maxWidth="xs" sx={{ marginTop: 4 }}>
<Typography component="h1" variant="h5">
Add User
Registrarse
</Typography>
<TextField
name="username"
margin="normal"
fullWidth
label="Username"
label="Nombre de usuario"
value={username}
onChange={(e) => setUsername(e.target.value)}
/>
<TextField
name="password"
margin="normal"
fullWidth
label="Password"
label="Contraseña"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
<Button variant="contained" color="primary" onClick={addUser}>
Add User
Registrarse
</Button>

<Snackbar open={openSnackbar} autoHideDuration={6000} onClose={handleCloseSnackbar} message="User added successfully" />
<Snackbar open={openSnackbar} autoHideDuration={6000} onClose={handleCloseSnackbar} message="Usuario añadido con éxito" />
{error && (
<Snackbar open={!!error} autoHideDuration={6000} onClose={() => setError('')} message={`Error: ${error}`} />
)}
<br></br>
<Link to="/login">
Already have an account? Login here.
¿Ya tienes una cuenta? Inicia sesión aquí.
</Link>
</Container>
);
Expand Down
32 changes: 16 additions & 16 deletions webapp/src/components/AddUser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ describe('AddUser component', () => {
</BrowserRouter>
);

const usernameInput = screen.getByLabelText(/Username/i);
const passwordInput = screen.getByLabelText(/Password/i);
const addUserButton = screen.getByRole('button', { name: /Add User/i });
const usernameInput = screen.getByLabelText(/Nombre de usuario/i);
const passwordInput = screen.getByLabelText(/Contraseña/i);
const addUserButton = screen.getByRole('button', { name: /Registrarse/i });

// Mock the axios.post request to simulate a successful response
mockAxios.onPost('http://localhost:8000/adduser').reply(200);
Expand All @@ -35,7 +35,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 con éxito/i)).toBeInTheDocument();
});
});

Expand All @@ -46,9 +46,9 @@ describe('AddUser component', () => {
</BrowserRouter>
);

const usernameInput = screen.getByLabelText(/Username/i);
const passwordInput = screen.getByLabelText(/Password/i);
const addUserButton = screen.getByRole('button', { name: /Add User/i });
const usernameInput = screen.getByLabelText(/Nombre de usuario/i);
const passwordInput = screen.getByLabelText(/Contraseña/i);
const addUserButton = screen.getByRole('button', { name: /Registrarse/i });

// Mock the axios.post request to simulate an error response
mockAxios.onPost('http://localhost:8000/adduser').reply(500, { error: 'Internal Server Error' });
Expand All @@ -73,9 +73,9 @@ describe('AddUser component', () => {
</BrowserRouter>
);

const usernameInput = screen.getByLabelText(/Username/i);
const passwordInput = screen.getByLabelText(/Password/i);
const addUserButton = screen.getByRole('button', { name: /Add User/i });
const usernameInput = screen.getByLabelText(/Nombre de usuario/i);
const passwordInput = screen.getByLabelText(/Contraseña/i);
const addUserButton = screen.getByRole('button', { name: /Registrarse/i });

// Mock the axios.post request to simulate an error response
mockAxios.onPost('http://localhost:8000/adduser').reply(400, { error: 'El nombre de usuario no puede estar vacío' });
Expand All @@ -99,9 +99,9 @@ describe('AddUser component', () => {
</BrowserRouter>
);

const usernameInput = screen.getByLabelText(/Username/i);
const passwordInput = screen.getByLabelText(/Password/i);
const addUserButton = screen.getByRole('button', { name: /Add User/i });
const usernameInput = screen.getByLabelText(/Nombre de usuario/i);
const passwordInput = screen.getByLabelText(/Contraseña/i);
const addUserButton = screen.getByRole('button', { name: /Registrarse/i });

// Mock the axios.post request to simulate an error response
mockAxios.onPost('http://localhost:8000/adduser').reply(400, { error: 'La contraseña no puede estar vacía' });
Expand All @@ -126,9 +126,9 @@ describe('AddUser component', () => {
</BrowserRouter>
);

const usernameInput = screen.getByLabelText(/Username/i);
const passwordInput = screen.getByLabelText(/Password/i);
const addUserButton = screen.getByRole('button', { name: /Add User/i });
const usernameInput = screen.getByLabelText(/Nombre de usuario/i);
const passwordInput = screen.getByLabelText(/Contraseña/i);
const addUserButton = screen.getByRole('button', { name: /Registrarse/i });

// Mock the axios.post request to simulate an error response
mockAxios.onPost('http://localhost:8000/adduser').reply(400, { error: 'Este nombre de usuario está en uso' });
Expand Down
12 changes: 6 additions & 6 deletions webapp/src/components/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,36 +38,36 @@ const Login = () => {
<div>
<Container maxWidth="xs" sx={{ marginTop: 4 }}>
<Typography component="h1" variant="h5">
Login
Iniciar sesión
</Typography>
<TextField
name="username"
margin="normal"
fullWidth
label="Username"
label="Nombre de usuario"
value={username}
onChange={(e) => setUsername(e.target.value)}
/>
<TextField
name="password"
margin="normal"
fullWidth
label="Password"
label="Contraseña"
type="password"
value={password}
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" />
<Snackbar open={openSnackbar} autoHideDuration={6000} onClose={handleCloseSnackbar} message="Inicio de sesión existoso" />
{error && (
<Snackbar open={!!error} autoHideDuration={6000} onClose={() => setError('')} message={`Error: ${error}`} />
)}
<br></br>
<Link to="/adduser">
Don't have an account? Register here.
¿No tienes cuenta? Regístrate aquí.
</Link>
</Container>
</div>
Expand Down
26 changes: 13 additions & 13 deletions webapp/src/components/Login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ describe('Login component', () => {
</BrowserRouter>
);

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

// Simulamos la respuesta de la petición axios.post
mockAxios.onPost('http://localhost:8000/login').reply(200, { token: 'testToken' });
Expand All @@ -39,7 +39,7 @@ describe('Login component', () => {

// Esperamos que se muestre el SnackBar de loggin exitoso
await waitFor(() => {
expect(screen.getByText(/Login successful/i)).toBeInTheDocument();
expect(screen.getByText(/Inicio de sesión existoso/i)).toBeInTheDocument();
});

// Verificar que el token ha sido almacenado en localStorage
Expand All @@ -57,12 +57,12 @@ describe('Login component', () => {
</BrowserRouter>
);

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

// Simular que ha ocurrido un error en el login
mockAxios.onPost('http://localhost:8000/login').reply(401, { error: 'Unauthorized' });
mockAxios.onPost('http://localhost:8000/login').reply(401, { error: 'Credenciales inválidas' });

// Simulamos la entrada incorrecta de un usuario
fireEvent.change(usernameInput, { target: { value: 'testUserError' } });
Expand All @@ -73,7 +73,7 @@ describe('Login component', () => {

// Texto del Snackbar de error
await waitFor(() => {
expect(screen.getByText(/Error: Unauthorized/i)).toBeInTheDocument();
expect(screen.getByText(/Error: Credenciales inválidas/i)).toBeInTheDocument();
});

// Verificar que no hay token en localStorage
Expand All @@ -87,13 +87,13 @@ describe('Login component', () => {
<App />
</BrowserRouter>
);
const button = screen.getByRole('button', { name: /Login/i });
const button = screen.getByRole('button', { name: /Iniciar sesión/i });
fireEvent.click(button);
const logoutButton = screen.queryByRole('button', { name: /Cerrar sesión/i });
expect(logoutButton).toBeNull();
const usernameInput = screen.getByLabelText(/Username/i);
const passwordInput = screen.getByLabelText(/Password/i);
const loginButton = screen.getByRole('button', { name: /Login/i });
const usernameInput = screen.getByLabelText(/Nombre de usuario/i);
const passwordInput = screen.getByLabelText(/Contraseña/i);
const loginButton = screen.getByRole('button', { name: /Iniciar sesión/i });

mockAxios.onPost('http://localhost:8000/login').reply(200, { token: 'testToken' });

Expand Down
4 changes: 2 additions & 2 deletions webapp/src/components/Welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ const HomeScreen = () => {
<br></br>
<div className="d-flex justify-content-center">
<div className="px-2">
<button type="button" className="btn btn-outline-primary btn-lg" onClick={handleLogin}>Login</button>
<button type="button" className="btn btn-outline-primary btn-lg" onClick={handleLogin}>Iniciar sesión</button>
</div>
<div className="px-2">
<button type="button" className="btn btn-outline-primary btn-lg" onClick={handleSignUp}>SignUp</button>
<button type="button" className="btn btn-outline-primary btn-lg" onClick={handleSignUp}>Registrarse</button>
</div>
</div>
</>
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/components/Welcome.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Welcome Component', () => {
<Welcome />
</BrowserRouter>
);
const loginButton = screen.getByRole('button', { name: /login/i });
const loginButton = screen.getByRole('button', { name: /Iniciar sesión/i });
fireEvent.click(loginButton);
expect(window.location.pathname).toBe('/login');
});
Expand All @@ -34,7 +34,7 @@ describe('Welcome Component', () => {
<Welcome />
</BrowserRouter>
);
const signupButton = screen.getByRole('button', { name: /signup/i });
const signupButton = screen.getByRole('button', { name: /Registrarse/i });
fireEvent.click(signupButton);
expect(window.location.pathname).toBe('/adduser');
});
Expand Down