Skip to content

Commit

Permalink
Added user for userContext in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
uo289267 committed Apr 18, 2024
1 parent 4c54efc commit 70a03a1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion webapp/src/components/ranking/RankingView.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const RankingView = () => {
try {
var ranking = await retriever.getTopTen();
setRankingData(ranking.usersCompetitiveStats);
var myrank = await retriever.getMyPosition("user");
var myrank = await retriever.getMyPosition(user.username);
setMyRankingData(myrank);
console.log(myrank)
} catch (error) {
Expand Down
15 changes: 8 additions & 7 deletions webapp/src/components/ranking/RankingView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('RankingView component', () => {

it('renders title', () => {
act(()=>{
render(<UserContextProvider><MemoryRouter><RankingView /></MemoryRouter></UserContextProvider>);
render(<UserContextProvider ><MemoryRouter><RankingView /></MemoryRouter></UserContextProvider>);
})
const text = screen.getByText(i18en.t('ranking.ranking'));
expect(text).toBeInTheDocument();
Expand Down Expand Up @@ -93,18 +93,19 @@ describe('RankingView component', () => {
]
});

mockAxios.onGet('http://localhost:8000/record/ranking/user').reply(200,
mockAxios.onGet('http://localhost:8000/record/ranking/myUser').reply(200,
{
"_id": "myUser",
"totalPoints": 250,
"totalCompetitiveGames": 1
}
);
const user = { username: 'myUser' };

it('renders position all headers in the table',async ()=>{

await act(async () =>{
await render(<UserContextProvider><MemoryRouter><RankingView /></MemoryRouter></UserContextProvider>);
await render(<UserContextProvider baseUser={user}><MemoryRouter><RankingView /></MemoryRouter></UserContextProvider>);

})
await waitFor(() => expect(screen.getByText(i18en.t('ranking.position'))).toBeInTheDocument());
Expand All @@ -114,7 +115,7 @@ describe('RankingView component', () => {
});
it('renders position all users usernames',async ()=>{
await act(async () =>{
await render(<UserContextProvider><MemoryRouter><RankingView /></MemoryRouter></UserContextProvider>);
await render(<UserContextProvider baseUser={user}><MemoryRouter><RankingView /></MemoryRouter></UserContextProvider>);

})
await waitFor(() => expect(screen.getByText(i18en.t('ranking.position'))).toBeInTheDocument());
Expand All @@ -132,7 +133,7 @@ describe('RankingView component', () => {
it('renders position all users totalPoints',async ()=>{

await act(async () =>{
await render(<UserContextProvider><MemoryRouter><RankingView /></MemoryRouter></UserContextProvider>);
await render(<UserContextProvider baseUser={user}><MemoryRouter><RankingView /></MemoryRouter></UserContextProvider>);

})
await waitFor(() => expect(screen.getByText(i18en.t('ranking.position'))).toBeInTheDocument());
Expand All @@ -149,7 +150,7 @@ describe('RankingView component', () => {
it('renders position all users competitive games',async ()=>{

await act(async () =>{
await render(<UserContextProvider><MemoryRouter><RankingView /></MemoryRouter></UserContextProvider>);
await render(<UserContextProvider baseUser={user}><MemoryRouter><RankingView /></MemoryRouter></UserContextProvider>);

})
await waitFor(() => expect(screen.getByText(i18en.t('ranking.position'))).toBeInTheDocument());
Expand All @@ -162,7 +163,7 @@ describe('RankingView component', () => {
it('renders position all users competitive games',async ()=>{

await act(async () =>{
await render(<UserContextProvider><MemoryRouter><RankingView /></MemoryRouter></UserContextProvider>);
await render(<UserContextProvider baseUser={user}><MemoryRouter><RankingView /></MemoryRouter></UserContextProvider>);

})
await waitFor(() => expect(screen.getByText(i18en.t('ranking.position'))).toBeInTheDocument());
Expand Down

0 comments on commit 70a03a1

Please sign in to comment.