From e48c3b123316e97480dafe3ba9ec3a2a647dd442 Mon Sep 17 00:00:00 2001 From: TheNullPower Date: Fri, 14 Jun 2024 23:54:24 -0600 Subject: [PATCH] Update --- .../rendertestmodall.test.tsx | 123 ++++++++++-------- 1 file changed, 70 insertions(+), 53 deletions(-) diff --git a/saraia/testing_A00833051/rendertestmodall.test.tsx b/saraia/testing_A00833051/rendertestmodall.test.tsx index e984b65..64089eb 100644 --- a/saraia/testing_A00833051/rendertestmodall.test.tsx +++ b/saraia/testing_A00833051/rendertestmodall.test.tsx @@ -1,79 +1,96 @@ +import '@testing-library/jest-dom'; import React from 'react'; -import userEvent from '@testing-library/user-event'; import { render, screen } from '@testing-library/react'; -import '@testing-library/jest-dom/extend-expect'; // Importante para los matchers de jest-dom -import { Avatar, AvatarImage, AvatarFallback } from '@/components/ui/avatar'; - - -global.fetch = jest.fn(); +import { Avatar, AvatarImage, AvatarFallback } from '../components/ui/avatar'; describe('Avatar Component Tests', () => { - // Prueba 1 + // Prueba 1: Renderización del Avatar sin errores test('Avatar renders without crashing', () => { render(); - expect(screen.getByRole('img')).toBeInTheDocument(); + const avatarElement = screen.getByRole('img'); + expect(avatarElement).toBeInTheDocument(); }); - // Prueba 2 - test('Avatar applies custom className', () => { - render(); - const avatar = screen.getByRole('img'); - expect(avatar).toHaveClass('custom-avatar'); + // Prueba 2: Verificación de la clase principal del Avatar + test('Avatar renders with correct base class', () => { + render(); + const avatarElement = screen.getByRole('img'); + expect(avatarElement).toHaveClass('relative'); + expect(avatarElement).toHaveClass('flex'); + expect(avatarElement).toHaveClass('h-10'); + expect(avatarElement).toHaveClass('w-10'); + expect(avatarElement).toHaveClass('shrink-0'); + expect(avatarElement).toHaveClass('overflow-hidden'); + expect(avatarElement).toHaveClass('rounded-full'); }); - // Prueba 3 - test('AvatarImage renders without crashing', () => { - render(); - expect(screen.getByAltText('Avatar')).toBeInTheDocument(); + // Prueba 3: Renderización del AvatarImage + test('AvatarImage renders correctly', () => { + render(); + const avatarImage = screen.getByRole('img'); + expect(avatarImage).toBeInTheDocument(); + expect(avatarImage).toHaveClass('aspect-square'); + expect(avatarImage).toHaveClass('h-full'); + expect(avatarImage).toHaveClass('w-full'); }); - // Prueba 4 - test('AvatarImage applies custom className', () => { - render(); - const image = screen.getByAltText('Avatar'); - expect(image).toHaveClass('custom-image'); + // Prueba 4: Renderización del AvatarFallback + test('AvatarFallback renders correctly', () => { + render(); + const avatarFallback = screen.getByTestId('avatar-fallback'); + expect(avatarFallback).toBeInTheDocument(); + expect(avatarFallback).toHaveClass('flex'); + expect(avatarFallback).toHaveClass('h-full'); + expect(avatarFallback).toHaveClass('w-full'); + expect(avatarFallback).toHaveClass('items-center'); + expect(avatarFallback).toHaveClass('justify-center'); + expect(avatarFallback).toHaveClass('rounded-full'); + expect(avatarFallback).toHaveClass('bg-muted'); }); - // Prueba 5 - test('AvatarFallback renders without crashing', () => { - render(Fallback Content); - expect(screen.getByText('Fallback Content')).toBeInTheDocument(); + // Prueba 5: Comprobación de las propiedades de accesibilidad en AvatarImage + test('AvatarImage accessibility properties', () => { + render(); + const avatarImage = screen.getByRole('img'); + expect(avatarImage).toHaveAttribute('src', '/avatar.jpg'); + expect(avatarImage).toHaveAttribute('alt', 'Avatar'); }); - // Prueba 6 - test('AvatarFallback applies custom className', () => { - render(Fallback Content); - const fallback = screen.getByText('Fallback Content'); - expect(fallback).toHaveClass('custom-fallback'); + // Prueba 6: Comprobación de las propiedades de accesibilidad en AvatarFallback + test('AvatarFallback accessibility properties', () => { + render(); + const avatarFallback = screen.getByTestId('avatar-fallback'); + expect(avatarFallback).toHaveAttribute('aria-busy', 'true'); + expect(avatarFallback).toHaveAttribute('aria-live', 'polite'); }); - // Prueba 7 - test('Avatar renders with default size', () => { - render(); - const avatar = screen.getByRole('img'); - expect(avatar).toHaveStyle('height: 10px'); - expect(avatar).toHaveStyle('width: 10px'); + // Prueba 7: AvatarImage y AvatarFallback se muestran correctamente juntos + test('Avatar renders AvatarImage and AvatarFallback correctly', () => { + render(); + const avatarImage = screen.getByRole('img'); + const avatarFallback = screen.getByTestId('avatar-fallback'); + expect(avatarImage).toBeInTheDocument(); + expect(avatarFallback).toBeInTheDocument(); }); - // Prueba 8 - test('Avatar renders with custom size', () => { - render(); - const avatar = screen.getByRole('img'); - expect(avatar).toHaveStyle('height: 20px'); - expect(avatar).toHaveStyle('width: 20px'); + // Prueba 8: Verificación de las clases personalizadas en AvatarImage + test('AvatarImage renders with custom class', () => { + render(); + const avatarImage = screen.getByRole('img'); + expect(avatarImage).toHaveClass('custom-avatar-image'); }); - // Prueba 9 - test('AvatarFallback renders with default background color', () => { - render(); - const fallback = screen.getByTestId('avatar-fallback'); - expect(fallback).toHaveClass('bg-muted'); + // Prueba 9: Verificación de las clases personalizadas en AvatarFallback + test('AvatarFallback renders with custom class', () => { + render(); + const avatarFallback = screen.getByTestId('avatar-fallback'); + expect(avatarFallback).toHaveClass('custom-avatar-fallback'); }); - // Prueba 10 - test('AvatarFallback renders with custom background color', () => { - render(Fallback Content); - const fallback = screen.getByText('Fallback Content'); - expect(fallback).toHaveStyle('background-color: blue'); + // Prueba 10: AvatarFallback se renderiza correctamente si no se proporciona AvatarImage + test('AvatarFallback renders when AvatarImage is not provided', () => { + render(); + const avatarFallback = screen.getByTestId('avatar-fallback'); + expect(avatarFallback).toBeInTheDocument(); }); });