import React from 'react';
import { describe, it, expect } from 'vitest';
import { render } from '@testing-library/react';
import {
Skeleton,
ProductCardSkeleton,
ProductListSkeleton,
PetProfileSkeleton,
OrderRowSkeleton,
} from '../Skeleton';
describe('Skeleton Components', () => {
describe('Skeleton base component', () => {
it('renders with default base classes including animation and shimmer', () => {
const { container } = render();
const el = container.firstElementChild;
expect(el).toBeInTheDocument();
expect(el).toHaveClass('bg-medical-gray-100');
expect(el).toHaveClass('animate-pulse');
expect(el).toHaveClass('rounded-2xl');
expect(el).toHaveClass('relative');
expect(el).toHaveClass('overflow-hidden');
// Shimmer pseudo element classes check
expect(el?.className).toContain('before:absolute');
expect(el?.className).toContain('before:inset-0');
expect(el?.className).toContain('before:-translate-x-full');
expect(el?.className).toContain('before:animate-[shimmer_2s_infinite]');
expect(el?.className).toContain('before:bg-gradient-to-r');
});
it('applies custom className sizing and styling correctly', () => {
const { container } = render();
const el = container.firstElementChild;
expect(el).toHaveClass('w-32');
expect(el).toHaveClass('h-8');
expect(el).toHaveClass('rounded-full');
expect(el).toHaveClass('custom-skeleton-class');
});
});
describe('ProductCardSkeleton variant', () => {
it('renders card skeleton layout with image, tags, titles, symptoms, and footer placeholders', () => {
const { container } = render();
const rootCard = container.firstElementChild;
expect(rootCard).toHaveClass('bg-white');
expect(rootCard).toHaveClass('rounded-[2.5rem]');
expect(rootCard).toHaveClass('shadow-sm');
// Check skeleton elements inside
const skeletons = container.querySelectorAll('.animate-pulse');
expect(skeletons.length).toBeGreaterThanOrEqual(7);
// Verify aspect-square placeholder for product image
const imagePlaceholder = container.querySelector('.aspect-square');
expect(imagePlaceholder).toBeInTheDocument();
expect(imagePlaceholder).toHaveClass('rounded-[2rem]', 'w-full', 'mb-6');
});
});
describe('ProductListSkeleton variant', () => {
it('renders horizontal list skeleton item with image thumb and info rows', () => {
const { container } = render();
const root = container.firstElementChild;
expect(root).toHaveClass('bg-white', 'rounded-2xl', 'p-3');
const skeletons = container.querySelectorAll('.animate-pulse');
expect(skeletons.length).toBe(6); // thumb + 3 info rows + 2 footer action rows
// Thumbnail check
const thumb = container.querySelector('.w-24.h-24');
expect(thumb).toBeInTheDocument();
});
});
describe('PetProfileSkeleton variant', () => {
it('renders pet profile skeleton layout with avatar, headers, badges, and stat cards', () => {
const { container } = render();
const root = container.firstElementChild;
expect(root).toHaveClass('bg-white', 'rounded-[3rem]', 'shadow-2xl');
// Avatar placeholder
const avatar = container.querySelector('.w-40.h-40');
expect(avatar).toBeInTheDocument();
// Check 4 stat cards exist
const statCards = container.querySelectorAll('.bg-medical-gray-50');
expect(statCards.length).toBe(4);
const skeletons = container.querySelectorAll('.animate-pulse');
expect(skeletons.length).toBeGreaterThanOrEqual(13); // avatar + 2 headers + 2 tags + 4*2 stats
});
});
describe('OrderRowSkeleton variant', () => {
it('renders order row skeleton with thumbnail and order detail blocks', () => {
const { container } = render();
const root = container.firstElementChild;
expect(root).toHaveClass('flex', 'items-center', 'gap-6', 'p-6');
const thumb = container.querySelector('.w-16.h-16');
expect(thumb).toBeInTheDocument();
const skeletons = container.querySelectorAll('.animate-pulse');
expect(skeletons.length).toBe(5); // thumb + 4 detail placeholders
});
});
});