-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Domino987
committed
Jul 6, 2023
1 parent
bb4ae80
commit b13b492
Showing
2 changed files
with
87 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import * as React from 'react'; | ||
import { | ||
act, | ||
screen, | ||
render, | ||
waitForElementToBeRemoved, | ||
within, | ||
waitFor, | ||
fireEvent | ||
} from '@testing-library/react'; | ||
import MaterialTable from '../src'; | ||
|
||
const lookup = { 1: 'One', 2: 'Two' }; | ||
|
||
const columns = [ | ||
{ title: 'Enum', field: 'enum', lookup }, | ||
{ title: 'Name', field: 'id' } | ||
]; | ||
|
||
const data = [{ id: 1, enum: 1 }]; | ||
|
||
describe('Detailpanel render', () => { | ||
test('It displays and hides the detail with function', async () => { | ||
render( | ||
<MaterialTable | ||
data={data} | ||
columns={columns} | ||
detailPanel={({ rowData }) => { | ||
return <div>Detail Panel Test</div>; | ||
}} | ||
/> | ||
); | ||
screen.getByRole('cell', { | ||
name: /one/i | ||
}); | ||
|
||
const panelIsHidden = screen.queryByText(/Detail Panel Test/i); | ||
|
||
expect(panelIsHidden).toBeNull(); | ||
|
||
const toggleButton = screen.getByRole('button', { | ||
name: /detail panel visibility toggle/i | ||
}); | ||
|
||
fireEvent.click(toggleButton); | ||
|
||
screen.findByText(/Detail Panel Test/i); | ||
|
||
fireEvent.click(toggleButton); | ||
|
||
expect(screen.queryByText(/Detail Panel Test/i)).toBeNull(); | ||
}); | ||
|
||
test('It displays the detail as is array', async () => { | ||
render( | ||
<MaterialTable | ||
data={data} | ||
columns={columns} | ||
detailPanel={[ | ||
{ | ||
tooltip: 'Show Name', | ||
render: ({ rowData }) => { | ||
return <div>Detail Panel Test</div>; | ||
} | ||
} | ||
]} | ||
/> | ||
); | ||
screen.getByRole('cell', { | ||
name: /one/i | ||
}); | ||
const toggleButton = screen.getByRole('button', { | ||
name: /detail panel visibility toggle/i | ||
}); | ||
|
||
fireEvent.click(toggleButton); | ||
|
||
await waitFor(() => screen.findByText(/Detail Panel Test/i)); | ||
|
||
fireEvent.click(toggleButton); | ||
|
||
await waitFor(() => | ||
expect(screen.queryByText(/Detail Panel Test/i)).toBeNull() | ||
); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.