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

Test HistoricalData y RegisteredUsers #161

Merged
merged 10 commits into from
Apr 26, 2024
13 changes: 11 additions & 2 deletions webapp/src/components/HistoricalData.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,22 @@ const HistoricalData = () => {
</TableRow>
</TableHead>
<TableBody>
{paginatedData.map((row, rowIndex) => (
{/* {paginatedData.map((row, rowIndex) => (
<TableRow key={rowIndex}>
{row.map((cell, cellIndex) => (
<TableCell key={cellIndex}>{cell}</TableCell>
))}
</TableRow>
))}
))} */}
{paginatedData.map((row, rowIndex) => (
<TableRow key={rowIndex}>
<TableCell>{row[0]}</TableCell>
<TableCell>{row[1]}</TableCell>
<TableCell>{row[2]}</TableCell>
<TableCell>{row[3]}</TableCell>
<TableCell>{row[4]}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
Expand Down
44 changes: 44 additions & 0 deletions webapp/src/components/HistoricalData.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import HistoricalData from './HistoricalData';
import { BrowserRouter as Router } from 'react-router-dom';

const mockAxios = new MockAdapter(axios);

describe('HistoricalData component', () => {
beforeEach(() => {
mockAxios.reset();
});

it('muestra la página con el histórico de preguntas generadas', async () => {

const question1 = ['¿Cual es la capital de Venezuela?', 'Caracas', 'Doha', 'Barcelona', 'Nasáu'];
const question2 = ['¿Cual es la capital de Francia?', 'París', 'Londres', 'Madrid', 'Roma'];
const mockUsers = [question1, question2];
mockAxios.onGet("http://localhost:8000/getquestionshistory").reply(200, mockUsers);

render(<Router>
<HistoricalData />
</Router>);

await waitFor(() => {

expect(screen.getByText('¿Cual es la capital de Venezuela?')).toBeInTheDocument();
expect(screen.getByText('Caracas')).toBeInTheDocument();
expect(screen.getByText('Doha')).toBeInTheDocument();
expect(screen.getByText('Barcelona')).toBeInTheDocument();
expect(screen.getByText('Nasáu')).toBeInTheDocument();

expect(screen.getByText('¿Cual es la capital de Francia?')).toBeInTheDocument();
expect(screen.getByText('París')).toBeInTheDocument();
expect(screen.getByText('Londres')).toBeInTheDocument();
expect(screen.getByText('Madrid')).toBeInTheDocument();
expect(screen.getByText('Roma')).toBeInTheDocument();

});
});
});


9 changes: 8 additions & 1 deletion webapp/src/components/RegisteredUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,20 @@ const RegisteredUsers = () => {
</tr>
</thead>
<tbody>
{registeredUsers.map((row, rowIndex) => (
{/* {registeredUsers.map((row, rowIndex) => (
<tr key={rowIndex}>
{row.map((cell, cellIndex) => (
<td key={cellIndex}>{cell}</td>
))}
</tr>
))} */}
{registeredUsers.map((row, rowIndex) => (
<tr key={rowIndex}>
<td>{row[0]}</td>
<td>{row[1]}</td>
</tr>
))}

</tbody>
</table>
</div>
Expand Down
32 changes: 32 additions & 0 deletions webapp/src/components/RegisteredUsers.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import {BrowserRouter as Router} from "react-router-dom";
import RegisteredUsers from './RegisteredUsers';

const mockAxios = new MockAdapter(axios);

describe('Registered Users component', () => {
beforeEach(() => {
mockAxios.reset();
});

it('muestra todos los usuarios registrados', async () => {
const user1 = ['pablo', '4/23/2024'];
const mockUsers = [user1];
mockAxios.onGet("http://localhost:8000/getregisteredusers").reply(200, mockUsers);

render(
<Router>
<RegisteredUsers />
</Router>);

await waitFor(() => {

expect(screen.getByText('pablo')).toBeInTheDocument();
expect(screen.getByText('4/23/2024')).toBeInTheDocument();
});

});
});