Skip to content

Commit

Permalink
test to check that is necessary to introduce name or surname
Browse files Browse the repository at this point in the history
  • Loading branch information
uo288574 committed Apr 23, 2024
1 parent 7404ac5 commit 9837b2e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion webapp/src/components/AddUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const AddUser = () => {

const addUser = async () => {
if (name.trim() === '' || surname.trim() === '') {
setError('Por favor, introduce tanto el nombre como los apellidos.');
setError('Por favor, introduzca tanto el nombre como los apellidos.');
} else {
if(password !== confirmPassword){
setError('Las contraseñas no coinciden.');
Expand Down
54 changes: 54 additions & 0 deletions webapp/src/components/AddUser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,60 @@ describe('AddUser component', () => {
});
});

it('try to add user but not introduce name', async () => {
render(<AddUser />);

const surnameInput = screen.getByLabelText(/Apellidos/i);
const usernameInput = screen.getByLabelText(/Usuario/i);
const passwordInput = screen.getAllByLabelText(/Contraseña/i)[0];
const confirmPasswordInput = screen.getByLabelText(/Repetir contraseña/i);
const addUserButton = document.getElementsByClassName('inner')[0]

// Mock the axios.post request to simulate a successful response
mockAxios.onPost('http://localhost:8000/adduser').reply(200);

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

// Trigger the add user button click
fireEvent.click(addUserButton);

// Wait for the Snackbar to be open
await waitFor(() => {
expect(screen.getByText(/Por favor, introduzca tanto el nombre como los apellidos./i)).toBeInTheDocument();
});
});

it('try to add user but not introduce surname', async () => {
render(<AddUser />);

const nameInput = screen.getByLabelText(/Nombre/);
const usernameInput = screen.getByLabelText(/Usuario/i);
const passwordInput = screen.getAllByLabelText(/Contraseña/i)[0];
const confirmPasswordInput = screen.getByLabelText(/Repetir contraseña/i);
const addUserButton = document.getElementsByClassName('inner')[0]

// Mock the axios.post request to simulate a successful response
mockAxios.onPost('http://localhost:8000/adduser').reply(200);

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

// Trigger the add user button click
fireEvent.click(addUserButton);

// Wait for the Snackbar to be open
await waitFor(() => {
expect(screen.getByText(/Por favor, introduzca tanto el nombre como los apellidos./i)).toBeInTheDocument();
});
});

it('try to add user but different passwords', async () => {
render(<AddUser />);

Expand Down

0 comments on commit 9837b2e

Please sign in to comment.