Skip to content

Commit

Permalink
Intento arreglar nuevas issues
Browse files Browse the repository at this point in the history
  • Loading branch information
uo287627 committed Apr 28, 2024
1 parent f815e39 commit 40edf3e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
4 changes: 4 additions & 0 deletions webapp/src/components/GeneratedQuestionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,8 @@ const GeneratedQuestionsList = ({setError}) => {
);
};

GeneratedQuestionsList.propTypes = {
setError: PropTypes.func.isRequired,
};

export default GeneratedQuestionsList;
8 changes: 3 additions & 5 deletions webapp/src/components/Login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,9 @@ describe('Login Component', () => {
fireEvent.click(usersListTab);
});

await waitFor(() => {
tabTexts.forEach(async (tabText) => {
const elements = await screen.findAllByText(new RegExp(tabText, 'i'));
expect(elements.length).toBeGreaterThan(0);
});
await waitFor(async () => {
await Promise.all(tabTexts.map(tabText => screen.findAllByText(new RegExp(tabText, 'i'))))
.then(elementsArray => elementsArray.forEach(elements => expect(elements.length).toBeGreaterThan(0)));
});
}

Expand Down
5 changes: 5 additions & 0 deletions webapp/src/components/RankingList.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,9 @@ const RankingList = ({setError}) => {
);
};


RankingList.propTypes = {
setError: PropTypes.func.isRequired,
};

export default RankingList;
41 changes: 19 additions & 22 deletions webapp/src/components/RankingList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,31 +292,28 @@ describe('RankingList', () => {

}); // fin tests correctos

describe('failing requests', () => {
test('should display an error message when the request fails', async () => {
let errorShown = "";
await act(async () => {
render(<RankingList setError={(errorMsg) => {errorShown=errorMsg}} />);
});
test('should display an error message when the request fails', async () => {
let errorShown = "";
await act(async () => {
render(<RankingList setError={(errorMsg) => {errorShown=errorMsg}} />);
});

// simulate a failed request
mockAxios.onPost('http://localhost:8000/obtainRank').reply(500, { error: 'Internal Server Error' });
// simulate a failed request
mockAxios.onPost('http://localhost:8000/obtainRank').reply(500, { error: 'Internal Server Error' });

// Check if the table headers are in the document
expect(screen.queryByText("Ranking")).toBeInTheDocument();
expect(screen.getByText(/Nombre de Usuario/i)).toBeInTheDocument();
expect(screen.queryAllByText(/Porcentaje de Aciertos/i)).not.toHaveLength(0);
expect(screen.getByText(/Preguntas Correctas/i)).toBeInTheDocument();
expect(screen.getByText(/Preguntas Falladas/i)).toBeInTheDocument();
expect(screen.getByText(/Número de Partidas/i)).toBeInTheDocument();
// Check if the table headers are in the document
expect(screen.queryByText("Ranking")).toBeInTheDocument();
expect(screen.getByText(/Nombre de Usuario/i)).toBeInTheDocument();
expect(screen.queryAllByText(/Porcentaje de Aciertos/i)).not.toHaveLength(0);
expect(screen.getByText(/Preguntas Correctas/i)).toBeInTheDocument();
expect(screen.getByText(/Preguntas Falladas/i)).toBeInTheDocument();
expect(screen.getByText(/Número de Partidas/i)).toBeInTheDocument();

// and no users rows are shown
const rows = await screen.findAllByRole('row');
expect(rows.length).toBe(1);

expect(errorShown).toBe("Error obteniendo el ranking del usuario: TypeError: Cannot read properties of undefined (reading 'status')");
});
// and no users rows are shown
const rows = await screen.findAllByRole('row');
expect(rows.length).toBe(1);

}); // fin tests fallidos
expect(errorShown).toBe("Error obteniendo el ranking del usuario: TypeError: Cannot read properties of undefined (reading 'status')");
});

});
4 changes: 4 additions & 0 deletions webapp/src/components/UsersList.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,8 @@ const UsersList = ({ setError }) => {
);
};

UsersList.propTypes = {
setError: PropTypes.func.isRequired,
};

export default UsersList;

0 comments on commit 40edf3e

Please sign in to comment.