Skip to content

Commit

Permalink
Merge pull request #80 from Arquisoft/Uo277382
Browse files Browse the repository at this point in the history
Uo277382
  • Loading branch information
uo287998 authored Mar 27, 2024
2 parents 5a4d887 + 6aa0550 commit aafedc1
Show file tree
Hide file tree
Showing 8 changed files with 21,020 additions and 21 deletions.
495 changes: 494 additions & 1 deletion package-lock.json

Large diffs are not rendered by default.

20,465 changes: 20,463 additions & 2 deletions webapp/package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion webapp/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ function App() {
<Routes />
</AuthProvider>
</main>

);
}

Expand Down
5 changes: 2 additions & 3 deletions webapp/src/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { render, waitFor, screen } from '@testing-library/react';
test('renders primera', async() => {
render(<App />);

await waitFor(() => {
expect(true);
});
const linkElement = screen.getByText(/Saber y Ganar: El Juego/i);
expect(linkElement).toBeInTheDocument();
});
2 changes: 1 addition & 1 deletion webapp/src/components/Primera.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function Primera() {


return (
<div class="box">
<div className="box">
<Container>
<CssBaseline />
<Typography component="h1" variant="h5" align="center" sx={{ marginTop: 20 }}>
Expand Down
17 changes: 17 additions & 0 deletions webapp/src/components/login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@ const Login = () => {

const loginUser = async () => {
try {

if(username.trim().length ===0 || password.trim().length===0)
{
setError("No se permite dejar espacios en blanco");
return;
}

let res= await axios.post(`${apiEndpoint}/login`, { username, password });


// Extract data from the response
setToken(res.data.token);
console.log(res);
Expand All @@ -36,6 +44,15 @@ const Login = () => {
}
};

const checkForm = () =>
{
if(username.trim().length ===0 || password.trim().length===0)
{
setError("No se permite dejar espacios en blanco");
return;
}
};

const handleCloseSnackbar = () => {
setOpenSnackbar(false);
};
Expand Down
28 changes: 22 additions & 6 deletions webapp/src/components/register/AddUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ const AddUser = () => {
}
};

const checkForm = () =>
{
if(name.trim().length === 0 || surname.trim().length === 0 || username.trim().length === 0
|| password.trim().length === 0 || passwordRepeat.trim().length === 0)
{
setError("No se permite dejar espacios en blanco");
return;
}
if(password != passwordRepeat)
{
setError("Repita correctamente la contraseña que quiera usar");
return;
}
addUser();
};

const handleCloseSnackbar = () => {
setOpenSnackbar(false);
};
Expand All @@ -55,7 +71,7 @@ const AddUser = () => {
label="Nombre"
value={name}
onChange={(e) => setName(e.target.value)}
id = "input"
id = "name"
/>
</div>
<div className='input'>
Expand All @@ -66,7 +82,7 @@ const AddUser = () => {
label="Apellidos"
value={surname}
onChange={(e) => setSurName(e.target.value)}
id = "input"
id = "surname"
/>
</div>
<div className='input'>
Expand All @@ -77,7 +93,7 @@ const AddUser = () => {
label="Nombre de usuario"
value={username}
onChange={(e) => setUsername(e.target.value)}
id = "input"
id = "username"
/>
</div>

Expand All @@ -90,7 +106,7 @@ const AddUser = () => {
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
id = "input"
id = "password"
/>
</div>

Expand All @@ -103,12 +119,12 @@ const AddUser = () => {
type="password"
value={passwordRepeat}
onChange={(e) => setPasswordRepeat(e.target.value)}
id = "input"
id = "password2"
/>
</div>
<div className="underline"></div>
<div className='button'>
<Button variant="contained" onClick={addUser}>
<Button variant="contained" onClick={checkForm}>
Registrarse
</Button>
</div>
Expand Down
28 changes: 21 additions & 7 deletions webapp/src/components/register/AddUser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,31 @@ describe('AddUser component', () => {

it('should add user successfully', async () => {
render(<AddUser />);

/*const usernameInput = screen.getByLabelText(/Nombre de Usuario/i);
const nameInput = screen.getByLabelText(/Nombre/i);
const surnameInput = screen.getByLabelText(/Apellidos/i);
const passwordInput = screen.getByLabelText(/Contraseña/i);
const password2Input = screen.getByLabelText(/Repetir contraseña/i);*/


const usernameInput = document.getElementById("username");
const nameInput = document.getElementById("name");
const surnameInput = document.getElementById("surname");
const passwordInput = document.getElementById("password");
const password2Input = document.getElementById("password2");

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);

// Simulate user input
fireEvent.change(usernameInput, { target: { value: 'testUser' } });
fireEvent.change(passwordInput, { target: { value: 'testPassword' } });
fireEvent.change(usernameInput, { target: { value: 'testUser' } });
fireEvent.change(nameInput, { target: { value: 'testUser' } });
fireEvent.change(surnameInput, { target: { value: 'testUser' } });
fireEvent.change(passwordInput, { target: { value: 'testPassword' } });
fireEvent.change(password2Input, { target: { value: 'testPassword' } });

// Trigger the add user button click
fireEvent.click(addUserButton);
Expand All @@ -37,8 +51,8 @@ describe('AddUser component', () => {
it('should handle error when adding user', async () => {
render(<AddUser />);

const usernameInput = screen.getByLabelText(/Nombre de usuario/i);
const passwordInput = screen.getByLabelText(/Contraseña/i);
const usernameInput = document.getElementById("username");
fireEvent.change(passwordInput, { target: { value: 'testPassword' } });
const addUserButton = screen.getByRole('button', { name: /Registrarse/i });

// Mock the axios.post request to simulate an error response
Expand All @@ -53,7 +67,7 @@ describe('AddUser component', () => {

// Wait for the error Snackbar to be open
await waitFor(() => {
expect(screen.getByText(/Error: Internal Server Error/i)).toBeInTheDocument();
expect(screen.getByText(/Error: No se permite dejar espacios en blanco/i)).toBeInTheDocument();
});
});
});

0 comments on commit aafedc1

Please sign in to comment.