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

Dev #420

Merged
merged 84 commits into from
Apr 29, 2024
Merged

Dev #420

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
e77cd55
Mejorando coverage componentes
uo287627 Apr 25, 2024
4451c05
Quito unused import
uo287627 Apr 25, 2024
0ac9dd0
Corrección nombre setError en componentes
uo287627 Apr 25, 2024
c97d2e0
Casos negativos modificados
uo287627 Apr 25, 2024
364a94d
Corregido casos negativos
uo287627 Apr 25, 2024
376a471
Corrigiendo caso negativo de test UserList y RankingList
uo287627 Apr 25, 2024
28d9c62
Corrigiendo formato cadena esperada
uo287627 Apr 25, 2024
a462625
Detalle menor
uo287627 Apr 25, 2024
1f8ff36
Merge remote-tracking branch 'origin/dev' into sergio
uo287627 Apr 26, 2024
6f86804
Mejorando tests Login
uo287627 Apr 26, 2024
cfedb0e
Añado configuración mockAxios
uo287627 Apr 26, 2024
2e8cb94
Faltaba importar "act"
uo287627 Apr 26, 2024
b41f1a9
Faltaba import "fireEvent"
uo287627 Apr 26, 2024
b282b61
Faltaba un import y colocar un "act"
uo287627 Apr 26, 2024
12acc97
Corregido prop de Login
uo287627 Apr 26, 2024
9144565
Reorganizando pruebas
uo287627 Apr 26, 2024
dc53960
Intento corregir test
uo287627 Apr 26, 2024
24bfe8b
Corrijo test
uo287627 Apr 26, 2024
39828ce
Cambio test login
uo287627 Apr 26, 2024
dfd7dd1
Probando tests
uo287627 Apr 26, 2024
0ae5f39
Probando
uo287627 Apr 26, 2024
832457f
Merge pull request #415 from Arquisoft/laura
uo277310 Apr 26, 2024
4d21180
Merge pull request #417 from Arquisoft/laura
uo277310 Apr 27, 2024
5cca184
Merge remote-tracking branch 'origin/dev' into sergio
uo287627 Apr 28, 2024
833f88c
Intentando corregir test login
uo287627 Apr 28, 2024
fdbff7b
Comprobando presencia elementos en login
uo287627 Apr 28, 2024
2c1cc4f
Comprobando si está saltando un error
uo287627 Apr 28, 2024
8f57012
Corrigiendo fallo retorno mockAxios en Login Test
uo287627 Apr 28, 2024
ac55f14
Depurando error inesperado
uo287627 Apr 28, 2024
72aa54a
Corrigiendo formato respuesta
uo287627 Apr 28, 2024
1953410
Formateando respuesta /login
uo287627 Apr 28, 2024
c093ad3
Más formateo
uo287627 Apr 28, 2024
efdf813
Probando
uo287627 Apr 28, 2024
7ba0c8d
Intento corregir
uo287627 Apr 28, 2024
10cb0f0
Sigo
uo287627 Apr 28, 2024
6bfc46f
Depuracion
uo287627 Apr 28, 2024
03c056a
Más depuración
uo287627 Apr 28, 2024
2c38508
Sigo intentándolo
uo287627 Apr 28, 2024
cd9c15b
Intento corregir
uo287627 Apr 28, 2024
6c1b214
Sigo
uo287627 Apr 28, 2024
ab71fca
Otra forma de hacer mock
uo287627 Apr 28, 2024
f455726
Pruebas
uo287627 Apr 28, 2024
8b8809e
Sigo probando
uo287627 Apr 28, 2024
1649f96
probando
uo287627 Apr 28, 2024
d469ebc
Más intentos
uo287627 Apr 28, 2024
d024293
Otro intento
uo287627 Apr 28, 2024
b6b0183
Creo que ya está
uo287627 Apr 28, 2024
121c673
Corregidos detalles menores Login.test.js
uo287627 Apr 28, 2024
d074528
Ya está
uo287627 Apr 28, 2024
5e9363a
Correcciones menores
uo287627 Apr 28, 2024
a048301
Último detalle
uo287627 Apr 28, 2024
ed73462
Ahora sí
uo287627 Apr 28, 2024
bc79039
Ampliando tests Login
uo287627 Apr 28, 2024
9978b6c
Refactorizando código
uo287627 Apr 28, 2024
bc8290d
Sigo refactorizando
uo287627 Apr 28, 2024
50c7c9a
Refactorizando más
uo287627 Apr 28, 2024
174c293
Error ínfimo
uo287627 Apr 28, 2024
50b2d30
Refactorizando más
uo287627 Apr 28, 2024
f815e39
Corrigiendo una función auxiliar
uo287627 Apr 28, 2024
40edf3e
Intento arreglar nuevas issues
uo287627 Apr 28, 2024
afb4913
Imports que faltaban
uo287627 Apr 28, 2024
7f37703
Sigo reparando las issues
uo287627 Apr 28, 2024
9de0abd
Corrigiendo las props
uo287627 Apr 28, 2024
c9d7146
Corrigiendo fallo
uo287627 Apr 28, 2024
8bc47b8
Terminando de corregir los tests
uo287627 Apr 28, 2024
3bdbe84
faltaban comillas
uo287627 Apr 28, 2024
525cf5c
Detalle selección encabezados tabs despues de login
uo287627 Apr 28, 2024
69b1053
Definitivo
uo287627 Apr 28, 2024
49ba828
Intentando refactorizar codigo
uo287627 Apr 28, 2024
cf622cf
Faltaba definir la variable, la pongo directamente
uo287627 Apr 28, 2024
35e7349
Vuelta a como estaba antes
uo287627 Apr 28, 2024
7e185db
Se me coló este detalle
uo287627 Apr 28, 2024
edaefe9
Resolviendo issues
uo287627 Apr 28, 2024
dec55fd
A ver si esta solución sirve
uo287627 Apr 28, 2024
df27148
Subiendo coverage del nuevo código
uo287627 Apr 28, 2024
7452a5c
Faltaba renderizarlo
uo287627 Apr 28, 2024
369e714
Añadida asincronía
uo287627 Apr 28, 2024
306096f
Faltaba un import
uo287627 Apr 28, 2024
7cd0e81
Corregidas comillas
uo287627 Apr 28, 2024
b1d8927
Acabando
uo287627 Apr 28, 2024
5f773c4
errata
uo287627 Apr 28, 2024
39dc4be
Detalle
uo287627 Apr 28, 2024
5c739c3
Conflicto nombres
uo287627 Apr 28, 2024
c7bdd4e
Merge pull request #414 from Arquisoft/sergio
uo277310 Apr 28, 2024
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
coverage
docs/build
docs/build
.idea/
6 changes: 6 additions & 0 deletions webapp/src/components/GameSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import React, { useState, useEffect } from 'react';
import { Box, Typography, Slider, TextField, FormGroup, FormControlLabel, Checkbox, Tab } from '@mui/material';
import { TabContext, TabList, TabPanel } from '@mui/lab';
import PropTypes from 'prop-types';

