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 historial de preguntas #140

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
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
53 changes: 53 additions & 0 deletions webapp/src/components/HistoricalData.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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 () => {

mockAxios.onGet("http://localhost:8000/historicaldata").reply(200,
{ question: "¿Cual es la capital de Venezuela?",
correctOption: "Caracas",
incorrectOption1: "Doha",
incorrectOption2: "Barcelona",
incorrectOption3: "Nasáu"
});

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

const tableElement = screen.getByRole('table');

// Verifica si el elemento se encuentra en el DOM
expect(element).toBeInTheDocument();
expect(tableElement).toBeInTheDocument();


await waitFor(() => {
expect(screen.getByText('Pregunta')).toBeInTheDocument();
expect(screen.getByText('Opción correcta')).toBeInTheDocument();
expect(screen.getByText('Opción incorrecta 1')).toBeInTheDocument();
expect(screen.getByText('Opción incorrecta 2')).toBeInTheDocument();
expect(screen.getByText('Opción incorrecta 3')).toBeInTheDocument();

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();

});
});
});


Loading