Skip to content

Commit

Permalink
Nuevos test
Browse files Browse the repository at this point in the history
  • Loading branch information
UO287747 committed Feb 29, 2024
1 parent 5315046 commit 4fc1342
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
6 changes: 2 additions & 4 deletions webapp/package-lock.json

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

4 changes: 2 additions & 2 deletions webapp/src/components/Nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function Nav({ goTo }) {
>

<MenuItem onClick={() => goToMenuClic()}>
<Typography textAlign="center">Volver al Menú</Typography>
<Typography textAlign="center">Volver al menú</Typography>
</MenuItem>
</Menu>
</Box>
Expand Down Expand Up @@ -125,7 +125,7 @@ function Nav({ goTo }) {
onClick={() => goToMenuClic()}
sx={{ my: 2, color: 'white', display: 'block' }}
>
Volver al Menú
Menú
</Button>
</Box>

Expand Down
48 changes: 41 additions & 7 deletions webapp/src/test/Nav.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,46 @@
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import { render, fireEvent, waitFor } from '@testing-library/react';
import Nav from '../components/Nav';

describe('Nav component', () => {
test('renders Nav component correctly', () => {
const mockGoTo = jest.fn();
render(<Nav goTo={mockGoTo} />);


describe('Nav Component', () => {

test('opens and closes navigation menu on menu icon click', async () => {
const { getByLabelText, queryByText } = render(<Nav />);
const menuIcon = getByLabelText('account of current user');

fireEvent.click(menuIcon);
await waitFor(() => {
expect(queryByText('Volver al menú')).toBeInTheDocument();
});

});

test('opens and closes user menu on avatar click', async () => {
const { getByAltText, queryByText } = render(<Nav />);
const avatar = getByAltText('Remy Sharp');

fireEvent.click(avatar);
await waitFor(() => {
expect(queryByText('Profile')).toBeInTheDocument();
});

});

test('calls goTo function when "Volver al menú" is clicked', async () => {
const goToMock = jest.fn();
const { getByText } = render(<Nav goTo={goToMock} />);
fireEvent.click(getByText('Volver al menú'));
await waitFor(() => {
expect(goToMock).toHaveBeenCalledTimes(1);
});
});

test('calls goTo function when "Logout" is clicked', async () => {
const goToMock = jest.fn();
const { getByText } = render(<Nav goTo={goToMock} />);
fireEvent.click(getByText('Logout'));
await waitFor(() => {
expect(goToMock).toHaveBeenCalledTimes(1);
});
});
});

0 comments on commit 4fc1342

Please sign in to comment.