2026-04-23 20:52:43 +03:00
|
|
|
import { render, screen } from '@testing-library/react';
|
|
|
|
|
import { ProjectCard } from './ProjectCard';
|
2026-04-19 08:37:21 +03:00
|
|
|
|
|
|
|
|
const DEFAULT_PROPS = {
|
|
|
|
|
title: 'My Project',
|
|
|
|
|
year: '2024',
|
|
|
|
|
description: 'A cool project description',
|
|
|
|
|
tags: ['React', 'Node'],
|
2026-05-18 20:45:54 +03:00
|
|
|
url: 'https://example.com',
|
2026-04-23 20:52:43 +03:00
|
|
|
};
|
2026-04-19 08:37:21 +03:00
|
|
|
|
|
|
|
|
describe('ProjectCard', () => {
|
|
|
|
|
describe('rendering', () => {
|
|
|
|
|
it('renders the project title', () => {
|
2026-04-23 20:52:43 +03:00
|
|
|
render(<ProjectCard {...DEFAULT_PROPS} />);
|
|
|
|
|
expect(screen.getByText('My Project')).toBeInTheDocument();
|
|
|
|
|
});
|
2026-04-19 08:37:21 +03:00
|
|
|
|
2026-05-18 13:14:40 +03:00
|
|
|
it('renders the year', () => {
|
2026-04-23 20:52:43 +03:00
|
|
|
render(<ProjectCard {...DEFAULT_PROPS} />);
|
|
|
|
|
expect(screen.getByText('2024')).toBeInTheDocument();
|
|
|
|
|
});
|
2026-04-19 08:37:21 +03:00
|
|
|
|
|
|
|
|
it('renders the description', () => {
|
2026-04-23 20:52:43 +03:00
|
|
|
render(<ProjectCard {...DEFAULT_PROPS} />);
|
|
|
|
|
expect(screen.getByText('A cool project description')).toBeInTheDocument();
|
|
|
|
|
});
|
2026-04-19 08:37:21 +03:00
|
|
|
|
|
|
|
|
it('renders each tag', () => {
|
2026-04-23 20:52:43 +03:00
|
|
|
render(<ProjectCard {...DEFAULT_PROPS} />);
|
|
|
|
|
expect(screen.getByText('React')).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText('Node')).toBeInTheDocument();
|
|
|
|
|
});
|
2026-04-19 08:37:21 +03:00
|
|
|
|
|
|
|
|
it('renders the View Project button', () => {
|
2026-04-23 20:52:43 +03:00
|
|
|
render(<ProjectCard {...DEFAULT_PROPS} />);
|
2026-05-18 20:45:54 +03:00
|
|
|
expect(screen.getByRole('link', { name: /view project/i })).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('View Project link points to the project url', () => {
|
|
|
|
|
render(<ProjectCard {...DEFAULT_PROPS} />);
|
|
|
|
|
expect(screen.getByRole('link', { name: /view project/i })).toHaveAttribute('href', 'https://example.com');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('View Project link opens in a new tab', () => {
|
|
|
|
|
render(<ProjectCard {...DEFAULT_PROPS} />);
|
|
|
|
|
expect(screen.getByRole('link', { name: /view project/i })).toHaveAttribute('target', '_blank');
|
2026-04-23 20:52:43 +03:00
|
|
|
});
|
|
|
|
|
});
|
2026-04-19 08:37:21 +03:00
|
|
|
|
2026-05-18 13:14:40 +03:00
|
|
|
describe('layout', () => {
|
|
|
|
|
it('year is inside the sidebar column', () => {
|
|
|
|
|
render(<ProjectCard {...DEFAULT_PROPS} />);
|
|
|
|
|
expect(screen.getByText('2024').closest('.brutal-border-sidebar')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('tags are inside the sidebar column', () => {
|
|
|
|
|
render(<ProjectCard {...DEFAULT_PROPS} />);
|
|
|
|
|
expect(screen.getByText('React').closest('.brutal-border-sidebar')).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByText('Node').closest('.brutal-border-sidebar')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('View Project button is inside the sidebar column', () => {
|
|
|
|
|
render(<ProjectCard {...DEFAULT_PROPS} />);
|
2026-05-18 20:45:54 +03:00
|
|
|
const btn = screen.getByRole('link', { name: /view project/i });
|
2026-05-18 13:14:40 +03:00
|
|
|
expect(btn.closest('.brutal-border-sidebar')).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('title is outside the sidebar column', () => {
|
|
|
|
|
render(<ProjectCard {...DEFAULT_PROPS} />);
|
|
|
|
|
expect(screen.getByText('My Project').closest('.brutal-border-sidebar')).toBeNull();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('description is outside the sidebar column', () => {
|
|
|
|
|
render(<ProjectCard {...DEFAULT_PROPS} />);
|
|
|
|
|
expect(screen.getByText('A cool project description').closest('.brutal-border-sidebar')).toBeNull();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-19 08:37:21 +03:00
|
|
|
describe('structure', () => {
|
|
|
|
|
it('card has hover transition classes', () => {
|
2026-04-23 20:52:43 +03:00
|
|
|
const { container } = render(<ProjectCard {...DEFAULT_PROPS} />);
|
2026-05-18 13:14:40 +03:00
|
|
|
expect(container.firstChild).toHaveClass('group', 'transition-shadow', 'duration-300');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('title renders as h3', () => {
|
|
|
|
|
render(<ProjectCard {...DEFAULT_PROPS} />);
|
|
|
|
|
expect(screen.getByRole('heading', { level: 3 })).toHaveTextContent('My Project');
|
2026-04-23 20:52:43 +03:00
|
|
|
});
|
2026-04-19 08:37:21 +03:00
|
|
|
|
2026-05-18 13:20:47 +03:00
|
|
|
it('year has period-style left border', () => {
|
2026-04-23 20:52:43 +03:00
|
|
|
render(<ProjectCard {...DEFAULT_PROPS} />);
|
2026-05-18 13:20:47 +03:00
|
|
|
const year = screen.getByText('2024');
|
|
|
|
|
expect(year.tagName).toBe('P');
|
|
|
|
|
expect(year).toHaveClass('brutal-border-left', 'text-sm');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('View Project button uses sm size', () => {
|
|
|
|
|
render(<ProjectCard {...DEFAULT_PROPS} />);
|
2026-05-18 20:45:54 +03:00
|
|
|
const btn = screen.getByRole('link', { name: /view project/i });
|
2026-05-19 18:05:57 +03:00
|
|
|
expect(btn).toHaveClass('px-3', 'py-1.5', 'sm:px-4', 'sm:py-2', 'text-sm');
|
2026-04-23 20:52:43 +03:00
|
|
|
});
|
2026-04-19 08:37:21 +03:00
|
|
|
|
2026-05-18 13:14:40 +03:00
|
|
|
it('tags are xs outline badges', () => {
|
2026-04-23 20:52:43 +03:00
|
|
|
render(<ProjectCard {...DEFAULT_PROPS} />);
|
|
|
|
|
const tag = screen.getByText('React');
|
2026-05-18 13:14:40 +03:00
|
|
|
expect(tag).toHaveClass('brutal-border', 'bg-transparent', 'px-2');
|
2026-04-23 20:52:43 +03:00
|
|
|
});
|
|
|
|
|
});
|
2026-04-19 08:37:21 +03:00
|
|
|
|
|
|
|
|
describe('conditional image rendering', () => {
|
|
|
|
|
it('does not render image when imageUrl is absent', () => {
|
2026-04-23 20:52:43 +03:00
|
|
|
const { container } = render(<ProjectCard {...DEFAULT_PROPS} />);
|
|
|
|
|
expect(container.querySelector('img')).toBeNull();
|
|
|
|
|
});
|
2026-04-19 08:37:21 +03:00
|
|
|
|
|
|
|
|
it('renders image when imageUrl is provided', () => {
|
2026-04-23 20:52:43 +03:00
|
|
|
render(<ProjectCard {...DEFAULT_PROPS} imageUrl="/project.jpg" />);
|
2026-04-24 08:38:00 +03:00
|
|
|
expect(screen.getByRole('img')).toBeInTheDocument();
|
2026-04-23 20:52:43 +03:00
|
|
|
});
|
2026-04-19 08:37:21 +03:00
|
|
|
|
2026-05-18 13:14:40 +03:00
|
|
|
it('image wrapper has aspect-video and overflow-hidden', () => {
|
2026-04-23 20:52:43 +03:00
|
|
|
const { container } = render(<ProjectCard {...DEFAULT_PROPS} imageUrl="/project.jpg" />);
|
2026-04-24 08:38:00 +03:00
|
|
|
const imgWrapper = container.querySelector('img')?.parentElement;
|
2026-04-23 20:52:43 +03:00
|
|
|
expect(imgWrapper).toHaveClass('aspect-video', 'overflow-hidden', 'brutal-border');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|