const GameSettings = ({ setSettings, currentUser }) => {
const [isWarningVisible, setIsWarningVisible] = useState(false);
Expand Down Expand Up @@ -195,4 +196,9 @@ const GameSettings = ({ setSettings, currentUser }) => {
);
};

GameSettings.propTypes = {
setSettings: PropTypes.func.isRequired,
currentUser: PropTypes.string.isRequired,
};

export default GameSettings;
11 changes: 8 additions & 3 deletions webapp/src/components/GeneratedQuestionsList.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

import React, { useState, useEffect } from 'react';
import axios from 'axios';
import PropTypes from 'prop-types';

const GeneratedQuestionsList = () => {
const GeneratedQuestionsList = ({setError}) => {

const [listquestions, setListquestions] = useState([]);
const [sortColumn, setSortColumn] = useState(null);
Expand All @@ -22,10 +23,10 @@ const GeneratedQuestionsList = () => {
setListquestions(qList);

} else {
console.error('Error obteniendo la lista de preguntas generadas');
setError('Error obteniendo la lista de preguntas generadas');
}
} catch (error) {
console.error('Error obteniendo la lista de preguntas generadas:', error);
setError('Error obteniendo la lista de preguntas generadas:', error);
}
};

Expand Down Expand Up @@ -76,4 +77,8 @@ const GeneratedQuestionsList = () => {
);
};

