| 1 | import { render } from '@testing-library/react'; |
| 2 | import { describe, it, expect } from 'vitest'; |
| 3 | import { Stack } from './stack'; |
| 4 | import { Slide } from './slide'; |
| 5 | |
| 6 | describe('Stack', () => { |
| 7 | it('renders as a <section> element', () => { |
| 8 | const { container } = render( |
| 9 | <Stack> |
| 10 | <Slide>A</Slide> |
| 11 | <Slide>B</Slide> |
| 12 | </Stack> |
| 13 | ); |
| 14 | |
| 15 | const sections = container.querySelectorAll('section'); |
| 16 | expect(sections).toHaveLength(3); // 1 outer (Stack) + 2 inner (Slides) |
| 17 | }); |
| 18 | |
| 19 | it('creates nested section structure for vertical slides', () => { |
| 20 | const { container } = render( |
| 21 | <Stack> |
| 22 | <Slide>First</Slide> |
| 23 | <Slide>Second</Slide> |
| 24 | </Stack> |
| 25 | ); |
| 26 | |
| 27 | const outer = container.querySelector('section'); |
| 28 | expect(outer).toBeInTheDocument(); |
| 29 | |
| 30 | const inner = outer?.querySelectorAll(':scope > section'); |
| 31 | expect(inner).toHaveLength(2); |
| 32 | expect(inner?.[0]).toHaveTextContent('First'); |
| 33 | expect(inner?.[1]).toHaveTextContent('Second'); |
| 34 | }); |
| 35 | |
| 36 | it('applies className and style to the outer section', () => { |
| 37 | const { container } = render( |
| 38 | <Stack className="my-stack" style={{ padding: '10px' }}> |
| 39 | <Slide>Content</Slide> |
| 40 | </Stack> |
| 41 | ); |
| 42 | |
| 43 | const outer = container.querySelector('section'); |
| 44 | expect(outer).toHaveClass('my-stack'); |
| 45 | expect(outer).toHaveStyle({ padding: '10px' }); |
| 46 | }); |
| 47 | }); |
| 48 |