Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cschroeter committed Dec 27, 2024
1 parent 0e76de0 commit 33b1812
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 100 deletions.
Binary file modified bun.lockb
Binary file not shown.
43 changes: 43 additions & 0 deletions packages/react/src/components/carousel/carousel.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { cleanup, render, screen, waitFor } from '@testing-library/react/pure'
import { axe } from 'vitest-axe'
import { Carousel, carouselAnatomy } from '.'
import { getExports, getParts } from '../../setup-test'
import { Basic as ComponentUnderTest } from './examples/basic'

describe('Carousel / Parts & Exports', () => {
afterAll(() => {
cleanup()
})

render(<ComponentUnderTest />)

it.each(getParts(carouselAnatomy))('should render part %s', async (part) => {
expect(document.querySelector(part)).toBeInTheDocument()
})

it.each(getExports(carouselAnatomy))('should export %s', async (part) => {
expect(Carousel[part]).toBeDefined()
})
})

describe('Carousel', () => {
afterEach(() => {
cleanup()
})

it('should have no a11y violations', async () => {
const { container } = render(<ComponentUnderTest />)
const results = await axe(container)

expect(results).toHaveNoViolations()
})

it('should have the correct disabled / enabled states for control buttons', async () => {
render(<ComponentUnderTest />)
const prevButton = screen.getByRole('button', { name: 'Previous slide' })
const nextButton = screen.getByRole('button', { name: 'Next slide' })

await waitFor(() => expect(prevButton).toBeDisabled())
await waitFor(() => expect(nextButton).toBeEnabled())
})
})
2 changes: 1 addition & 1 deletion packages/react/src/components/carousel/examples/basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const images = Array(5).fill('https://picsum.photos/seed/a/500/300')

export const Basic = () => {
return (
<Carousel.Root autoplay={{ delay: 1000 }} loop>
<Carousel.Root>
<Carousel.Control>
<Carousel.AutoplayTrigger>Play or Pause</Carousel.AutoplayTrigger>
<Carousel.PrevTrigger>Previous</Carousel.PrevTrigger>
Expand Down
28 changes: 0 additions & 28 deletions packages/react/src/components/carousel/tests/basic.tsx

This file was deleted.

71 changes: 0 additions & 71 deletions packages/react/src/components/carousel/tests/carousel.test.tsx

This file was deleted.

13 changes: 13 additions & 0 deletions packages/react/src/setup-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,23 @@ import { vi } from 'vitest'
import 'vitest-axe/extend-expect'

const { window } = new JSDOM()
/**
* IntersectionObserver
*/
const IntersectionObserverMock = vi.fn(() => ({
disconnect: vi.fn(),
observe: vi.fn(),
takeRecords: vi.fn(),
unobserve: vi.fn(),
}))
vi.stubGlobal('IntersectionObserver', IntersectionObserverMock)
// biome-ignore lint/complexity/useLiteralKeys: <explanation>
window['IntersectionObserver'] = IntersectionObserverMock

vi.stubGlobal('ResizeObserver', ResizeObserver)
// biome-ignore lint/complexity/useLiteralKeys: <explanation>
window['ResizeObserver'] = ResizeObserver

window.Element.prototype.scrollTo = () => {}
window.Element.prototype.scrollIntoView = () => {}
window.requestAnimationFrame = (cb) => setTimeout(cb, 1000 / 60)
Expand Down

0 comments on commit 33b1812

Please sign in to comment.