1+ import React from 'react' ;
2+ import { render , screen } from '@testing-library/react' ;
3+ import AspectRatio from '../AspectRatio' ;
4+
5+ describe ( 'AspectRatio' , ( ) => {
6+ test ( 'renders AspectRatio component' , ( ) => {
7+ render ( < AspectRatio > Content</ AspectRatio > ) ;
8+ expect ( screen . getByText ( 'Content' ) ) . toBeInTheDocument ( ) ;
9+ } ) ;
10+
11+ test ( 'applies custom classes correctly' , ( ) => {
12+ render ( < AspectRatio className = "additional-class" > Content</ AspectRatio > ) ;
13+ const divElement = screen . getByText ( 'Content' ) ;
14+ expect ( divElement ) . toHaveClass ( 'additional-class' ) ;
15+ } ) ;
16+
17+ test ( 'applies correct aspect ratio' , ( ) => {
18+ render ( < AspectRatio ratio = "16/9" > Content</ AspectRatio > ) ;
19+ expect ( screen . getByText ( 'Content' ) . style . aspectRatio ) . toBe ( '16/9' ) ;
20+ } ) ;
21+
22+ test ( 'applies correct aspect ratio when ratio is not provided' , ( ) => {
23+ render ( < AspectRatio > Content</ AspectRatio > ) ;
24+ expect ( screen . getByText ( 'Content' ) . style . aspectRatio ) . toBe ( '1' ) ;
25+ } ) ;
26+
27+ test ( 'applies correct aspect ratio when ratio is invalid' , ( ) => {
28+ render ( < AspectRatio ratio = "invalid" > Content</ AspectRatio > ) ;
29+ expect ( screen . getByText ( 'Content' ) . style . aspectRatio ) . toBe ( '1' ) ;
30+ } ) ;
31+
32+ test ( 'applies correct aspect ratio when ratio contains a character' , ( ) => {
33+ render ( < AspectRatio ratio = "16/o" > Content</ AspectRatio > ) ;
34+ expect ( screen . getByText ( 'Content' ) . style . aspectRatio ) . toBe ( '1' ) ;
35+ } ) ;
36+
37+ test ( 'applies correct aspect ratio when ratio is negative' , ( ) => {
38+ render ( < AspectRatio ratio = "-5" > Content</ AspectRatio > ) ;
39+ expect ( screen . getByText ( 'Content' ) . style . aspectRatio ) . toBe ( '1' ) ;
40+ } ) ;
41+
42+
43+ } ) ;
0 commit comments