From de016cc0a3463fbc9d18c5d5f967b0d1de3daf53 Mon Sep 17 00:00:00 2001 From: uo264915 Date: Thu, 18 Apr 2024 19:27:34 +0200 Subject: [PATCH 1/8] 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/8] 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/8] 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/8] 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/8] 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", From fe9b795091fb8a2abb33e678e926d71d73cdc02c Mon Sep 17 00:00:00 2001 From: uo264915 Date: Tue, 23 Apr 2024 21:57:12 +0200 Subject: [PATCH 6/8] Sincronizacion y tests --- webapp/src/components/HistoricalData.test.js | 6 ---- webapp/src/components/RegisteredUsers.test.js | 34 +++++++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 webapp/src/components/RegisteredUsers.test.js diff --git a/webapp/src/components/HistoricalData.test.js b/webapp/src/components/HistoricalData.test.js index eabfdd7d..8d6ebca4 100644 --- a/webapp/src/components/HistoricalData.test.js +++ b/webapp/src/components/HistoricalData.test.js @@ -26,12 +26,6 @@ describe('HistoricalData', () => { ); - const tableElement = screen.getByRole('table'); - - // Verifica si el elemento se encuentra en el DOM - expect(tableElement).toBeInTheDocument(); - - await waitFor(() => { expect(screen.getByText('Pregunta')).toBeInTheDocument(); expect(screen.getByText('Opción correcta')).toBeInTheDocument(); diff --git a/webapp/src/components/RegisteredUsers.test.js b/webapp/src/components/RegisteredUsers.test.js new file mode 100644 index 00000000..824c9fec --- /dev/null +++ b/webapp/src/components/RegisteredUsers.test.js @@ -0,0 +1,34 @@ +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 () => { + + mockAxios.onGet("http://localhost:8000/RegisteredUsers").reply(200, + [{ username: "pablo", + fecha: "4/23/2024"}]); + + render( + + + ); + + await waitFor(() => { + + + expect(screen.getByText('pablo')).toBeInTheDocument(); + expect(screen.getByText('4/23/2024')).toBeInTheDocument(); + }); + + }); +}); \ No newline at end of file From 06055d91187aaa9d9ede9269cd9a0d8e25dd4fb1 Mon Sep 17 00:00:00 2001 From: uo264915 Date: Thu, 25 Apr 2024 20:00:29 +0200 Subject: [PATCH 7/8] Test HisotircalData y RegisteredUsers --- webapp/src/components/HistoricalData.js | 13 ++++++++++-- webapp/src/components/HistoricalData.test.js | 21 +++++++++++++------ webapp/src/components/RegisteredUsers.js | 8 ++++++- webapp/src/components/RegisteredUsers.test.js | 1 - 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/webapp/src/components/HistoricalData.js b/webapp/src/components/HistoricalData.js index c07669f0..6045c211 100644 --- a/webapp/src/components/HistoricalData.js +++ b/webapp/src/components/HistoricalData.js @@ -62,13 +62,22 @@ const HistoricalData = () => { - {paginatedData.map((row, rowIndex) => ( + {/* {paginatedData.map((row, rowIndex) => ( {row.map((cell, cellIndex) => ( {cell} ))} - ))} + ))} */} + {paginatedData.map((row, rowIndex) => ( + + {row[0]} + {row[1]} + {row[2]} + {row[3]} + {row[4]} + + ))} diff --git a/webapp/src/components/HistoricalData.test.js b/webapp/src/components/HistoricalData.test.js index 8d6ebca4..4e1dc9ec 100644 --- a/webapp/src/components/HistoricalData.test.js +++ b/webapp/src/components/HistoricalData.test.js @@ -20,24 +20,33 @@ describe('HistoricalData', () => { incorrectOption1: "Doha", incorrectOption2: "Barcelona", incorrectOption3: "Nasáu" - }]); + }, + { + question: "¿Cuál es la capital de Francia?", + correctOption: "París", + incorrectOption1: "Londres", + incorrectOption2: "Madrid", + incorrectOption3: "Roma" + } + ]); render( ); 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(); + + expect(screen.getByText('¿Cuál 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(); }); }); diff --git a/webapp/src/components/RegisteredUsers.js b/webapp/src/components/RegisteredUsers.js index ed4347da..d321ea3f 100644 --- a/webapp/src/components/RegisteredUsers.js +++ b/webapp/src/components/RegisteredUsers.js @@ -41,12 +41,18 @@ const RegisteredUsers = () => { - {registeredUsers.map((row, rowIndex) => ( + {/* {registeredUsers.map((row, rowIndex) => ( {row.map((cell, cellIndex) => ( {cell} ))} + ))} */} + {registeredUsers.map((row, rowIndex) => ( + + {row[0]} + {row[1]} + ))} diff --git a/webapp/src/components/RegisteredUsers.test.js b/webapp/src/components/RegisteredUsers.test.js index 824c9fec..9c285aee 100644 --- a/webapp/src/components/RegisteredUsers.test.js +++ b/webapp/src/components/RegisteredUsers.test.js @@ -25,7 +25,6 @@ describe('Registered Users component', () => { await waitFor(() => { - expect(screen.getByText('pablo')).toBeInTheDocument(); expect(screen.getByText('4/23/2024')).toBeInTheDocument(); }); From d59b5ad95429744fa5d38df7adef808d8b8b5c85 Mon Sep 17 00:00:00 2001 From: uo264915 Date: Fri, 26 Apr 2024 21:09:31 +0200 Subject: [PATCH 8/8] Test HistoricalData y RegisteredUsers --- webapp/src/components/HistoricalData.test.js | 23 +++++-------------- webapp/src/components/RegisteredUsers.js | 1 + webapp/src/components/RegisteredUsers.test.js | 7 +++--- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/webapp/src/components/HistoricalData.test.js b/webapp/src/components/HistoricalData.test.js index 4e1dc9ec..d5fdf64d 100644 --- a/webapp/src/components/HistoricalData.test.js +++ b/webapp/src/components/HistoricalData.test.js @@ -7,28 +7,17 @@ import { BrowserRouter as Router } from 'react-router-dom'; const mockAxios = new MockAdapter(axios); -describe('HistoricalData', () => { +describe('HistoricalData component', () => { beforeEach(() => { mockAxios.reset(); }); it('muestra la página con el histórico de preguntas generadas', async () => { - mockAxios.onGet("http://localhost:8000/getquestionshistory").reply(200, - [{ question: "¿Cual es la capital de Venezuela?", - correctOption: "Caracas", - incorrectOption1: "Doha", - incorrectOption2: "Barcelona", - incorrectOption3: "Nasáu" - }, - { - question: "¿Cuál es la capital de Francia?", - correctOption: "París", - incorrectOption1: "Londres", - incorrectOption2: "Madrid", - incorrectOption3: "Roma" - } - ]); + 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( @@ -42,7 +31,7 @@ describe('HistoricalData', () => { expect(screen.getByText('Barcelona')).toBeInTheDocument(); expect(screen.getByText('Nasáu')).toBeInTheDocument(); - expect(screen.getByText('¿Cuál es la capital de Francia?')).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(); diff --git a/webapp/src/components/RegisteredUsers.js b/webapp/src/components/RegisteredUsers.js index d321ea3f..bc2b6347 100644 --- a/webapp/src/components/RegisteredUsers.js +++ b/webapp/src/components/RegisteredUsers.js @@ -54,6 +54,7 @@ const RegisteredUsers = () => { {row[1]} ))} + diff --git a/webapp/src/components/RegisteredUsers.test.js b/webapp/src/components/RegisteredUsers.test.js index 9c285aee..76e49bde 100644 --- a/webapp/src/components/RegisteredUsers.test.js +++ b/webapp/src/components/RegisteredUsers.test.js @@ -13,10 +13,9 @@ describe('Registered Users component', () => { }); it('muestra todos los usuarios registrados', async () => { - - mockAxios.onGet("http://localhost:8000/RegisteredUsers").reply(200, - [{ username: "pablo", - fecha: "4/23/2024"}]); + const user1 = ['pablo', '4/23/2024']; + const mockUsers = [user1]; + mockAxios.onGet("http://localhost:8000/getregisteredusers").reply(200, mockUsers); render(