Skip to content

Commit

Permalink
ODC-7671: Update FilterDropdown tests
Browse files Browse the repository at this point in the history
  • Loading branch information
logonoff committed Aug 30, 2024
1 parent 06507d1 commit 82a9ffe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
9 changes: 6 additions & 3 deletions frontend/packages/topology/src/filters/FilterDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,12 @@ const FilterDropdown: React.FC<FilterDropdownProps> = ({
);

const toggle = (toggleRef: React.Ref<MenuToggleElement>) => (
<MenuToggle ref={toggleRef} onClick={() => setIsOpen(!isOpen)} isExpanded={isOpen}>
<MenuToggle
ref={toggleRef}
onClick={() => setIsOpen(!isOpen)}
isExpanded={isOpen}
isDisabled={isSelectDisabled}
>
{t('topology~Display options')}
</MenuToggle>
);
Expand All @@ -136,8 +141,6 @@ const FilterDropdown: React.FC<FilterDropdownProps> = ({
<Select
toggle={toggle}
className="odc-topology-filter-dropdown__select"
customContent={selectContent}
isDisabled={isSelectDisabled}
onToggle={onToggle}
isOpen={isOpen}
onSelect={onSelect}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from 'react';
import { Switch } from '@patternfly/react-core';
import { SelectOption as SelectOptionDeprecated } from '@patternfly/react-core/deprecated';
import { Switch, SelectOption } from '@patternfly/react-core';
import { mount, shallow } from 'enzyme';
import { DisplayFilters, TopologyDisplayFilterType, TopologyViewType } from '../../topology-types';
import {
Expand All @@ -15,6 +14,19 @@ jest.mock('@console/shared/src/hooks/useTelemetry', () => ({
useTelemetry: () => {},
}));

// FIXME Remove this code when jest is updated to at least 25.1.0 -- see https://github.com/jsdom/jsdom/issues/1555
if (!Element.prototype.closest) {
Element.prototype.closest = function (this: Element, selector: string) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
let el: Element | null = this;
while (el) {
if (el.matches(selector)) return el;
el = el.parentElement;
}
return null;
};
}

describe(FilterDropdown.displayName, () => {
let dropdownFilter: DisplayFilters;
let onChange: () => void;
Expand Down Expand Up @@ -45,7 +57,7 @@ describe(FilterDropdown.displayName, () => {
opened
/>,
);
expect(wrapper.find(SelectOptionDeprecated)).toHaveLength(DEFAULT_TOPOLOGY_FILTERS.length - 1);
expect(wrapper.find(SelectOption)).toHaveLength(DEFAULT_TOPOLOGY_FILTERS.length - 1);
});

it('should hide the show filters for list view', () => {
Expand All @@ -58,7 +70,7 @@ describe(FilterDropdown.displayName, () => {
opened
/>,
);
expect(wrapper.find(SelectOptionDeprecated)).toHaveLength(
expect(wrapper.find(SelectOption)).toHaveLength(
DEFAULT_TOPOLOGY_FILTERS.filter((f) => f.type !== TopologyDisplayFilterType.show).length - 1,
);
});
Expand All @@ -73,7 +85,7 @@ describe(FilterDropdown.displayName, () => {
opened
/>,
);
expect(wrapper.find(SelectOptionDeprecated)).toHaveLength(1);
expect(wrapper.find(SelectOption)).toHaveLength(1);
});

it('should contain the expand groups switch', () => {
Expand All @@ -100,6 +112,6 @@ describe(FilterDropdown.displayName, () => {
opened
/>,
);
expect(wrapper.find(SelectOptionDeprecated).first().props().isDisabled).toBeTruthy();
expect(wrapper.find('[disabled].pf-v5-c-menu-toggle')).toBeTruthy();
});
});

0 comments on commit 82a9ffe

Please sign in to comment.