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

Prueba conjunto #60

Merged
merged 8 commits into from
Apr 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
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
Loading