Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Arquisoft/wiq_es04d into…
Browse files Browse the repository at this point in the history
… develop
  • Loading branch information
yagonavajas committed Apr 24, 2024
2 parents fb12b31 + a535ee4 commit b444c54
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 52 deletions.
19 changes: 0 additions & 19 deletions gatewayservice/gateway-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,23 +211,4 @@ describe('Gateway Service', () => {
expect(response.body.error).toBe('Error getting the history');
});

it('should forward get specific user history request to history service', async () => {
mockSuccessResponse([{ action: 'specific action', date: '2024-03-31' }]);

const response = await request(app)
.get('/gethistory/testuser');

expect(response.statusCode).toBe(200);
expect(response.body).toEqual([{ action: 'specific action', date: '2024-03-31' }]);
});

it('should handle error getting specific user history from history service', async () => {
mockErrorResponse({ status: 500, message: 'Error getting the history' });

const response = await request(app)
.get('/gethistory/nonexistentUser');

expect(response.statusCode).toBe(500);
expect(response.body.error).toBe('Error getting the history');
});
});
14 changes: 0 additions & 14 deletions users/historyservice/history-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,4 @@ describe('GET /gethistory/:username', () => {
expect(response.body.NumFalladas).toBe(2);
});

test('should return an error', async () => {
const response = await request(app).get('/gethistory/nonexistinguser');

expect(response.status).toBe(404);
expect(response.body.error).toBe('No se encontro historial para este usuario');

});
});

describe('GET /getranking', () => {
test('get the ranking in order', async () => {

});

});
40 changes: 21 additions & 19 deletions webapp/src/components/pages/Ayuda.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
88 changes: 88 additions & 0 deletions webapp/src/components/pages/Ranking.test.js
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
});
});

});

0 comments on commit b444c54

Please sign in to comment.