GeneratedQuestionsList.propTypes = {
setError: PropTypes.func.isRequired,
};

export default GeneratedQuestionsList;
130 changes: 109 additions & 21 deletions webapp/src/components/GeneratedQuestionsList.test.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,131 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { render, screen, act } from '@testing-library/react';
import GeneratedQuestionsList from './GeneratedQuestionsList';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';

jest.mock('axios');

const mockAxios = new MockAdapter(axios);

describe('GeneratedQuestionsList component', () => {
// Test for rendering the component and checking the main heading
test('renders GeneratedQuestionsList component and main heading', () => {
render(<GeneratedQuestionsList />);
beforeEach(() => {
axios.get.mockResolvedValue({
status: 200,
data: [
{
generatedQuestionBody: "¿A qué género literario pertenece 'Cinco horas con Mario'?",
correctAnswer: 'Narrativo'
},
{
generatedQuestionBody: "¿De qué grupo es la canción 'Vino Tinto'?",
correctAnswer: 'Estopa'
},
{
generatedQuestionBody: "¿Cuál es la capital de Portugal?",
correctAnswer: 'Lisboa'
},
{
generatedQuestionBody: "¿Quién escribió la novela 'El Extranjero'?",
correctAnswer: 'Albert Camus'
},
],
});
});

// Check if the main heading is in the document
test('renders GeneratedQuestionsList component and main heading', async () => {
await act( async () => {
render(<GeneratedQuestionsList setError={() => {}} />);
});
const heading = screen.getByRole('heading', { name: /Lista de preguntas/i });
expect(heading).toBeInTheDocument();
});

// Test for rendering the table
it('should display the table', () => {
render(<GeneratedQuestionsList />);

it('should display the table', async () => {
await act( async () => {
render(<GeneratedQuestionsList setError={() => {}} />);
});
const table = screen.getByRole('table');
expect(table).toBeInTheDocument();
});

// Test for rendering the table headers
test('renders table headers', () => {
render(<GeneratedQuestionsList />);

// Check if the table headers are in the document
test('renders table headers', async () => {
await act( async () => {
render(<GeneratedQuestionsList setError={() => {}} />);
});
const questionHeader = screen.getByRole('columnheader', { name: /Pregunta/i });
const answerHeader = screen.getByRole('columnheader', { name: /Respuesta Correcta/i });
expect(questionHeader).toBeInTheDocument();
expect(answerHeader).toBeInTheDocument();
});

// Test for rendering the table rows
test('renders table rows', () => {
render(<GeneratedQuestionsList />);
test('renders table rows', async () => {
await act( async () => {
render(<GeneratedQuestionsList setError={() => {}} />);
});
const tableRows = screen.getAllByRole('row');
expect(tableRows).not.toHaveLength(0);
});

test('should order questions by questionBody correctly', async () => {
await act(async () => {
render(<GeneratedQuestionsList setError={() => {}} />);
});

const questionBodyHeader = screen.getByRole('columnheader', { name: /Pregunta/i });

await act(async() => {
questionBodyHeader.click();
});

let rows = await screen.findAllByRole('row');

expect(rows[1]).toHaveTextContent("¿A qué género literario pertenece 'Cinco horas con Mario'?");
expect(rows[2]).toHaveTextContent("¿Cuál es la capital de Portugal?");
expect(rows[3]).toHaveTextContent("¿De qué grupo es la canción 'Vino Tinto'?");
expect(rows[4]).toHaveTextContent("¿Quién escribió la novela 'El Extranjero'?");

await act(async() => {
questionBodyHeader.click();
});

rows = await screen.findAllByRole('row');

// Check if the table rows are in the document
const tableRows = screen.getAllByRole('row');
expect(tableRows).not.toHaveLength(0);
});
expect(rows[4]).toHaveTextContent("¿A qué género literario pertenece 'Cinco horas con Mario'?");
expect(rows[3]).toHaveTextContent("¿Cuál es la capital de Portugal?");
expect(rows[2]).toHaveTextContent("¿De qué grupo es la canción 'Vino Tinto'?");
expect(rows[1]).toHaveTextContent("¿Quién escribió la novela 'El Extranjero'?");
});

test('should order questions by answer correctly', async () => {
await act(async () => {
render(<GeneratedQuestionsList setError={() => {}} />);
});

const answerHeader = screen.getByRole('columnheader', { name: /Respuesta Correcta/i });

await act(async() => {
answerHeader.click();
});

let rows = await screen.findAllByRole('row');

expect(rows[1]).toHaveTextContent("Albert Camus");
expect(rows[2]).toHaveTextContent("Estopa");
expect(rows[3]).toHaveTextContent("Lisboa");
expect(rows[4]).toHaveTextContent("Narrativo");


await act(async() => {
answerHeader.click();
});

rows = await screen.findAllByRole('row');

expect(rows[4]).toHaveTextContent("Albert Camus");
expect(rows[3]).toHaveTextContent("Estopa");
expect(rows[2]).toHaveTextContent("Lisboa");
expect(rows[1]).toHaveTextContent("Narrativo");
});

});
18 changes: 8 additions & 10 deletions webapp/src/components/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ const Login = ({ setLogged }) => {
try {
const response = await axios.post(`${apiEndpoint}/login`, { username, password });
const { createdAt: userCreatedAt } = response.data;
const usersResponse = await axios.get(`${apiEndpoint}/getAllUsers`);
const users = usersResponse.data;

await axios.get(`${apiEndpoint}/getAllUsers`);
setCreatedAt(userCreatedAt);
setLoginSuccess(true);
setLogged();
setLoading(true);

// Envía todos los nombres de usuario en una sola solicitud
await axios.post(`${apiEndpoint}/createUserRank`, { username });
// Envía todos los nombres de usuario en una sola solicitud
await axios.post(`${apiEndpoint}/createUserRank`, { username });

setLoading(false);
setOpenSnackbar(true);
Expand All @@ -64,7 +62,7 @@ const Login = ({ setLogged }) => {
} else if (error.request) {
setError('No response from server. Please try again later.');
} else {
setError('An unexpected error occurred.');
setError('An unexpected error occurred');
}
}
};
Expand Down Expand Up @@ -142,10 +140,10 @@ const Login = ({ setLogged }) => {
{showComponent === 'game' &&
<Game username={username} totalQuestions={settings.numberQuestions} timeLimit={totalTime} themes={settings.themes}/>
}
{showComponent === 'userList' && <UsersList />}
{showComponent === 'questionList' && <GeneratedQuestionsList />}
{showComponent === 'recordList' && <RecordList username={username} />}
{showComponent === 'rankingList' && <RankingList />}
{showComponent === 'userList' && <UsersList setError={setError} />}
{showComponent === 'questionList' && <GeneratedQuestionsList setError={setError} />}
{showComponent === 'recordList' && <RecordList username={username} setError={setError} />}
{showComponent === 'rankingList' && <RankingList setError={setError} />}
{showComponent === 'settings' && <GameSettings setSettings={setSettings} currentUser={username} />}
{showComponent === 'login' && (
<div>
Expand Down
Loading