Skip to content

Commit

Permalink
Merge pull request #60 from Arquisoft/PruebaConjunto
Browse files Browse the repository at this point in the history
Prueba conjunto
  • Loading branch information
uo283182 authored Apr 22, 2024
2 parents 8d0895a + 40a9005 commit 3fd1538
Show file tree
Hide file tree
Showing 8 changed files with 433 additions and 5 deletions.
173 changes: 173 additions & 0 deletions webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"axios": "^1.6.5",
"bootstrap": "^5.3.3",
"history": "^5.3.0",
"jsonwebtoken": "^9.0.2",
"jwt-decode": "^4.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down Expand Up @@ -58,4 +59,4 @@
"serve": "^14.2.1",
"start-server-and-test": "^2.0.3"
}
}
}
2 changes: 1 addition & 1 deletion webapp/src/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import App from './App';

describe('App component', () => {

it('renders learn react link',async () => {
it('should show the nav var and the logout button',async () => {
render(
<BrowserRouter>
<App/>
Expand Down
80 changes: 80 additions & 0 deletions webapp/src/components/AddUser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,84 @@ describe('AddUser component', () => {
expect(screen.getByText(/Error: Internal Server Error/i)).toBeInTheDocument();
});
});

it('should handle error when adding user with empty username', async () => {
render(
<BrowserRouter>
<AddUser />
</BrowserRouter>
);

const usernameInput = screen.getByLabelText(/Username/i);
const passwordInput = screen.getByLabelText(/Password/i);
const addUserButton = screen.getByRole('button', { name: /Add User/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' });

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

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

// Wait for the error Snackbar to be open
await waitFor(() => {
expect(screen.getByText(/Error: El nombre de usuario no puede estar vacío/i)).toBeInTheDocument();
});
});
it('should handle error when adding user with empty password', async () => {
render(
<BrowserRouter>
<AddUser />
</BrowserRouter>
);

const usernameInput = screen.getByLabelText(/Username/i);
const passwordInput = screen.getByLabelText(/Password/i);
const addUserButton = screen.getByRole('button', { name: /Add User/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' });

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

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

// Wait for the error Snackbar to be open
await waitFor(() => {
expect(screen.getByText(/Error: La contraseña no puede estar vacía/i)).toBeInTheDocument();
});
});

it('try to add user with username existing', async () => {
render(
<BrowserRouter>
<AddUser />
</BrowserRouter>
);

const usernameInput = screen.getByLabelText(/Username/i);
const passwordInput = screen.getByLabelText(/Password/i);
const addUserButton = screen.getByRole('button', { name: /Add User/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' });

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

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

// Wait for the Snackbar to be open
await waitFor(() => {
expect(screen.getByText(/Error: Este nombre de usuario está en uso/i)).toBeInTheDocument();
});
});
});
Loading

0 comments on commit 3fd1538

Please sign in to comment.