Skip to content

Commit

Permalink
Vuelta a como estaba antes
Browse files Browse the repository at this point in the history
  • Loading branch information
uo287627 committed Apr 28, 2024
1 parent cf622cf commit 35e7349
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions webapp/src/components/RankingList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { render, screen, waitFor, act } from '@testing-library/react';
import RankingList from './RankingList';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import exp from 'constants';

jest.mock('axios');

Expand Down Expand Up @@ -49,7 +48,7 @@ describe('RankingList', () => {

async function renderRankingList() {
await act(async () => {
render(<RankingList setError={() => {}} />);
render(<RankingList setError={emptyFunction} />);
});
}

Expand Down Expand Up @@ -116,7 +115,14 @@ describe('RankingList', () => {

});

async function expectOrder(header) {
test('show users ordered by "username" correctly', async () => {
await renderRankingList();
const usernameHeader = screen.getByRole('columnheader', { name: /Nombre de Usuario/i });

await act(async() => {
usernameHeader.click(); // DESC
});

// We wait for the users to be loaded and the table to be updated
let rows = await screen.findAllByRole('row');

Expand All @@ -127,7 +133,7 @@ describe('RankingList', () => {
expect(rows[1]).toHaveTextContent('troll');

await act(async() => {
header.click(); // ASC
usernameHeader.click(); // ASC
});

// We wait for the users to be loaded and the table to be updated
Expand All @@ -138,17 +144,7 @@ describe('RankingList', () => {
expect(rows[2]).toHaveTextContent('maría');
expect(rows[3]).toHaveTextContent('pedro');
expect(rows[4]).toHaveTextContent('troll');
}

test('show users ordered by "username" correctly', async () => {
await renderRankingList();
const usernameHeader = screen.getByRole('columnheader', { name: /Nombre de Usuario/i });

await act(async() => {
usernameHeader.click(); // DESC
});

expectOrder(usernameHeader);
});

test('show users ordered by "porcentajeAciertos" correctly', async () => {
Expand All @@ -159,7 +155,28 @@ describe('RankingList', () => {
porcentajeAciertosHeader.click(); // ASC
});

expectOrder(porcentajeAciertosHeader);
// We wait for the users to be loaded and the table to be updated
let rows = await screen.findAllByRole('row');

// We check if the first row is the one with the username 'troll'
expect(rows[4]).toHaveTextContent('manuel');
expect(rows[3]).toHaveTextContent('maría');
expect(rows[2]).toHaveTextContent('pedro');
expect(rows[1]).toHaveTextContent('troll');

await act(async() => {
porcentajeAciertosHeader.click(); // DESC
});

// We wait for the users to be loaded and the table to be updated
rows = await screen.findAllByRole('row');

// We check if the first row is the one with the username 'manuel'
expect(rows[1]).toHaveTextContent('manuel');
expect(rows[2]).toHaveTextContent('maría');
expect(rows[3]).toHaveTextContent('pedro');
expect(rows[4]).toHaveTextContent('troll');

});

test('show users ordered by "preguntasCorrectas" correctly', async () => {
Expand Down

0 comments on commit 35e7349

Please sign in to comment.