diff --git a/gatewayservice/monitoring/prometheus/prometheus.yml b/gatewayservice/monitoring/prometheus/prometheus.yml index 3093655..a7ae2c0 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 diff --git a/webapp/e2e/singlePlayer.js b/webapp/e2e/singlePlayer.js index 7195376..103869f 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'); diff --git a/webapp/src/components/game/PlayingGame.test.js b/webapp/src/components/game/PlayingGame.test.js new file mode 100644 index 0000000..2387562 --- /dev/null +++ b/webapp/src/components/game/PlayingGame.test.js @@ -0,0 +1,73 @@ +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')).toHaveTextContent('10'); + + }); + + // Simulate answering question 2 + fireEvent.click(getByTestId('answer-2')); + jest.advanceTimersByTime(10000); + await waitFor(() => { + expect(getByTestId('question')).toBeInTheDocument(); + expect(getByTestId('seconds')).toHaveTextContent('10'); + }); + + // 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')).toHaveTextContent('playing_single_player_you_earned50playing_single_player_points'); + }); + }); + + // Add more test cases for edge cases and multiplayer scenarios if applicable +}); \ No newline at end of file diff --git a/webapp/src/components/group/GroupCreationModal.test.js b/webapp/src/components/group/GroupCreationModal.test.js index ad0a55d..5adff1d 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 e5956d2..bbfc7ed 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')} diff --git a/webapp/src/components/register/Register.test.js b/webapp/src/components/register/Register.test.js index 548b8ae..23065e6 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 5ff5b05..5a4e698 100644 --- a/webapp/src/components/register/Register.tsx +++ b/webapp/src/components/register/Register.tsx @@ -89,7 +89,7 @@ const Register = (props:ActionProps) => { {t('register')} - + {t('return')}
{t('create_group_max_members')}
{t('create_group_description')}