-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5312 from WiXSL/fix-optional-first-tab
Fix TabbedShowLayout resolves path incorrectly if first tab is null
- Loading branch information
Showing
2 changed files
with
60 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/ra-ui-materialui/src/detail/TabbedShowLayout.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import * as React from 'react'; | ||
import expect from 'expect'; | ||
import { cleanup, render } from '@testing-library/react'; | ||
|
||
import TabbedShowLayout from './TabbedShowLayout'; | ||
import Tab from './Tab'; | ||
import TextField from '../field/TextField'; | ||
import { createMemoryHistory } from 'history'; | ||
import { Router } from 'react-router-dom'; | ||
|
||
describe('<TabbedShowLayout />', () => { | ||
afterEach(cleanup); | ||
|
||
const renderWithRouter = children => { | ||
const history = createMemoryHistory(); | ||
|
||
return { | ||
history, | ||
...render(<Router history={history}>{children}</Router>), | ||
}; | ||
}; | ||
|
||
it('should display the first Tab component and its content', () => { | ||
const { queryByText, history } = renderWithRouter( | ||
<TabbedShowLayout basePath="/" record={{ id: 123 }} resource="foo"> | ||
<Tab label="Tab1"> | ||
<TextField label="Field On Tab1" source="field1" /> | ||
</Tab> | ||
<Tab label="Tab2"> | ||
<TextField label="Field On Tab2" source="field2" /> | ||
</Tab> | ||
</TabbedShowLayout> | ||
); | ||
|
||
expect(queryByText('Tab1')).not.toBeNull(); | ||
expect(queryByText('Field On Tab1')).not.toBeNull(); | ||
}); | ||
|
||
it('should display the first valid Tab component and its content', () => { | ||
const { queryByText, history } = renderWithRouter( | ||
<TabbedShowLayout basePath="/" record={{ id: 123 }} resource="foo"> | ||
{null} | ||
<Tab label="Tab1"> | ||
<TextField label="Field On Tab1" source="field1" /> | ||
</Tab> | ||
<Tab label="Tab2"> | ||
<TextField label="Field On Tab2" source="field2" /> | ||
</Tab> | ||
</TabbedShowLayout> | ||
); | ||
|
||
expect(queryByText('Tab1')).not.toBeNull(); | ||
expect(queryByText('Field On Tab1')).not.toBeNull(); | ||
}); | ||
}); |