Skip to content

Commit

Permalink
Replaced use of any with ExclusiveUnion for search props of EuiSelect…
Browse files Browse the repository at this point in the history
…able.

Resolved flaky test for spaces nav.
  • Loading branch information
jeramysoucy committed Aug 1, 2022
1 parent d623e6f commit 712798e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 24 deletions.
47 changes: 30 additions & 17 deletions x-pack/plugins/spaces/public/nav_control/components/spaces_menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import './spaces_menu.scss';

import type { ExclusiveUnion } from '@elastic/eui';
import {
EuiLoadingSpinner,
EuiPopoverFooter,
Expand All @@ -15,7 +16,10 @@ import {
EuiText,
} from '@elastic/eui';
import type { EuiSelectableOption } from '@elastic/eui/src/components/selectable';
import type { EuiSelectableOnChangeEvent } from '@elastic/eui/src/components/selectable/selectable';
import type {
EuiSelectableOnChangeEvent,
EuiSelectableSearchableSearchProps,
} from '@elastic/eui/src/components/selectable/selectable';
import React, { Component, lazy, Suspense } from 'react';

import type { ApplicationStart, Capabilities } from '@kbn/core/public';
Expand Down Expand Up @@ -56,6 +60,30 @@ class SpacesMenuUI extends Component<Props> {
</EuiText>
);

// In the future this could be replaced by EuiSelectableSearchableProps, but at this time is is not exported from EUI
const searchableProps: ExclusiveUnion<
{ searchable: true; searchProps: EuiSelectableSearchableSearchProps<{}> },
{ searchable: false }
> =
this.props.spaces.length >= SPACE_SEARCH_COUNT_THRESHOLD
? {
searchable: true,
searchProps: {
placeholder: i18n.translate(
'xpack.spaces.navControl.spacesMenu.findSpacePlaceholder',
{
defaultMessage: 'Find a space',
}
),
compressed: true,
isClearable: true,
id: 'headerSpacesMenuListSearch',
},
}
: {
searchable: false,
};

return (
<>
<EuiSelectable
Expand All @@ -64,22 +92,7 @@ class SpacesMenuUI extends Component<Props> {
title={i18n.translate('xpack.spaces.navControl.spacesMenu.changeCurrentSpaceTitle', {
defaultMessage: 'Change current space',
})}
searchable={this.props.spaces.length >= SPACE_SEARCH_COUNT_THRESHOLD}
searchProps={
this.props.spaces.length >= SPACE_SEARCH_COUNT_THRESHOLD
? ({
placeholder: i18n.translate(
'xpack.spaces.navControl.spacesMenu.findSpacePlaceholder',
{
defaultMessage: 'Find a space',
}
),
compressed: true,
isClearable: true,
id: 'headerSpacesMenuListSearch',
} as any)
: undefined
}
{...searchableProps}
noMatchesMessage={noSpacesMessage}
options={spaceOptions}
singleSelection={'always'}
Expand Down
8 changes: 4 additions & 4 deletions x-pack/test/functional/apps/spaces/spaces_selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ export default function spaceSelectorFunctionalTests({
await PageObjects.spaceSelector.goToSpecificSpace(space5Id);
await PageObjects.spaceSelector.expectHomePage(space5Id);

// await PageObjects.spaceSelector.openSpacesNav();
// await PageObjects.spaceSelector.goToSpecificSpace(defaultSpaceId);
// await PageObjects.spaceSelector.expectHomePage(defaultSpaceId);

await PageObjects.spaceSelector.openSpacesNav();
await PageObjects.spaceSelector.goToSpecificSpace(anotherSpaceId);
await PageObjects.spaceSelector.expectHomePage(anotherSpaceId);

await PageObjects.spaceSelector.openSpacesNav();
await PageObjects.spaceSelector.goToSpecificSpace(defaultSpaceId);
await PageObjects.spaceSelector.expectHomePage(defaultSpaceId);
});
});

Expand Down
4 changes: 1 addition & 3 deletions x-pack/test/functional/page_objects/space_selector_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ export class SpaceSelectorPageObject extends FtrService {
async goToSpecificSpace(spaceId: string) {
return await this.retry.try(async () => {
this.log.info(`SpaceSelectorPage:goToSpecificSpace(${spaceId})`);
// await this.testSubjects.click(`${spaceId}-selectableSpaceItem`);
const spaceOption = await this.testSubjects.find(`${spaceId}-selectableSpaceItem`);
await spaceOption?.click();
await this.testSubjects.click(`${spaceId}-selectableSpaceItem`);
await this.common.sleep(1000);
});
}
Expand Down

0 comments on commit 712798e

Please sign in to comment.