generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #241 from Arquisoft/test-run-daniel-6
Ranking added and its tests
- Loading branch information
Showing
12 changed files
with
164 additions
and
771 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"presets": [ | ||
"@babel/preset-env", | ||
"@babel/preset-react" | ||
], | ||
"plugins": [ | ||
"@babel/plugin-proposal-private-property-in-object" | ||
] | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,3 +37,4 @@ describe('NavBar component', () => { | |
expect(window.location.pathname).toBe('/'); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import axios from 'axios'; | ||
import Ranking from '../../pages/Ranking.js'; | ||
|
||
jest.mock('axios'); | ||
|
||
it('fetches ranking from an API and displays them', async () => { | ||
const ranking = [ | ||
{ username: 'User1', totalScore: 100 }, | ||
{ username: 'User2', totalScore: 90 }, | ||
// Add more users if needed | ||
]; | ||
|
||
axios.get.mockResolvedValueOnce({ data: { rank: ranking } }); | ||
|
||
render(<Ranking />); | ||
|
||
const listItemElements = await screen.findAllByRole('listitem'); | ||
|
||
expect(listItemElements).toHaveLength(ranking.length); | ||
|
||
listItemElements.forEach((listItemElement, index) => { | ||
expect(listItemElement).toHaveTextContent(`${ranking[index].username.toUpperCase()}: ${ranking[index].totalScore}`); | ||
}); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import axios from 'axios'; | ||
import {Container, Typography } from '@mui/material'; | ||
|
||
const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; | ||
|
||
const Ranking = () => { | ||
|
||
const [ranking, setRanking] = useState([]); | ||
|
||
useEffect(() => { | ||
const fetchRanking = async () => { | ||
axios.get(`${apiEndpoint}/user/ranking`) | ||
.then((response) => { | ||
const resp = response.data; | ||
setRanking(resp.rank); | ||
}) | ||
.catch((error) => { | ||
console.error(error); | ||
}); | ||
}; | ||
|
||
fetchRanking(); | ||
}, []); | ||
|
||
return ( | ||
<Container sx={{ | ||
display: "flex", | ||
flexDirection: "column", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
flexGrow: 1, | ||
gap: "2em", | ||
padding:"6vh" | ||
}}> | ||
<Typography variant="h3" align="center" fontWeight="bold">RANKING</Typography> | ||
|
||
<ol> | ||
<strong> | ||
{ranking.slice(0,10).map((user, index) => ( // Show only the top 10 users | ||
<li key={index}> | ||
{user.username.toUpperCase()}: {user.totalScore} | ||
</li> | ||
))} | ||
</strong> | ||
</ol> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default Ranking; |