Skip to content

Commit

Permalink
Made the default search value the username and fixed bad mock on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Mario committed Apr 21, 2024
1 parent 3801d71 commit e407b7b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
9 changes: 5 additions & 4 deletions webapp/src/components/ranking/RankingView.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ import { useUserContext } from '../loginAndRegistration/UserContext';
const retriever = new RankingRetriever();

const RankingView = () => {
const[t] = useTranslation("global");
const {user} = useUserContext();

const [rankingData, setRankingData] = useState(null);
const [myRankingData, setMyRankingData] = useState(null);
const [searchTerm, setSearchTerm] = useState(""); // Nuevo estado para el término de búsqueda
const [searchTerm, setSearchTerm] = useState(user.username);


const[t] = useTranslation("global");
const {user} = useUserContext();

const getRanking = async () => {
try {
var ranking = await retriever.getTopTen();
setRankingData(ranking.usersCompetitiveStats);
var myrank = await retriever.getUser(user.username);
setMyRankingData(myrank);
console.log(myrank)
} catch (error) {
console.log(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 @@ -18,24 +18,23 @@ global.i18en = i18en;

const mockAxios = new MockAdapter(axios);
describe('RankingView component', () => {
const user = { username: 'myUser' };

it('renders title', () => {
act(()=>{
render(<UserContextProvider ><MemoryRouter><RankingView /></MemoryRouter></UserContextProvider>);
render(<UserContextProvider baseUser={user}><MemoryRouter><RankingView /></MemoryRouter></UserContextProvider>);
})
const text = screen.getByText(i18en.t('ranking.ranking'));
expect(text).toBeInTheDocument();
});
it('renders Loading if the call to the gateway has not been done', () => {
act(()=>{
render(<UserContextProvider><MemoryRouter><RankingView /></MemoryRouter></UserContextProvider>);
render(<UserContextProvider baseUser={user}><MemoryRouter><RankingView /></MemoryRouter></UserContextProvider>);
})
const text = screen.getByText('Loading...');
expect(text).toBeInTheDocument();
});
});

describe('RankingView component with endpoint', ()=>{
mockAxios.onGet('http://localhost:8000/record/ranking/top10').reply(200,
{
Expand Down Expand Up @@ -94,7 +93,7 @@ describe('RankingView component', () => {
});

mockAxios.onGet('http://localhost:8000/record/ranking/myUser').reply(200,
{usersCompetitiveStats:
{userCompetitiveStats:
{
"_id": "myUser",
"totalPoints": 250,
Expand All @@ -111,11 +110,12 @@ describe('RankingView component', () => {
await render(<UserContextProvider baseUser={user}><MemoryRouter><RankingView /></MemoryRouter></UserContextProvider>);

})
await waitFor(() => expect(screen.getByText(i18en.t('ranking.position'))).toBeInTheDocument());
await waitFor(() => expect(screen.getByText(i18en.t('ranking.position'))).toBeInTheDocument());
expect(screen.getByText(i18en.t('ranking.username'))).toBeInTheDocument()
expect(screen.getByText(i18en.t('ranking.points'))).toBeInTheDocument()
expect(screen.getByText(i18en.t('ranking.num_games'))).toBeInTheDocument()
});
});

it('renders position all users usernames',async ()=>{
await act(async () =>{
await render(<UserContextProvider baseUser={user}><MemoryRouter><RankingView /></MemoryRouter></UserContextProvider>);
Expand Down Expand Up @@ -177,5 +177,6 @@ describe('RankingView component', () => {
expect(screen.getAllByText(/1/).length).toBeGreaterThanOrEqual(2);//hay dos pq hay una posicion

});

})

0 comments on commit e407b7b

Please sign in to comment.