Skip to content

Commit

Permalink
Eliminado el timeout de las estadisticas, añadido botón de buscar
Browse files Browse the repository at this point in the history
  • Loading branch information
iyanfdezz committed Apr 1, 2024
1 parent 662e1f4 commit bfc765e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 12 additions & 1 deletion webapp/src/pages/Stats/Stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const Stats = () => {
const [gamemode, setGamemode] = useState("clasico");
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState(null);
const [fetched,setFetched] = useState(false);

const fetchStats = () => {
setIsLoading(true);
Expand All @@ -28,7 +29,11 @@ const Stats = () => {
};

useEffect(() => {
fetchStats(); // Eliminamos el retardo para la primera llamada
if(!fetched){
fetchStats();
setFetched(true);
}

}, [username, gamemode]);

const handleUsernameChange = (event) => {
Expand All @@ -41,6 +46,10 @@ const Stats = () => {
fetchStats();
};

const handleSearch = () => {
fetchStats();
};

const getModeName = () => {
if(gamemode=="clasico"){
return "Clásico";
Expand Down Expand Up @@ -72,6 +81,7 @@ const Stats = () => {
onChange={handleUsernameChange}
data-testid="usernameInput"
/>
<Button onClick={handleSearch}>Buscar</Button>
<Heading as="h2">Error: {error}</Heading>
<p>
Por favor compruebe si los valores del formulario son correctos e
Expand All @@ -95,6 +105,7 @@ const Stats = () => {
onChange={handleUsernameChange}
data-testid="usernameInput"
/>
<Button onClick={handleSearch}>Buscar</Button>
<div>
<Button
className={gamemode === "clasico" ? "active" : ""}
Expand Down
4 changes: 4 additions & 0 deletions webapp/src/pages/Stats/Stats.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ describe('Stats component', () => {

const newUsername = 'newUser';
localStorage.setItem('username', newUsername);

const searchbutton=await screen.findByText('Buscar');
userEvent.click(searchbutton);

render(
<Router>
Expand Down Expand Up @@ -173,6 +176,7 @@ describe('Stats component', () => {
<Stats />
</Router>
);

await waitFor(() => {
expect(screen.queryByText('Estadísticas de testUser - modo Batería de sabios')).toBeInTheDocument();
});
Expand Down

0 comments on commit bfc765e

Please sign in to comment.