Skip to content

Commit

Permalink
Nuevos test
Browse files Browse the repository at this point in the history
  • Loading branch information
UO287747 committed Feb 28, 2024
1 parent 5db2e66 commit 85964f5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
31 changes: 31 additions & 0 deletions webapp/src/test/Nav.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import { render, screen, fireEvent } 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} />);

// Verifica que los elementos del Nav se rendericen correctamente
expect(screen.getByText('React Quiz')).toBeInTheDocument();
expect(screen.getByText('Volver al Menú')).toBeInTheDocument();
expect(screen.getByAltText('Remy Sharp')).toBeInTheDocument();

// Simula hacer clic en el botón de menú
fireEvent.click(screen.getByLabelText('account of current user'));
// Verifica que se abra el menú
expect(screen.getByText('Profile')).toBeInTheDocument();
expect(screen.getByText('Logout')).toBeInTheDocument();

// Simula hacer clic en el botón de "Volver al Menú"
fireEvent.click(screen.getByText('Volver al Menú'));
// Verifica que la función goTo haya sido llamada con el parámetro correcto
expect(mockGoTo).toHaveBeenCalledWith(1);

// Simula hacer clic en el botón de "Logout"
fireEvent.click(screen.getByText('Logout'));
// Verifica que la función goTo haya sido llamada con el parámetro correcto
expect(mockGoTo).toHaveBeenCalledWith(0);
});
});
12 changes: 12 additions & 0 deletions webapp/src/test/PostGame.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { PostGame } from '../components/PostGame';

describe('PostGame component', () => {
test('renders "FIN" text correctly', () => {
render(<PostGame />);

// Verifica que el texto "FIN" se renderice correctamente
expect(screen.getByText('FIN')).toBeInTheDocument();
});
});

0 comments on commit 85964f5

Please sign in to comment.