diff --git a/webapp/src/pages/Perfil/Perfil.test.js b/webapp/src/pages/Perfil/Perfil.test.js index ba00ad8c..9bc8130e 100644 --- a/webapp/src/pages/Perfil/Perfil.test.js +++ b/webapp/src/pages/Perfil/Perfil.test.js @@ -69,6 +69,34 @@ describe('Perfil Component', () => { expect(screen.getByText('No hay partidas recientes.')).toBeInTheDocument(); }); }); + + test('displays recent calculator game data', async () => { + const mockUserData = { + username: 'testUser', + createdAt: new Date(), + games: [ + { gamemode: 'calculadora', points: 15, avgTime: 8.5 } + ] + }; + + jest.spyOn(global, 'fetch').mockResolvedValueOnce({ + json: jest.fn().mockResolvedValueOnce(mockUserData), + }); + + render( + + + + ); + + await waitFor(() => { + expect(screen.getByText('calculadora')).toBeInTheDocument(); + const dashCells = screen.getAllByText('-'); + expect(dashCells.length).toBe(2); + expect(screen.getByText('15')).toBeInTheDocument(); + expect(screen.getByText('8.50 segundos')).toBeInTheDocument(); + }); + }); }); \ No newline at end of file diff --git a/webapp/src/pages/Ranking/Ranking.test.js b/webapp/src/pages/Ranking/Ranking.test.js index 25da9631..3c987643 100644 --- a/webapp/src/pages/Ranking/Ranking.test.js +++ b/webapp/src/pages/Ranking/Ranking.test.js @@ -74,5 +74,21 @@ describe('Ranking component', () => { expect(screen.getByText('Ranking - modo Batería de sabios')).toBeInTheDocument(); }); }); + + test('changes gamemode when clicking on mode buttons, clicks on Human Calculator button', async () => { + global.fetch.mockResolvedValueOnce({ json: () => Promise.resolve(mockData) }); + + renderComponent(); + + await assertRankingTableWithData(); + + const calculatorButton = screen.getByRole('button', { name: 'Calculadora humana' }); + fireEvent.click(calculatorButton); + + await waitFor(() => { + expect(screen.getByText('Ranking - modo Calculadora humana')).toBeInTheDocument(); + expect(screen.queryByText('Ratio de aciertos (%)')).toBeNull(); // Asegura que no se muestra la opción de filtrar por ratio de aciertos + }); + }); }); diff --git a/webapp/src/pages/Stats/Stats.test.js b/webapp/src/pages/Stats/Stats.test.js index 8a6a57ff..e3fcfb5b 100644 --- a/webapp/src/pages/Stats/Stats.test.js +++ b/webapp/src/pages/Stats/Stats.test.js @@ -124,4 +124,47 @@ describe('Stats component', () => { expect(screen.queryByText('Estadísticas de testUser - modo Batería de sabios')).toBeInTheDocument(); }); }); + + test('fetches and displays user statistics for Human Calculator mode', async () => { + localStorage.setItem('username', 'testUser'); + + userData.ratioCorrect=0; + userData.totalCorrectQuestions=0; + userData.totalIncorrectQuestions=0; + + global.fetch = jest.fn().mockResolvedValue({ + json: jest.fn().mockResolvedValue(userData) + }); + + renderComponentWithRouter(); + + await waitFor(() => { + expect(screen.queryByText('Cargando ...')).not.toBeInTheDocument(); + }); + + const modeButton = screen.getByRole('button', { name: /Calculadora humana/i }); + userEvent.click(modeButton); + + const table = await screen.findByRole('table'); + expect(table).toBeInTheDocument(); + + const columnHeaders = ['Partidas jugadas', 'Puntos por partida', 'Puntos totales', 'Tiempo por pregunta (s):']; + columnHeaders.forEach(headerText => { + const headerElement = screen.getByText(headerText); + expect(headerElement).toBeInTheDocument(); + }); + + Object.entries(userData).forEach(([key, value]) => { + if (key !== 'username') { + if (key === 'avgPoints' || key === 'avgTime') { + const valueElements = screen.getAllByText(value.toFixed(2)); + expect(valueElements.length).toBeGreaterThan(0); + } else { + const valueElements = screen.getAllByText(value.toString()); + expect(valueElements.length).toBeGreaterThan(0); + } + } + }); +}); + });