generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/Arquisoft/wiq_es04d into…
… develop
- Loading branch information
Showing
4 changed files
with
109 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,34 +17,36 @@ describe('Help Tests', () => { | |
mockNavigate.mockClear(); | ||
}); | ||
|
||
test('renders Help', () => { | ||
test('renders Help', async () => { | ||
render( | ||
<BrowserRouter> | ||
<Ayuda /> | ||
</BrowserRouter> | ||
); | ||
|
||
// Verifica que estan los elementos | ||
expect(screen.getByText(/AYUDA (WIQ 4D)/i)).toBeInTheDocument(); | ||
|
||
// verifica las secciones | ||
expect(screen.getByText(/Registro e Inicio de Sesión/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/Cómo Jugar/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/Historial y Ranking/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/API REST de la aplicación/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/Otras Funcionalidades/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/Contacto/i)).toBeInTheDocument(); | ||
|
||
// verifica el video | ||
expect(screen.getByTestId('help-video')).toHaveAttribute('src', '/videos/help.mp4'); | ||
|
||
// verifica los links | ||
expect(screen.getByText('[email protected]')).toBeInTheDocument(); | ||
expect(screen.getByText('[email protected]')).toBeInTheDocument(); | ||
expect(screen.getByText('[email protected]')).toBeInTheDocument(); | ||
// Utiliza findByText para esperar de forma asíncrona a que el texto esté disponible | ||
const ayudaTitle = await screen.findByText(/AYUDA \(WIQ 4D\)/i); | ||
expect(ayudaTitle).toBeInTheDocument(); | ||
|
||
// Verifica las secciones | ||
expect(await screen.findByText(/Registro e Inicio de Sesión/i)).toBeInTheDocument(); | ||
expect(await screen.findByText(/Cómo Jugar/i)).toBeInTheDocument(); | ||
expect(await screen.findByText(/Historial y Ranking/i)).toBeInTheDocument(); | ||
expect(await screen.findByText(/API REST de la aplicación/i)).toBeInTheDocument(); | ||
expect(await screen.findByText(/Otras Funcionalidades/i)).toBeInTheDocument(); | ||
expect(await screen.findByText(/Contacto/i)).toBeInTheDocument(); | ||
|
||
// Verifica el video | ||
expect(screen.getByTestId('help-video')).toHaveAttribute('src', '/videos/help.mp4'); | ||
|
||
// Verifica los links | ||
expect(await screen.findByText('[email protected]')).toBeInTheDocument(); | ||
expect(await screen.findByText('[email protected]')).toBeInTheDocument(); | ||
expect(await screen.findByText('[email protected]')).toBeInTheDocument(); | ||
}); | ||
|
||
|
||
|
||
}); | ||
|
||
async function wait(milliseconds) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React from 'react'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import axios from 'axios'; | ||
import { AuthContext } from '../../AuthContext'; | ||
import Ranking from './Ranking'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
|
||
const mockedNavigate = jest.fn(); | ||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useNavigate: () => mockedNavigate, | ||
})); | ||
|
||
// Mock de axios | ||
jest.mock('axios'); | ||
|
||
describe('Ranking Component', () => { | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('should navigate to login if not logged in', () => { | ||
render( | ||
<BrowserRouter> | ||
<AuthContext.Provider value={{ isLoggedIn: false }}> | ||
<Ranking /> | ||
</AuthContext.Provider> | ||
</BrowserRouter> | ||
); | ||
|
||
// Verifica que se haya llamado a navigate con '/login' | ||
expect(mockedNavigate).toHaveBeenCalledWith('/login'); | ||
}); | ||
test('should handle no ranking data', async () => { | ||
axios.get.mockResolvedValue({ data: [] }); | ||
|
||
render( | ||
<BrowserRouter> | ||
<AuthContext.Provider value={{ isLoggedIn: true }}> | ||
<Ranking /> | ||
</AuthContext.Provider> | ||
</BrowserRouter> | ||
); | ||
|
||
await waitFor(() => expect(screen.getByText('No hay datos de ranking disponibles.')).toBeInTheDocument()); | ||
}); | ||
test('should display table headers and player data correctly', async () => { | ||
const rankingData = [ | ||
{ username: 'user1', NumPreguntasJugadas: 10, NumAcertadas: 5 }, | ||
{ username: 'user2', NumPreguntasJugadas: 20, NumAcertadas: 12 } | ||
]; | ||
|
||
axios.get.mockResolvedValue({ data: rankingData }); | ||
|
||
render( | ||
<BrowserRouter> | ||
<AuthContext.Provider value={{ isLoggedIn: true }}> | ||
<Ranking /> | ||
</AuthContext.Provider> | ||
</BrowserRouter> | ||
); | ||
|
||
// Esperamos a que se muestren los elementos en la pantalla | ||
await waitFor(() => { | ||
// Verificar que los encabezados de la tabla se cargan correctamente | ||
expect(screen.getByText('Posición')).toBeInTheDocument(); | ||
expect(screen.getByText('Nombre de usuario')).toBeInTheDocument(); | ||
expect(screen.getByText('Preguntas Jugadas')).toBeInTheDocument(); | ||
expect(screen.getByText('Preguntas Acertadas')).toBeInTheDocument(); | ||
expect(screen.getByText('Porcentaje de Aciertos')).toBeInTheDocument(); | ||
|
||
// Verificar que los datos del primer jugador se cargan correctamente | ||
expect(screen.getByText('user1')).toBeInTheDocument(); | ||
expect(screen.getByText('10')).toBeInTheDocument(); // Preguntas Jugadas por user1 | ||
expect(screen.getByText('5')).toBeInTheDocument(); // Preguntas Acertadas por user1 | ||
expect(screen.getByText('50.00%')).toBeInTheDocument(); // Porcentaje de Aciertos de user1 | ||
|
||
// Verificar que los datos del segundo jugador se cargan correctamente | ||
expect(screen.getByText('user2')).toBeInTheDocument(); | ||
expect(screen.getByText('20')).toBeInTheDocument(); // Preguntas Jugadas por user2 | ||
expect(screen.getByText('12')).toBeInTheDocument(); // Preguntas Acertadas por user2 | ||
expect(screen.getByText('60.00%')).toBeInTheDocument(); // Porcentaje de Aciertos de user2 | ||
}); | ||
}); | ||
|
||
}); |