|
| 1 | +import * as React from 'react'; |
| 2 | +import expect from 'expect'; |
| 3 | +import { cleanup, render } from '@testing-library/react'; |
| 4 | + |
| 5 | +import TabbedShowLayout from './TabbedShowLayout'; |
| 6 | +import Tab from './Tab'; |
| 7 | +import TextField from '../field/TextField'; |
| 8 | +import { createMemoryHistory } from 'history'; |
| 9 | +import { Router } from 'react-router-dom'; |
| 10 | + |
| 11 | +describe('<TabbedShowLayout />', () => { |
| 12 | + afterEach(cleanup); |
| 13 | + |
| 14 | + const renderWithRouter = children => { |
| 15 | + const history = createMemoryHistory(); |
| 16 | + |
| 17 | + return { |
| 18 | + history, |
| 19 | + ...render(<Router history={history}>{children}</Router>), |
| 20 | + }; |
| 21 | + }; |
| 22 | + |
| 23 | + it('should display the first Tab component and its content', () => { |
| 24 | + const { queryByText, history } = renderWithRouter( |
| 25 | + <TabbedShowLayout basePath="/" record={{ id: 123 }} resource="foo"> |
| 26 | + <Tab label="Tab1"> |
| 27 | + <TextField label="Field On Tab1" source="field1" /> |
| 28 | + </Tab> |
| 29 | + <Tab label="Tab2"> |
| 30 | + <TextField label="Field On Tab2" source="field2" /> |
| 31 | + </Tab> |
| 32 | + </TabbedShowLayout> |
| 33 | + ); |
| 34 | + |
| 35 | + expect(queryByText('Tab1')).not.toBeNull(); |
| 36 | + expect(queryByText('Field On Tab1')).not.toBeNull(); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should display the first valid Tab component and its content', () => { |
| 40 | + const { queryByText, history } = renderWithRouter( |
| 41 | + <TabbedShowLayout basePath="/" record={{ id: 123 }} resource="foo"> |
| 42 | + {null} |
| 43 | + <Tab label="Tab1"> |
| 44 | + <TextField label="Field On Tab1" source="field1" /> |
| 45 | + </Tab> |
| 46 | + <Tab label="Tab2"> |
| 47 | + <TextField label="Field On Tab2" source="field2" /> |
| 48 | + </Tab> |
| 49 | + </TabbedShowLayout> |
| 50 | + ); |
| 51 | + |
| 52 | + expect(queryByText('Tab1')).not.toBeNull(); |
| 53 | + expect(queryByText('Field On Tab1')).not.toBeNull(); |
| 54 | + }); |
| 55 | +}); |
0 commit comments