feat: amélioration majeure de la qualité du code et des tests - ajout de 20 nouveaux tests et fonctions utilitaires

This commit is contained in:
Yannick Le Duc
2025-08-28 20:53:53 +02:00
parent cea3b81994
commit 74189ac037
4 changed files with 243 additions and 1 deletions

View File

@@ -0,0 +1,59 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { BaseModal } from '../../components/base/BaseModal';
describe('BaseModal', () => {
const defaultProps = {
isOpen: true,
onClose: jest.fn(),
title: 'Test Modal',
children: <div>Modal Content</div>,
};
it('should render modal when open', () => {
render(<BaseModal {...defaultProps} />);
expect(screen.getByText('Test Modal')).toBeInTheDocument();
expect(screen.getByText('Modal Content')).toBeInTheDocument();
});
it('should not render modal when closed', () => {
render(<BaseModal {...defaultProps} isOpen={false} />);
expect(screen.queryByText('Test Modal')).not.toBeInTheDocument();
expect(screen.queryByText('Modal Content')).not.toBeInTheDocument();
});
it('should render with custom maxWidth and maxHeight', () => {
render(
<BaseModal
{...defaultProps}
maxWidth="sm:max-w-[800px]"
maxHeight="max-h-[80vh]"
/>
);
const modalContent = screen.getByTestId('modal-content');
expect(modalContent).toHaveClass('sm:max-w-[800px]');
expect(modalContent).toHaveClass('max-h-[80vh]');
});
it('should render with description when provided', () => {
render(
<BaseModal
{...defaultProps}
description="Test description"
/>
);
expect(screen.getByText('Test description')).toBeInTheDocument();
});
it('should render footer when provided', () => {
const footer = <button>Save</button>;
render(<BaseModal {...defaultProps} footer={footer} />);
expect(screen.getByText('Save')).toBeInTheDocument();
});
});