Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
50 changes: 50 additions & 0 deletions src/app-layout/__tests__/multi-layout-props.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ describe('mergeMultiAppLayoutProps', () => {
id: 'drawer-global',
ariaLabels: { drawerName: 'Global Drawer' },
content: <div>Global Drawer Content</div>,
trigger: {
iconName: 'add-plus',
},
},
],
onActiveGlobalDrawersChange: mockParentActiveGlobalDrawerChange,
Expand Down Expand Up @@ -117,12 +120,59 @@ describe('mergeMultiAppLayoutProps', () => {
id: 'drawer-global',
ariaLabels: { drawerName: 'Global Drawer' },
content: <div>Global Drawer Content</div>,
trigger: {
iconName: 'add-plus',
},
},
],
onActiveGlobalDrawersChange: mockParentActiveGlobalDrawerChange,
});
});

it('should merge ownProps and additionalProps (triggerless global drawers)', () => {
const result = mergeProps(ownProps, [
{
...additionalPropsBase[0],
globalDrawers: [
{
id: 'drawer-global',
ariaLabels: { drawerName: 'Global Drawer' },
content: <div>Global Drawer Content</div>,
},
],
},
additionalPropsBase[1],
]);

expect(result).toEqual({
//asserting new aria labels overwrite existing yet preserve others
ariaLabels: {
navigation: 'New Navigation',
drawers: 'Drawers',
},
hasNavigation: true,
navigationOpen: true,
navigationFocusRef: ownProps.navigationFocusRef,
onNavigationToggle: mockParentNavigationToggle,
hasBreadcrumbsPortal: true,
hasSplitPanel: true,
splitPanelToggleProps: {
displayed: true,
active: false,
position: 'bottom',
controlId: 'test',
ariaLabel: 'test',
},
splitPanelFocusRef: ownProps.splitPanelFocusRef,
onSplitPanelToggle: mockParentSplitPanelToggle,
//asserting the ownProps drawer is not overwritten
activeDrawerId: ownProps.activeDrawerId,
drawers: ownProps.drawers,
drawersFocusRef: ownProps.drawersFocusRef,
onActiveDrawerChange: mockParentActiveDrawerChange,
});
});

it('should return null if no fields are defined, except ariaLabels', () => {
const result = mergeProps({ ariaLabels: {} } as SharedProps, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ export const mergeProps: MergeProps = (ownProps, additionalProps) => {
toolbar.drawersFocusRef = props.drawersFocusRef;
toolbar.onActiveDrawerChange = props.onActiveDrawerChange;
}
if (props.globalDrawers && !checkAlreadyExists(!!toolbar.globalDrawers, 'globalDrawers')) {
if (
props.globalDrawers &&
props.globalDrawers.some(drawer => drawer.trigger) &&
!checkAlreadyExists(!!toolbar.globalDrawers, 'globalDrawers')
) {
toolbar.globalDrawersFocusControl = props.globalDrawersFocusControl;
toolbar.globalDrawers = props.globalDrawers;
toolbar.activeGlobalDrawersIds = props.activeGlobalDrawersIds;
Expand Down
Loading