From de016cc0a3463fbc9d18c5d5f967b0d1de3daf53 Mon Sep 17 00:00:00 2001 From: uo264915 Date: Thu, 18 Apr 2024 19:27:34 +0200 Subject: [PATCH 1/5] Test historial de preguntas --- webapp/src/components/HistoricalData.test.js | 54 ++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 webapp/src/components/HistoricalData.test.js diff --git a/webapp/src/components/HistoricalData.test.js b/webapp/src/components/HistoricalData.test.js new file mode 100644 index 00000000..2de12890 --- /dev/null +++ b/webapp/src/components/HistoricalData.test.js @@ -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( + + ); + + 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(); + + }); + }); +}); + + From b3d492520c7c91760316039df6058ba0e9741b8e Mon Sep 17 00:00:00 2001 From: uo264915 Date: Thu, 18 Apr 2024 19:37:21 +0200 Subject: [PATCH 2/5] Test historial de preguntas --- webapp/src/components/HistoricalData.test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/webapp/src/components/HistoricalData.test.js b/webapp/src/components/HistoricalData.test.js index 2de12890..0b0a5bed 100644 --- a/webapp/src/components/HistoricalData.test.js +++ b/webapp/src/components/HistoricalData.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { render, fireEvent, screen, waitFor } from '@testing-library/react'; +import { render, screen, waitFor } from '@testing-library/react'; import axios from 'axios'; import MockAdapter from 'axios-mock-adapter'; import HistoricalData from './HistoricalData'; @@ -26,7 +26,6 @@ describe('HistoricalData component', () => { ); - const element = screen.getByText(/Historial de preguntas/); const tableElement = screen.getByRole('table'); // Verifica si el elemento se encuentra en el DOM From fd1a602153cb43355018418eb0d46f41783b3c65 Mon Sep 17 00:00:00 2001 From: uo264915 Date: Thu, 18 Apr 2024 19:44:13 +0200 Subject: [PATCH 3/5] Test historial de preguntas --- webapp/src/components/HistoricalData.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/webapp/src/components/HistoricalData.test.js b/webapp/src/components/HistoricalData.test.js index 0b0a5bed..8f1fb619 100644 --- a/webapp/src/components/HistoricalData.test.js +++ b/webapp/src/components/HistoricalData.test.js @@ -29,7 +29,6 @@ describe('HistoricalData component', () => { const tableElement = screen.getByRole('table'); // Verifica si el elemento se encuentra en el DOM - expect(element).toBeInTheDocument(); expect(tableElement).toBeInTheDocument(); From 8064d6086a9386bf92ea24005e1b46c3f06e69c6 Mon Sep 17 00:00:00 2001 From: uo264915 Date: Thu, 18 Apr 2024 20:19:59 +0200 Subject: [PATCH 4/5] Test historial de preguntas --- webapp/src/components/HistoricalData.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/webapp/src/components/HistoricalData.test.js b/webapp/src/components/HistoricalData.test.js index 8f1fb619..44dbdd59 100644 --- a/webapp/src/components/HistoricalData.test.js +++ b/webapp/src/components/HistoricalData.test.js @@ -7,7 +7,7 @@ import { BrowserRouter as Router } from 'react-router-dom'; const mockAxios = new MockAdapter(axios); -describe('HistoricalData component', () => { +describe('HistoricalData', () => { beforeEach(() => { mockAxios.reset(); }); @@ -15,12 +15,12 @@ describe('HistoricalData component', () => { 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?", + [{ question: "¿Cual es la capital de Venezuela?", correctOption: "Caracas", incorrectOption1: "Doha", incorrectOption2: "Barcelona", incorrectOption3: "Nasáu" - }); + }]); render( From 2005870dde5dac42f9b4133ad2e786553d44cca7 Mon Sep 17 00:00:00 2001 From: uo264915 Date: Thu, 18 Apr 2024 20:26:10 +0200 Subject: [PATCH 5/5] Test historial de preguntas --- webapp/src/components/HistoricalData.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/src/components/HistoricalData.test.js b/webapp/src/components/HistoricalData.test.js index 44dbdd59..eabfdd7d 100644 --- a/webapp/src/components/HistoricalData.test.js +++ b/webapp/src/components/HistoricalData.test.js @@ -14,7 +14,7 @@ describe('HistoricalData', () => { it('muestra la página con el histórico de preguntas generadas', async () => { - mockAxios.onGet("http://localhost:8000/historicaldata").reply(200, + mockAxios.onGet("http://localhost:8000/getquestionshistory").reply(200, [{ question: "¿Cual es la capital de Venezuela?", correctOption: "Caracas", incorrectOption1: "Doha",