|
1 | | -import {render} from '@testing-library/react' |
2 | 1 | import React from 'react' |
| 2 | +import {act, render} from '@testing-library/react' |
| 3 | +import MatchMediaMock from 'jest-matchmedia-mock' |
3 | 4 | import {ThemeProvider} from '..' |
| 5 | +import {viewportRanges} from '../hooks/useResponsiveValue' |
4 | 6 | import {PageLayout} from './PageLayout' |
5 | 7 |
|
| 8 | +let matchMedia: MatchMediaMock |
| 9 | + |
6 | 10 | describe('PageLayout', () => { |
| 11 | + beforeAll(() => { |
| 12 | + matchMedia = new MatchMediaMock() |
| 13 | + }) |
| 14 | + |
| 15 | + afterEach(() => { |
| 16 | + matchMedia.clear() |
| 17 | + }) |
| 18 | + |
7 | 19 | it('renders default layout', () => { |
8 | 20 | const {container} = render( |
9 | 21 | <ThemeProvider> |
@@ -63,4 +75,44 @@ describe('PageLayout', () => { |
63 | 75 | ) |
64 | 76 | expect(container).toMatchSnapshot() |
65 | 77 | }) |
| 78 | + |
| 79 | + it('can hide pane when narrow', () => { |
| 80 | + // Set narrow viewport |
| 81 | + act(() => { |
| 82 | + matchMedia.useMediaQuery(viewportRanges.narrow) |
| 83 | + }) |
| 84 | + |
| 85 | + const {getByText} = render( |
| 86 | + <ThemeProvider> |
| 87 | + <PageLayout> |
| 88 | + <PageLayout.Header>Header</PageLayout.Header> |
| 89 | + <PageLayout.Content>Content</PageLayout.Content> |
| 90 | + <PageLayout.Pane hidden={{narrow: true}}>Pane</PageLayout.Pane> |
| 91 | + <PageLayout.Footer>Footer</PageLayout.Footer> |
| 92 | + </PageLayout> |
| 93 | + </ThemeProvider> |
| 94 | + ) |
| 95 | + |
| 96 | + expect(getByText('Pane')).not.toBeVisible() |
| 97 | + }) |
| 98 | + |
| 99 | + it('shows all subcomponents by default', () => { |
| 100 | + // Set regular viewport |
| 101 | + act(() => { |
| 102 | + matchMedia.useMediaQuery(viewportRanges.regular) |
| 103 | + }) |
| 104 | + |
| 105 | + const {getByText} = render( |
| 106 | + <ThemeProvider> |
| 107 | + <PageLayout> |
| 108 | + <PageLayout.Header>Header</PageLayout.Header> |
| 109 | + <PageLayout.Content>Content</PageLayout.Content> |
| 110 | + <PageLayout.Pane hidden={{narrow: true}}>Pane</PageLayout.Pane> |
| 111 | + <PageLayout.Footer>Footer</PageLayout.Footer> |
| 112 | + </PageLayout> |
| 113 | + </ThemeProvider> |
| 114 | + ) |
| 115 | + |
| 116 | + expect(getByText('Pane')).toBeVisible() |
| 117 | + }) |
66 | 118 | }) |
0 commit comments