diff --git a/src/components/datagrid/controls/data_grid_toolbar.test.tsx b/src/components/datagrid/controls/data_grid_toolbar.test.tsx index 2d7bfa9299f..6299871343e 100644 --- a/src/components/datagrid/controls/data_grid_toolbar.test.tsx +++ b/src/components/datagrid/controls/data_grid_toolbar.test.tsx @@ -135,6 +135,36 @@ describe('EuiDataGridToolbar', () => { `); }); + + it('renders custom content if renderCustomToolbar is defined', () => { + const mockRenderCustomToolbar = jest.fn(() => ( +
Custom
+ )); + const component = shallow( + + ); + + expect(component).toMatchInlineSnapshot(` +
+ Custom +
+ `); + expect(mockRenderCustomToolbar).toHaveBeenCalledWith( + expect.objectContaining({ + hasRoomForGridControls: true, + fullScreenControl: requiredProps.fullScreenSelector, + keyboardShortcutsControl: requiredProps.keyboardShortcuts, + displayControl: requiredProps.displaySelector, + columnControl: requiredProps.columnSelector, + columnSortingControl: requiredProps.columnSorting, + }) + ); + }); }); describe('checkOrDefaultToolBarDisplayOptions', () => { diff --git a/src/components/datagrid/controls/display_selector.test.tsx b/src/components/datagrid/controls/display_selector.test.tsx index cb3ef4cb03b..9ec5e5e800d 100644 --- a/src/components/datagrid/controls/display_selector.test.tsx +++ b/src/components/datagrid/controls/display_selector.test.tsx @@ -402,26 +402,100 @@ describe('useDataGridDisplaySelector', () => { }); }); - it('renders a reset button only when the user changes from the current settings', () => { - const component = mount(); - openPopover(component); - expect( - component.find('[data-test-subj="resetDisplaySelector"]').exists() - ).toBe(false); - - component.find('[data-test-subj="expanded"]').simulate('change'); - component.find('[data-test-subj="auto"]').simulate('change'); - expect( - component.find('[data-test-subj="resetDisplaySelector"]').exists() - ).toBe(true); - - // Should hide the reset button again after it's been clicked - component - .find('button[data-test-subj="resetDisplaySelector"]') - .simulate('click'); - expect( - component.find('[data-test-subj="resetDisplaySelector"]').exists() - ).toBe(false); + describe('reset button', () => { + it('renders a reset button only when the user changes from the current settings', () => { + const component = mount(); + openPopover(component); + expect( + component.find('[data-test-subj="resetDisplaySelector"]').exists() + ).toBe(false); + + component.find('[data-test-subj="expanded"]').simulate('change'); + component.find('[data-test-subj="auto"]').simulate('change'); + expect( + component.find('[data-test-subj="resetDisplaySelector"]').exists() + ).toBe(true); + + // Should hide the reset button again after it's been clicked + component + .find('button[data-test-subj="resetDisplaySelector"]') + .simulate('click'); + expect( + component.find('[data-test-subj="resetDisplaySelector"]').exists() + ).toBe(false); + }); + + it('renders the reset button after the user changed from the current settings and reopened popover', () => { + const component = mount(); + openPopover(component); + expect( + component.find('[data-test-subj="resetDisplaySelector"]').exists() + ).toBe(false); + + component.find('[data-test-subj="expanded"]').simulate('change'); + component.find('[data-test-subj="auto"]').simulate('change'); + expect( + component.find('[data-test-subj="resetDisplaySelector"]').exists() + ).toBe(true); + + // Should show the reset button again after the popover was reopened + closePopover(component); + openPopover(component); + expect( + component.find('[data-test-subj="resetDisplaySelector"]').exists() + ).toBe(true); + }); + + it('hides the reset button even after changes if allowResetButton is false', () => { + const component = mount( + + ); + openPopover(component); + expect( + component.find('[data-test-subj="resetDisplaySelector"]').exists() + ).toBe(false); + + component.find('[data-test-subj="expanded"]').simulate('change'); + component.find('[data-test-subj="auto"]').simulate('change'); + expect( + component.find('[data-test-subj="resetDisplaySelector"]').exists() + ).toBe(false); + + // Should hide the reset button again after the popover was reopened + closePopover(component); + openPopover(component); + expect( + component.find('[data-test-subj="resetDisplaySelector"]').exists() + ).toBe(false); + }); + }); + + describe('additionalDisplaySettings', () => { + it('renders custom content if additionalDisplaySettings is defined', () => { + const component = mount( + Custom content + ), + }} + /> + ); + openPopover(component); + expect(component.find('[data-test-subj="test-custom"]')) + .toMatchInlineSnapshot(` +
+ Custom content +
+ `); + }); }); });