generated 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 #27 from Arquisoft/zohaib
Mejora de coverage y otros ajustes menores
- Loading branch information
Showing
14 changed files
with
249 additions
and
28 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
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 |
---|---|---|
|
@@ -39,5 +39,4 @@ | |
transition: all 0.3s ease-out; | ||
background: #fff; | ||
color: #242424; | ||
transition: 250ms; | ||
} |
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,36 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
import CardItem from './CardItem'; | ||
|
||
describe('Componente CardItem', () => { | ||
const mockProps = { | ||
path: '/test-path', | ||
label: 'Test Label', | ||
src: 'test-img.jpg', | ||
text: 'Test Text' | ||
}; | ||
|
||
test('Renderiza correctamente con los props dados', () => { | ||
render( | ||
<BrowserRouter> | ||
<CardItem {...mockProps} /> | ||
</BrowserRouter> | ||
); | ||
|
||
// Verifica que el componente Link lleve a la ruta correcta | ||
expect(screen.getByRole('link')).toHaveAttribute('href', mockProps.path); | ||
|
||
// Verifica que la imagen tenga el src correcto y alt text vacío | ||
expect(screen.getByRole('img')).toHaveAttribute('src', mockProps.src); | ||
expect(screen.getByRole('img')).toHaveAttribute('alt', ''); | ||
|
||
// Verifica que el texto sea correcto | ||
expect(screen.getByText(mockProps.text)).toBeInTheDocument(); | ||
|
||
// Encuentra el elemento por su atributo data-category usando mockProps.label | ||
// y verifica que el contenido sea correcto | ||
const figure = document.querySelector(`[data-category='${mockProps.label}']`); | ||
expect(figure).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,23 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import Layout from './Layout'; | ||
|
||
// Mock del componente Navbar para controlar su salida en el test | ||
jest.mock('./Navbar', () => () => <div data-testid="navbar">Navbar</div>); | ||
|
||
describe('Componente Layout', () => { | ||
test('Renderiza el Navbar y el contenido de children correctamente', () => { | ||
const childText = 'Contenido de prueba'; | ||
render( | ||
<Layout> | ||
<div>{childText}</div> | ||
</Layout> | ||
); | ||
|
||
// Verifica que el Navbar se renderiza correctamente | ||
expect(screen.getByTestId('navbar')).toBeInTheDocument(); | ||
|
||
// Verifica que el contenido de children se renderiza correctamente | ||
expect(screen.getByText(childText)).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,38 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
import { AuthContext } from '../AuthContext'; | ||
import Logout from './Logout'; | ||
|
||
|
||
// Mocks para las funciones que serán utilizadas por el componente | ||
const mockHandleLogout = jest.fn(); | ||
const mockNavigate = jest.fn(); | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useNavigate: () => mockNavigate, | ||
})); | ||
|
||
// Prueba para el componente Logout | ||
describe('Logout Component', () => { | ||
beforeEach(() => { | ||
// Limpiar mocks antes de cada prueba | ||
mockHandleLogout.mockClear(); | ||
mockNavigate.mockClear(); | ||
}); | ||
|
||
it('Llama a handleLogout y navega a la página de inicio en Mount', () => { | ||
render( | ||
<BrowserRouter> | ||
<AuthContext.Provider value={{ handleLogout: mockHandleLogout }}> | ||
<Logout /> | ||
</AuthContext.Provider> | ||
</BrowserRouter> | ||
); | ||
|
||
// Verificar si handleLogout y navigate fueron llamados correctamente | ||
expect(mockHandleLogout).toHaveBeenCalledTimes(1); | ||
expect(mockNavigate).toHaveBeenCalledWith('/'); | ||
}); | ||
}); |
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,66 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import { BrowserRouter as Router } from 'react-router-dom'; | ||
import Navbar from './Navbar'; | ||
import { AuthContext } from '../AuthContext'; | ||
|
||
// Función mock para simular el contexto de autenticación | ||
const mockContext = (isLoggedIn) => ({ | ||
isLoggedIn | ||
}); | ||
|
||
// Función de utilidad para renderizar el Navbar bajo diferentes condiciones | ||
const renderNavbar = (contextValue, width = 1024) => { | ||
window.innerWidth = width; // Simula el ancho de la ventana para pruebas de responsividad | ||
return render( | ||
<AuthContext.Provider value={mockContext(contextValue)}> | ||
<Router> | ||
<Navbar /> | ||
</Router> | ||
</AuthContext.Provider> | ||
); | ||
}; | ||
|
||
describe('Componente Navbar', () => { | ||
test('Se muestra correctamente cuando el usuario está logueado', () => { | ||
renderNavbar(true); | ||
|
||
expect(screen.getByRole('link', { name: 'Inicio' })).toBeInTheDocument(); | ||
expect(screen.getByRole('button', { name: 'Salir' })).toBeInTheDocument(); | ||
expect(screen.getByRole('link', { name: 'Historial' })).toBeInTheDocument(); | ||
expect(screen.getByRole('link', { name: 'Jugar' })).toBeInTheDocument(); | ||
}); | ||
|
||
test('Reacciona correctamente al redimensionar la ventana cuando el usuario está logueado', () => { | ||
renderNavbar(true, 500); | ||
|
||
fireEvent.click(screen.getByRole('button', { name: /Menu toggle/i })); | ||
expect(screen.getByRole('link', { name: 'Salir' })).toBeInTheDocument(); | ||
expect(screen.getByRole('link', { name: 'Historial' })).toBeInTheDocument(); | ||
expect(screen.getByRole('link', { name: 'Jugar' })).toBeInTheDocument(); | ||
expect(screen.getByRole('link', { name: 'Inicio' })).toBeInTheDocument(); | ||
expect(screen.queryByRole('button', { name: 'Salir' })).not.toBeInTheDocument(); | ||
}); | ||
|
||
test('Se muestra correctamente cuando el usuario no está logueado', () => { | ||
renderNavbar(false); | ||
expect(screen.getByRole('link', { name: 'Inicio' })).toBeInTheDocument(); | ||
expect(screen.getByRole('button', { name: 'Registrarse' })).toBeInTheDocument(); | ||
expect(screen.getByRole('button', { name: 'Entrar' })).toBeInTheDocument(); | ||
expect(screen.queryByRole('button', { name: 'Salir' })).not.toBeInTheDocument(); | ||
expect(screen.queryByRole('link', { name: 'Historial' })).not.toBeInTheDocument(); | ||
expect(screen.queryByRole('link', { name: 'Jugar' })).not.toBeInTheDocument(); | ||
}); | ||
test('Reacciona correctamente al redimensionar la ventana cuando el usuario no está logueado', () => { | ||
renderNavbar(false, 500); | ||
|
||
fireEvent.click(screen.getByRole('button', { name: /Menu toggle/i })); | ||
expect(screen.getByRole('link', { name: 'Inicio' })).toBeInTheDocument(); | ||
expect(screen.getByRole('link', { name: 'Registrarse' })).toBeInTheDocument(); | ||
expect(screen.getByRole('link', { name: 'Entrar' })).toBeInTheDocument(); | ||
expect(screen.queryByRole('link', { name: 'Historial' })).not.toBeInTheDocument(); | ||
expect(screen.queryByRole('link', { name: 'Jugar' })).not.toBeInTheDocument(); | ||
expect(screen.queryByRole('button', { name: 'Registrarse' })).not.toBeInTheDocument(); | ||
expect(screen.queryByRole('button', { name: 'Entrar' })).not.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
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,45 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
import Error404Page from './Error404Page'; | ||
|
||
const mockNavigate = jest.fn(); | ||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useNavigate: () => mockNavigate, | ||
})); | ||
describe('Error404Page Tests', () => { | ||
beforeEach(() => { | ||
// Limpiar mocks antes de cada prueba | ||
mockNavigate.mockClear(); | ||
}); | ||
|
||
test('renders 404 message', () => { | ||
render( | ||
<BrowserRouter> | ||
<Error404Page /> | ||
</BrowserRouter> | ||
); | ||
|
||
// Verifica que el mensaje de 404 esté presente | ||
expect(screen.getByText(/404 - ¡Ups! Te quedaste sin oxígeno/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/La página que estas buscando está fuera de nuestro alcance/i)).toBeInTheDocument(); | ||
}); | ||
test('Go home after 15 seconds', () => { | ||
render( | ||
<BrowserRouter> | ||
<Error404Page initialCountdown={0} /> | ||
</BrowserRouter> | ||
); | ||
|
||
expect(mockNavigate).toHaveBeenCalledWith('/'); | ||
}); | ||
|
||
|
||
|
||
}); | ||
|
||
async function wait(milliseconds) { | ||
jest.advanceTimersByTime(milliseconds); | ||
} |
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