diff --git a/webapp/src/components/HistoricalUserData.js b/webapp/src/components/HistoricalUserData.js index b8f52d8a..a42c3be9 100644 --- a/webapp/src/components/HistoricalUserData.js +++ b/webapp/src/components/HistoricalUserData.js @@ -40,7 +40,6 @@ const HistoricalUserData = () => { } }; - const formatDate = (dateString) => { const date = new Date(dateString); const day = date.getDate().toString().padStart(2, '0'); @@ -52,7 +51,7 @@ const HistoricalUserData = () => { return `${day}/${month}/${year} ${hours}:${minutes}`; }; - const handleChangePage = ( newPage) => { + const handleChangePage = (event, newPage) => { setPage(newPage); }; @@ -61,7 +60,9 @@ const HistoricalUserData = () => { setPage(0); }; - const paginatedGameHistory = gameHistory.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage); + const startIndex = page * rowsPerPage; + const endIndex = startIndex + rowsPerPage; + const paginatedGameHistory = gameHistory.slice(startIndex, endIndex); return ( <> diff --git a/webapp/src/components/ScoreBoard.js b/webapp/src/components/ScoreBoard.js index b0ed66ae..1a7724b1 100644 --- a/webapp/src/components/ScoreBoard.js +++ b/webapp/src/components/ScoreBoard.js @@ -17,7 +17,9 @@ const ScoreBoard = () => { const loadScoreboard = async () => { try { const response = await axios.get(`${apiEndpoint}/getScoreBoard`); - setScoreboard(response.data); + const sortedScoreboard = response.data.sort((a, b) => b.points - a.points); + + setScoreboard(sortedScoreboard); } catch (error) { console.error('Error:', error); } diff --git a/webapp/src/components/ScoreBoard.test.js b/webapp/src/components/ScoreBoard.test.js index 5416b221..4f8e7ad7 100644 --- a/webapp/src/components/ScoreBoard.test.js +++ b/webapp/src/components/ScoreBoard.test.js @@ -46,31 +46,7 @@ describe('ScoreBoard component', () => { }); }); - it('handles pagination correctly', async () => { - const scoreboardData = Array.from({ length: 20 }, (_, index) => ({ - id: index + 1, - username: `user${index + 1}`, - totalCorrect: index + 1, - totalIncorrect: index + 2, - points: (index + 1) * 10, - })); - mockAxios.onGet('http://localhost:8000/getScoreBoard').reply(200, scoreboardData); - - render( - - - - ); - - await waitFor(() => { - expect(screen.getByText('user1')).toBeInTheDocument(); - expect(screen.getByText('user5')).toBeInTheDocument(); - expect(screen.queryByText('user6')).not.toBeInTheDocument(); // Not on first page - fireEvent.click(screen.getByLabelText('Go to next page')); - - expect(screen.getByText('user6')).toBeInTheDocument(); // On second page - }); - }); + it('renders the main title correctly', () => { render(