Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add custom fixtures for optional control props in order to test the p…
…anel header icon toggle in isolation from the other tests.
  • Loading branch information
ramonjd committed Oct 13, 2021
commit 5b4dd79f2f8c1b09ba2ec8126b6038e31c0d3aa8
17 changes: 14 additions & 3 deletions packages/components/src/tools-panel/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,11 +518,22 @@ describe( 'ToolsPanel', () => {
} );

describe( 'panel header icon toggle', () => {
const optionalControls = {
attributes: { value: false },
hasValue: jest.fn().mockImplementation( () => {
return !! optionalControls.attributes.value;
} ),
label: 'Optional',
onDeselect: jest.fn(),
onSelect: jest.fn(),
isShownByDefault: false,
};

it( 'should render appropriate icons for the dropdown menu', async () => {
render(
<ToolsPanel { ...defaultProps }>
<ToolsPanelItem { ...controlProps }>
<div>Default control</div>
<ToolsPanelItem { ...optionalControls }>
<div>Optional control</div>
</ToolsPanelItem>
</ToolsPanel>
);
Expand All @@ -534,7 +545,7 @@ describe( 'ToolsPanel', () => {

expect( optionsHiddenIcon ).toBeInTheDocument();

await selectMenuItem( controlProps.label );
await selectMenuItem( optionalControls.label );

// There are now NO unactivated, optional menu items in the Tools Panel dropdown.
expect(
Expand Down
21 changes: 0 additions & 21 deletions packages/components/src/tools-panel/tools-panel/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,27 +130,6 @@ export function useToolsPanel(
} );
};

// Track whether all optional controls are displayed or not.
// If no optional controls are present, then none are hidden and this will
// be `false`.
const [
areAllOptionalControlsHidden,
setAreAllOptionalControlsHidden,
] = useState( false );

// We need to track whether any optional menu items are active to later
// determine whether the panel is currently empty and any inner wrapper
// should be hidden.
useEffect( () => {
if ( menuItems.optional ) {
const optionalItems = Object.entries( menuItems.optional );
const allControlsHidden =
optionalItems.length > 0 &&
! optionalItems.some( ( [ , isSelected ] ) => isSelected );
setAreAllOptionalControlsHidden( allControlsHidden );
}
}, [ menuItems.optional ] );

const cx = useCx();
const classes = useMemo( () => {
const hasDefaultMenuItems =
Expand Down