import { render, screen } from '@testing-library/react'; import React from 'react'; import { describe, expect, it } from 'vitest'; import { MdStep } from '../MdStep'; import { MdStepper } from '../MdStepper'; describe('MdStepper', () => { describe('rendering', () => { it('renders steps', () => { render( Content 1 Content 2 Content 3 , ); expect(screen.getByText('Step 1')).toBeInTheDocument(); expect(screen.getByText('Step 2')).toBeInTheDocument(); expect(screen.getByText('Step 3')).toBeInTheDocument(); }); it('renders step numbers', () => { render( Content 1 Content 2 , ); expect(screen.getByText('1')).toBeInTheDocument(); expect(screen.getByText('2')).toBeInTheDocument(); }); it('renders active step content', () => { render( First step content Second step content , ); expect(screen.getByText('First step content')).toBeInTheDocument(); }); }); describe('active step', () => { it('marks first step as active when activeStep is 0', () => { const { container } = render( Content 1 Content 2 , ); expect(container.querySelector('.md-stepper__selected')).toBeInTheDocument(); expect(screen.getByText('Step 1').closest('h4')).toHaveClass('md-stepper__selected'); }); it('marks second step as active when activeStep is 1', () => { render( Content 1 Content 2 , ); expect(screen.getByText('Step 2').closest('h4')).toHaveClass('md-stepper__selected'); }); }); describe('completed steps', () => { it('marks previous steps as completed', () => { render( Content 1 Content 2 Content 3 , ); expect(screen.getByText('Step 1').closest('h4')).toHaveClass('md-stepper__completed'); expect(screen.getByText('Step 2').closest('h4')).toHaveClass('md-stepper__completed'); expect(screen.getByText('Step 3').closest('h4')).toHaveClass('md-stepper__selected'); }); it('shows check icon for completed steps', () => { const { container } = render( Content 1 Content 2 , ); expect(container.querySelector('.md-stepper__step-title-badge.completed')).toBeInTheDocument(); }); it('renders completed content when step is completed', () => { render( Completed!}> Active content Content 2 , ); expect(screen.getByText('Completed!')).toBeInTheDocument(); }); }); describe('disabled steps', () => { it('marks future steps as disabled', () => { render( Content 1 Content 2 Content 3 , ); expect(screen.getByText('Step 2').closest('h4')).toHaveClass('md-stepper__disabled'); expect(screen.getByText('Step 3').closest('h4')).toHaveClass('md-stepper__disabled'); }); it('shows step number for disabled steps', () => { const { container } = render( Content 1 Content 2 , ); expect(container.querySelector('.md-stepper__step-title-badge.disabled')).toBeInTheDocument(); }); }); }); describe('MdStep', () => { it('renders children', () => { render(
Step content
Content 2
, ); expect(screen.getByTestId('step-content')).toBeInTheDocument(); }); });