Skip to content

Commit

Permalink
Test historial de preguntas
Browse files Browse the repository at this point in the history
  • Loading branch information
uo264915 committed Apr 18, 2024
1 parent daf806e commit de016cc
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions webapp/src/components/HistoricalData.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';
import { render, fireEvent, 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 element = screen.getByText(/Historial de preguntas/);
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();

});
});
});


0 comments on commit de016cc

Please sign in to comment.