Skip to content

Commit

Permalink
Test all aspect ratio classes on Image
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentSmedinga committed Nov 7, 2024
1 parent fa3006a commit dea0535
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
19 changes: 7 additions & 12 deletions packages/react/src/Image/Image.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { render } from '@testing-library/react'
import { createRef } from 'react'
import { Image } from './Image'
import { aspectRatioOptions } from '../common/types'
import '@testing-library/jest-dom'

describe('Image', () => {
Expand Down Expand Up @@ -29,20 +30,14 @@ describe('Image', () => {
expect(component).toHaveClass('ams-image extra')
})

it('renders class names to display the image in a given aspect ratio', () => {
const { container } = render(<Image aspectRatio="x-tall" />)
aspectRatioOptions.forEach((aspectRatio) => {
it(`renders class names to display the image in the ${aspectRatio} aspect ratio`, () => {
const { container } = render(<Image aspectRatio={aspectRatio} />)

const component = container.querySelector(':only-child')

expect(component).toHaveClass('ams-aspect-ratio--x-tall')
})

it('renders class names to display the image with the default aspect ratio', () => {
const { container } = render(<Image />)

const component = container.querySelector(':only-child')
const component = container.querySelector(':only-child')

expect(component).toHaveClass('ams-aspect-ratio--wide')
expect(component).toHaveClass(`ams-aspect-ratio--${aspectRatio}`)
})
})

it('supports ForwardRef in React', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/common/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const aspectRatioOptions = ['x-tall', 'tall', 'square', 'wide', 'x-wide', '2x-wide'] as const
export type AspectRatioProps = {
/** The aspect ratio to display media content in. */
aspectRatio?: 'x-tall' | 'tall' | 'square' | 'wide' | 'x-wide' | '2x-wide'
aspectRatio?: (typeof aspectRatioOptions)[number]
}

export const crossAlignOptions = ['start', 'center', 'baseline', 'end'] as const
Expand Down

0 comments on commit dea0535

Please sign in to comment.