|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { render, screen } from '@testing-library/react'; |
| 3 | +import SidebarLayout from './SidebarLayout'; |
| 4 | + |
| 5 | +describe('SidebarLayout', () => { |
| 6 | + it('renders sidebar, main content, and optional right panel', () => { |
| 7 | + render( |
| 8 | + <SidebarLayout |
| 9 | + sidebar={<div>sidebar-content</div>} |
| 10 | + rightPanel={<div>right-panel</div>} |
| 11 | + > |
| 12 | + <div>main-content</div> |
| 13 | + </SidebarLayout>, |
| 14 | + ); |
| 15 | + |
| 16 | + expect(screen.getByText('sidebar-content')).toBeInTheDocument(); |
| 17 | + expect(screen.getByText('main-content')).toBeInTheDocument(); |
| 18 | + expect(screen.getByText('right-panel')).toBeInTheDocument(); |
| 19 | + }); |
| 20 | + |
| 21 | + it('omits right panel when not provided', () => { |
| 22 | + const { container } = render( |
| 23 | + <SidebarLayout sidebar={<div>sidebar</div>}> |
| 24 | + <div>main</div> |
| 25 | + </SidebarLayout>, |
| 26 | + ); |
| 27 | + |
| 28 | + const asides = container.querySelectorAll('aside'); |
| 29 | + expect(asides).toHaveLength(1); |
| 30 | + }); |
| 31 | + |
| 32 | + it('uses semantic main and aside landmarks', () => { |
| 33 | + render( |
| 34 | + <SidebarLayout sidebar={<div>s</div>}> |
| 35 | + <div>m</div> |
| 36 | + </SidebarLayout>, |
| 37 | + ); |
| 38 | + |
| 39 | + expect(screen.getByRole('main')).toBeInTheDocument(); |
| 40 | + expect(screen.getByRole('complementary')).toBeInTheDocument(); |
| 41 | + }); |
| 42 | + |
| 43 | + it('applies the sidebarWidth variant', () => { |
| 44 | + const { container } = render( |
| 45 | + <SidebarLayout sidebar={<div>s</div>} sidebarWidth="lg"> |
| 46 | + <div>m</div> |
| 47 | + </SidebarLayout>, |
| 48 | + ); |
| 49 | + |
| 50 | + const aside = container.querySelector('aside'); |
| 51 | + expect(aside?.className).toContain('md:w-72'); |
| 52 | + }); |
| 53 | + |
| 54 | + it('assigns distinct aria-labels to left and right asides', () => { |
| 55 | + render( |
| 56 | + <SidebarLayout |
| 57 | + sidebar={<div>s</div>} |
| 58 | + rightPanel={<div>r</div>} |
| 59 | + sidebarAriaLabel="主要ナビゲーション" |
| 60 | + rightPanelAriaLabel="詳細パネル" |
| 61 | + > |
| 62 | + <div>m</div> |
| 63 | + </SidebarLayout>, |
| 64 | + ); |
| 65 | + |
| 66 | + expect(screen.getByRole('complementary', { name: '主要ナビゲーション' })).toBeInTheDocument(); |
| 67 | + expect(screen.getByRole('complementary', { name: '詳細パネル' })).toBeInTheDocument(); |
| 68 | + }); |
| 69 | + |
| 70 | + it('right panel has a bounded md width to prevent overflow', () => { |
| 71 | + const { container } = render( |
| 72 | + <SidebarLayout sidebar={<div>s</div>} rightPanel={<div>r</div>}> |
| 73 | + <div>m</div> |
| 74 | + </SidebarLayout>, |
| 75 | + ); |
| 76 | + |
| 77 | + const asides = container.querySelectorAll('aside'); |
| 78 | + const rightAside = asides[asides.length - 1]; |
| 79 | + expect(rightAside.className).toContain('md:w-64'); |
| 80 | + expect(rightAside.className).toContain('lg:w-80'); |
| 81 | + }); |
| 82 | +}); |
0 commit comments