|
| 1 | +import React from 'react'; |
| 2 | +import { render, screen } from '@testing-library/react'; |
| 3 | +import Layout from '..'; |
| 4 | + |
| 5 | +describe('Layout', () => { |
| 6 | + test('should match the snapshot', () => { |
| 7 | + const { asFragment } = render( |
| 8 | + <Layout> |
| 9 | + <Layout.Header>Header</Layout.Header> |
| 10 | + <Layout> |
| 11 | + <Layout.Sidebar>Sidebar</Layout.Sidebar> |
| 12 | + <Layout.Content>Content</Layout.Content> |
| 13 | + </Layout> |
| 14 | + <Layout.Footer>Footer</Layout.Footer> |
| 15 | + </Layout> |
| 16 | + ); |
| 17 | + expect(asFragment()).toMatchSnapshot(); |
| 18 | + }); |
| 19 | + |
| 20 | + test('should support custom class name', () => { |
| 21 | + render( |
| 22 | + <Layout className="custom-layout"> |
| 23 | + <Layout.Header className="custom-layout-header">Header</Layout.Header> |
| 24 | + <Layout> |
| 25 | + <Layout.Sidebar className="custom-layout-sidebar"> |
| 26 | + Sidebar |
| 27 | + </Layout.Sidebar> |
| 28 | + <Layout.Content className="custom-layout-content"> |
| 29 | + Content |
| 30 | + </Layout.Content> |
| 31 | + </Layout> |
| 32 | + <Layout.Footer className="custom-layout-footer">Footer</Layout.Footer> |
| 33 | + </Layout> |
| 34 | + ); |
| 35 | + expect(screen.getAllByTestId('layout')[0]).toHaveClass('custom-layout'); |
| 36 | + expect(screen.getByTestId('layoutHeader')).toHaveClass( |
| 37 | + 'custom-layout-header' |
| 38 | + ); |
| 39 | + expect(screen.getByTestId('layoutSidebar')).toHaveClass( |
| 40 | + 'custom-layout-sidebar' |
| 41 | + ); |
| 42 | + expect(screen.getByTestId('layoutContent')).toHaveClass( |
| 43 | + 'custom-layout-content' |
| 44 | + ); |
| 45 | + expect(screen.getByTestId('layoutFooter')).toHaveClass( |
| 46 | + 'custom-layout-footer' |
| 47 | + ); |
| 48 | + }); |
| 49 | + |
| 50 | + test('should detect the sidebar as children', () => { |
| 51 | + render( |
| 52 | + <Layout> |
| 53 | + <Layout.Header>Header</Layout.Header> |
| 54 | + <Layout> |
| 55 | + <Layout.Sidebar>Sidebar</Layout.Sidebar> |
| 56 | + <Layout.Content>Content</Layout.Content> |
| 57 | + </Layout> |
| 58 | + <Layout.Footer>Footer</Layout.Footer> |
| 59 | + </Layout> |
| 60 | + ); |
| 61 | + expect(screen.getAllByTestId('layout')[1]).toHaveClass( |
| 62 | + 'raw-layout-has-sidebar' |
| 63 | + ); |
| 64 | + }); |
| 65 | +}); |
0 commit comments