forked 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 #146 from Arquisoft/Ruben
Nuevos tests index y Ranking y solucionados errores menores
- Loading branch information
Showing
8 changed files
with
133 additions
and
31 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 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 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,61 @@ | ||
import React from 'react'; | ||
import { render, waitFor, act } from '@testing-library/react'; | ||
import Ranking from './Ranking'; | ||
import axios from 'axios'; | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import { BrowserRouter as Router } from 'react-router-dom'; | ||
import { UserProvider } from './UserContext'; | ||
import { I18nextProvider } from "react-i18next"; | ||
import i18n from "../translations/i18n"; | ||
|
||
const mock = new MockAdapter(axios); | ||
|
||
describe('Ranking test', () => { | ||
it('renders correctly', async () => { | ||
mock.onGet('http://localhost:8000/topUsers').reply(200, { | ||
topUsers: [ | ||
{ userId: 'usuario1', ratio: 80 }, | ||
{ userId: 'usuario2', ratio: 75 }, | ||
{ userId: 'usuario3', ratio: 70 }, | ||
], | ||
}); | ||
|
||
mock.onGet('http://localhost:8000/ranking').reply(200, | ||
[ | ||
{ userId: 'usuario1', totalGamesPlayed: 10, totalQuestionsAnswered: 50, totalRightQuestions: 40, ratio: '80%', totalTime: '100s' }, | ||
{ userId: 'usuario2', totalGamesPlayed: 12, totalQuestionsAnswered: 60, totalRightQuestions: 45, ratio: '75%', totalTime: '120s' }, | ||
]); | ||
|
||
const { getByText, getByLabelText } = render( | ||
<I18nextProvider i18n={i18n}> | ||
<UserProvider> | ||
<Router> | ||
<Ranking /> | ||
</Router> | ||
</UserProvider> | ||
</I18nextProvider>); | ||
|
||
await waitFor(() => { | ||
expect(getByLabelText('Número de usuarios')).toBeInTheDocument(); | ||
expect(getByText('Posición')).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('can handle errors', async () => { | ||
mock.onGet('http://localhost:8000/ranking').reply(500, {error: "Error al obtener el ranking"}); | ||
|
||
const { getByText } = render( | ||
<I18nextProvider i18n={i18n}> | ||
<UserProvider> | ||
<Router> | ||
<Ranking /> | ||
</Router> | ||
</UserProvider> | ||
</I18nextProvider>); | ||
|
||
await waitFor(() => { | ||
let error = getByText("Error: Error al obtener el ranking"); | ||
expect(error).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
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,54 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'; | ||
import { I18nextProvider } from 'react-i18next'; | ||
import { UserProvider } from './components/UserContext'; | ||
import i18next from './translations/i18n'; | ||
import NavigationBar from './components/fragments/NavigationBar'; | ||
import Footer from './components/fragments/Footer'; | ||
import PantallaInicio from './components/PantallaInicio'; | ||
import PantallaInicioAdmin from './components/PantallaInicioAdmin'; | ||
import Login from './components/Login'; | ||
import AddUser from './components/AddUser'; | ||
import App from './App'; | ||
import Game from './components/Game'; | ||
import EndGame from './components/EndGame'; | ||
import Gamehistory from './components/Gamehistory'; | ||
import Perfil from './components/Perfil'; | ||
import AllUsers from './components/AllUsers'; | ||
import AllQuestions from './components/AllQuestions'; | ||
import Ranking from './components/Ranking'; | ||
import GameConfiguration from './components/GameConfiguration'; | ||
|
||
describe('Root component', () => { | ||
it('renders all routes correctly', () => { | ||
render( | ||
<Router> | ||
<React.StrictMode> | ||
<I18nextProvider i18n={i18next}> | ||
<UserProvider> | ||
<NavigationBar /> | ||
<Routes> | ||
<Route path="/" element={<App />} /> | ||
<Route path="/PantallaInicio" element={<PantallaInicio />} /> | ||
<Route path="/PantallaInicioAdmin" element={<PantallaInicioAdmin />} /> | ||
<Route path="/Login" element={<Login />} /> | ||
<Route path="/AddUser" element={<AddUser />} /> | ||
<Route path="/App" element={<App />} /> | ||
<Route path="/Game" element={<Game />} /> | ||
<Route path="/EndGame" element={<EndGame />} /> | ||
<Route path="/Gamehistory" element={<Gamehistory />} /> | ||
<Route path="/Perfil" element={<Perfil />} /> | ||
<Route path="/AllUsers" element={<AllUsers />} /> | ||
<Route path="/AllQuestions" element={<AllQuestions />} /> | ||
<Route path="/Ranking" element={<Ranking />} /> | ||
<Route path="/GameConfiguration" element={<GameConfiguration />} /> | ||
</Routes> | ||
<Footer /> | ||
</UserProvider> | ||
</I18nextProvider> | ||
</React.StrictMode> | ||
</Router> | ||
); | ||
}); | ||
}); |