From 5b0d192320badd84fc0831b479e0f9e33fc9f548 Mon Sep 17 00:00:00 2001 From: Marcos Barril Villaverde Date: Wed, 1 May 2024 21:13:44 +0200 Subject: [PATCH] Increased coverage --- webapp/src/usersRanking/test/App.test.jsx | 66 +++++++++++++++++++++-- 1 file changed, 61 insertions(+), 5 deletions(-) diff --git a/webapp/src/usersRanking/test/App.test.jsx b/webapp/src/usersRanking/test/App.test.jsx index e5c6834b..b9df4344 100644 --- a/webapp/src/usersRanking/test/App.test.jsx +++ b/webapp/src/usersRanking/test/App.test.jsx @@ -14,10 +14,10 @@ describe('App', () => { const mockUser = Array.from({ length: 20 }, (_, index) => ({ _id: String(index + 1), username: `User ${index + 1}`, - tpoints: 100, - avgpoints: 100, - ttime: 100, - avgtime: 100, + tpoints: 100 + index, + avgpoints: 100 + index, + ttime: 100 - index, + avgtime: 100 - index, createdAt: '05/04/2024', })); @@ -81,6 +81,61 @@ describe('App', () => { }); + test('sorts users by username', async () => { + const { getByText } = render(); + + userEvent.click(getByText('Nombre de Usuario')); + + await waitFor(() => { + expect(getByText('User 10')).toBeInTheDocument(); + expect(getByText('User 11')).toBeInTheDocument(); + }); + }); + + test('sorts users by tpoints', async () => { + const { getByText } = render(); + + userEvent.click(getByText('Puntos totales')); + + await waitFor(() => { + expect(getByText('User 1')).toBeInTheDocument(); + expect(getByText('User 10')).toBeInTheDocument(); + }); + }); + + test('sorts users by avgpoints', async () => { + const { getByText } = render(); + + userEvent.click(getByText('Puntos promedio')); + + await waitFor(() => { + expect(getByText('User 11')).toBeInTheDocument(); + expect(getByText('User 20')).toBeInTheDocument(); + }); + }); + + test('sorts users by ttime', async () => { + const { getByText } = render(); + + userEvent.click(getByText('Tiempo Total')); + + await waitFor(() => { + expect(getByText('User 1')).toBeInTheDocument(); + expect(getByText('User 10')).toBeInTheDocument(); + }); + }); + + test('sorts users by avgtime', async () => { + const { getByText } = render(); + + userEvent.click(getByText('Tiempo promedio')); + + await waitFor(() => { + expect(getByText('User 1')).toBeInTheDocument(); + expect(getByText('User 10')).toBeInTheDocument(); + }); + }); + }); test('handles unknown error when fetching users', async () => { @@ -99,4 +154,5 @@ test('handles error with response.data.error when fetching users', async () => { render(); expect(axios.get).toHaveBeenCalledWith('http://localhost:8100/usersStats'); -}); \ No newline at end of file +}); +