From a5ad28cd232aec8fe78194e6696bd185de0653cc Mon Sep 17 00:00:00 2001 From: Miguel Date: Mon, 29 Apr 2024 20:17:42 +0200 Subject: [PATCH 1/6] Change to prometheus so all services appear in the data --- gatewayservice/monitoring/prometheus/prometheus.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gatewayservice/monitoring/prometheus/prometheus.yml b/gatewayservice/monitoring/prometheus/prometheus.yml index 3093655b..a7ae2c09 100644 --- a/gatewayservice/monitoring/prometheus/prometheus.yml +++ b/gatewayservice/monitoring/prometheus/prometheus.yml @@ -1,6 +1,6 @@ global: scrape_interval: 5s scrape_configs: - - job_name: "example-nodejs-app" + - job_name: "conoceryvencer-nodejs-app" static_configs: - - targets: ["gatewayservice:8000"] \ No newline at end of file + - targets: ["gatewayservice:8000","userservice:8001","queryservice:8002","gatewayservice:8003","gameservice:8004"] \ No newline at end of file From 3580d56d7410f474179aa513ca4ccd0316b70fa8 Mon Sep 17 00:00:00 2001 From: CarolinaUniovi Date: Mon, 29 Apr 2024 22:47:28 +0200 Subject: [PATCH 2/6] Test for registration --- .../src/components/register/Register.test.js | 46 +++++++++++++++++++ webapp/src/components/register/Register.tsx | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/webapp/src/components/register/Register.test.js b/webapp/src/components/register/Register.test.js index 548b8ae5..23065e61 100644 --- a/webapp/src/components/register/Register.test.js +++ b/webapp/src/components/register/Register.test.js @@ -14,6 +14,24 @@ describe('Register component', () => { }); it('should add user successfully', async () => { + var localStorageMock = (function() { + var store = {}; + return { + getItem: function(key) { + return store[key]; + }, + setItem: function(key, value) { + store[key] = value.toString(); + }, + clear: function() { + store = {}; + }, + removeItem: function(key) { + delete store[key]; + } + }; + })(); + Object.defineProperty(window, 'localStorage', { value: localStorageMock }); render( @@ -26,6 +44,12 @@ describe('Register component', () => { // Mock the axios.post request to simulate a successful response mockAxios.onPost('http://localhost:8000/adduser').reply(200); + mockAxios.onPost('http://localhost:8000/login').reply(200, { + username: 'testUser', + totalScore: 0, + nWins: 0, + uuid: '123' + }); // Simulate user input fireEvent.change(usernameInput, { target: { value: 'testUser' } }); @@ -38,6 +62,14 @@ describe('Register component', () => { await waitFor(() => { expect(screen.getByTestId('register-successfull-snackbar')).toBeInTheDocument(); }); + + await waitFor(() => { + expect(localStorageMock.getItem('username')).toBe('testUser'); + expect(localStorageMock.getItem('score')).toBe('0'); + expect(localStorageMock.getItem('isAuthenticated')).toBe('true'); + expect(localStorageMock.getItem('userUUID')).toBe('123'); + + }); }); it('should handle error when adding user', async () => { @@ -66,4 +98,18 @@ describe('Register component', () => { expect(screen.getByTestId('register-error-snackbar')).toBeInTheDocument(); }); }); + + it('should handle return button click', () => { + const goBackMock = jest.fn(); + const { getByTestId } = render( + + + ); + + // Click on the return button + fireEvent.click(getByTestId("return-button")); + + expect(goBackMock).toHaveBeenCalled(); + }); + }); diff --git a/webapp/src/components/register/Register.tsx b/webapp/src/components/register/Register.tsx index 5ff5b05f..5a4e6984 100644 --- a/webapp/src/components/register/Register.tsx +++ b/webapp/src/components/register/Register.tsx @@ -89,7 +89,7 @@ const Register = (props:ActionProps) => { - From 0acd688d045d048fb9b4ad5d591ac00e6125c8c8 Mon Sep 17 00:00:00 2001 From: CarolinaUniovi Date: Mon, 29 Apr 2024 23:05:25 +0200 Subject: [PATCH 3/6] playingGame tests --- .../src/components/game/PlayingGame.test.js | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 webapp/src/components/game/PlayingGame.test.js diff --git a/webapp/src/components/game/PlayingGame.test.js b/webapp/src/components/game/PlayingGame.test.js new file mode 100644 index 00000000..f6fc3081 --- /dev/null +++ b/webapp/src/components/game/PlayingGame.test.js @@ -0,0 +1,72 @@ +import React from 'react'; +import { render, fireEvent, waitFor } from '@testing-library/react'; +import PlayingGame from './PlayingGame'; + +jest.useFakeTimers(); + +describe('PlayingGame component', () => { + it('should handle answering questions and end game correctly', async () => { + const questions = [ + { uuid: '1', + question: 'What is the capital of France?', + correctAnswer: '1', + incorrectAnswer1: '2', + incorrectAnswer2: '3', + incorrectAnswer3: '4', }, + { uuid: '2', + question: 'What is the capital of Italy?', + correctAnswer: '1', + incorrectAnswer1: '2', + incorrectAnswer2: '3', + incorrectAnswer3: '4', }, + { uuid: '2', + question: 'What is the capital of Spain?', + correctAnswer: '1', + incorrectAnswer1: '2', + incorrectAnswer2: '3', + incorrectAnswer3: '4', }, + ]; + + const setCurrentStageMock = jest.fn(); + const { getByTestId, queryByTestId } = render( + + ); + + // Ensure initial rendering + expect(getByTestId('question-container')).toBeInTheDocument(); + expect(getByTestId('question-title')).toBeInTheDocument(); + expect(getByTestId('question')).toBeInTheDocument(); + expect(getByTestId('seconds')).toBeInTheDocument(); + + // Simulate answering question 1 + fireEvent.click(getByTestId('answer-1')); + jest.advanceTimersByTime(10000); + await waitFor(() => { + expect(getByTestId('question-title')).toBeInTheDocument(); + expect(getByTestId('question')).toBeInTheDocument(); + expect(getByTestId('seconds')).toBeInTheDocument(); + }); + + // Simulate answering question 2 + fireEvent.click(getByTestId('answer-2')); + jest.advanceTimersByTime(10000); + await waitFor(() => { + expect(getByTestId('question')).toBeInTheDocument(); + expect(getByTestId('seconds')).toBeInTheDocument(); + }); + + // Simulate answering question 3 + fireEvent.click(getByTestId('answer-3')); + jest.advanceTimersByTime(10000); + await waitFor(() => { + expect(queryByTestId('question-container')).toBeNull(); + expect(getByTestId('result')).toBeInTheDocument(); + expect(getByTestId('points')).toBeInTheDocument(); + }); + }); + + // Add more test cases for edge cases and multiplayer scenarios if applicable +}); \ No newline at end of file From 30ebf2c09a073727872e3184f9d932f1189e3e97 Mon Sep 17 00:00:00 2001 From: CarolinaUniovi Date: Mon, 29 Apr 2024 23:43:01 +0200 Subject: [PATCH 4/6] Group creation modal tests added --- .../group/GroupCreationModal.test.js | 41 ++++++++++++++++++- .../components/group/GroupCreationModal.tsx | 13 +++++- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/webapp/src/components/group/GroupCreationModal.test.js b/webapp/src/components/group/GroupCreationModal.test.js index ad0a55da..5adff1d3 100644 --- a/webapp/src/components/group/GroupCreationModal.test.js +++ b/webapp/src/components/group/GroupCreationModal.test.js @@ -1,7 +1,10 @@ -import { render, fireEvent } from '@testing-library/react'; +import { render, screen, fireEvent, waitFor } from '@testing-library/react'; +import userEvent from "@testing-library/user-event"; import { CreationModal } from './GroupCreationModal'; +import axios from 'axios'; +import MockAdapter from 'axios-mock-adapter'; -jest.mock('axios'); +const mockAxios = new MockAdapter(axios); describe('CreationModal component', () => { test('renders the modal properly', async () => { @@ -29,4 +32,38 @@ describe('CreationModal component', () => { }); + it('should render input fields and handle changes correctly', async () => { + const nowHasGroupMock = jest.fn(); + const setErrorMock = jest.fn(); + const toggleCreateModalMock = jest.fn(); + + render( + + ); + + const groupName = screen.getByTestId('group-name-input'); + const description = screen.getByTestId('description-input'); + + // Simulate changing input values + await userEvent.type(groupName, "a") + await userEvent.type(description, "a") + fireEvent.click(screen.getByTestId('no-button')); + fireEvent.change(screen.getByTestId('max-members-input'), { target: { value: '5' } }); + + // Ensure input values are updated correctly + expect(screen.getByTestId('max-members-input')).toHaveValue(5); + + mockAxios.onPost('http://localhost:8000/createGroup').reply(200, {group: "1"}); + + + fireEvent.click(screen.getByTestId('create-button')); + await waitFor(() => { + expect(nowHasGroupMock).toHaveBeenCalled(); + }); + }); + }); \ No newline at end of file diff --git a/webapp/src/components/group/GroupCreationModal.tsx b/webapp/src/components/group/GroupCreationModal.tsx index e5956d20..bbfc7ed3 100644 --- a/webapp/src/components/group/GroupCreationModal.tsx +++ b/webapp/src/components/group/GroupCreationModal.tsx @@ -27,7 +27,12 @@ export const CreationModal: FC = ({ nowHasGroup, setError, toggleCr nowHasGroup(); }); } catch (error: any) { - setError(error.response?.data.error); + if (error.response && error.response.data && error.response.data.error) { + setError(error.response.data.error); + } else { + // Handle other types of errors + console.error('An error occurred:', error); + } } }; @@ -81,7 +86,11 @@ export const CreationModal: FC = ({ nowHasGroup, setError, toggleCr

{t('create_group_max_members')}

+ style={{ width: '37px' }} + type="number" + step={1} + value={maxMembers} + onChange={handleChange} max={200} min={2} />

{t('create_group_description')}

From e5c01716d1f6b5b84dff252e2e34c64d4860a26c Mon Sep 17 00:00:00 2001 From: CarolinaUniovi Date: Tue, 30 Apr 2024 00:03:06 +0200 Subject: [PATCH 5/6] added something to test --- webapp/src/components/game/PlayingGame.test.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/webapp/src/components/game/PlayingGame.test.js b/webapp/src/components/game/PlayingGame.test.js index f6fc3081..23875629 100644 --- a/webapp/src/components/game/PlayingGame.test.js +++ b/webapp/src/components/game/PlayingGame.test.js @@ -47,7 +47,8 @@ describe('PlayingGame component', () => { await waitFor(() => { expect(getByTestId('question-title')).toBeInTheDocument(); expect(getByTestId('question')).toBeInTheDocument(); - expect(getByTestId('seconds')).toBeInTheDocument(); + expect(getByTestId('seconds')).toHaveTextContent('10'); + }); // Simulate answering question 2 @@ -55,7 +56,7 @@ describe('PlayingGame component', () => { jest.advanceTimersByTime(10000); await waitFor(() => { expect(getByTestId('question')).toBeInTheDocument(); - expect(getByTestId('seconds')).toBeInTheDocument(); + expect(getByTestId('seconds')).toHaveTextContent('10'); }); // Simulate answering question 3 @@ -64,7 +65,7 @@ describe('PlayingGame component', () => { await waitFor(() => { expect(queryByTestId('question-container')).toBeNull(); expect(getByTestId('result')).toBeInTheDocument(); - expect(getByTestId('points')).toBeInTheDocument(); + expect(getByTestId('points')).toHaveTextContent('playing_single_player_you_earned50playing_single_player_points'); }); }); From 0428deafdce4ab451069729b7d58418516771b92 Mon Sep 17 00:00:00 2001 From: JaimeLoredo Date: Tue, 30 Apr 2024 00:28:36 +0200 Subject: [PATCH 6/6] fix change in css --- webapp/e2e/singlePlayer.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/webapp/e2e/singlePlayer.js b/webapp/e2e/singlePlayer.js index 7195376d..103869f0 100644 --- a/webapp/e2e/singlePlayer.js +++ b/webapp/e2e/singlePlayer.js @@ -36,10 +36,10 @@ function delay(time) { // Esperar a que aparezca el botón de inicio de sesión y hacer clic en él await page.waitForSelector('button.MuiButtonBase-root:nth-child(1)'); await page.click('button.MuiButtonBase-root:nth-child(1)'); - + // Esperar a que aparezca el botón de juego individual y hacer clic en él - await page.waitForSelector('button.game-page-button:nth-child(1)'); - await page.click('button.game-page-button:nth-child(1)'); + await page.waitForSelector('a.game-page-button:nth-child(1)'); + await page.click('a.game-page-button:nth-child(1)'); // Esperar a que aparezca el botón "add bot" y hacer clic en él await page.waitForSelector('.add-bot-button');