Skip to content
This repository has been archived by the owner on Nov 28, 2024. It is now read-only.

Commit

Permalink
CNV-39761: filter lldp enabled or disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
upalatucci committed Mar 21, 2024
1 parent c1bd823 commit aaa68f1
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 2 deletions.
40 changes: 40 additions & 0 deletions cypress/e2e/StatusList.spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
EXPAND_INTERFACES_LIST_TEST_ID,
INTERFACE_DRAWER_TEST_ID,
LLDP_DRAWER_DETAILS_SECTION_TEST_ID,
LLDP_ENABLED_FILTER,
ROW_FILTERS_BUTTON,
} from '../support/selectors';

describe('NodeNetworkState list', () => {
Expand Down Expand Up @@ -83,4 +85,42 @@ describe('NodeNetworkState list', () => {
.should('contain', 'VLANS');
});
});

it('filter by lldp', () => {
cy.intercept('GET', '/api/kubernetes/apis/nmstate.io/v1beta1/nodenetworkstates*', {
fixture: 'NodeNetworkStatusWithLLDP.json',
}).as('getStatuses');

cy.fixture('NodeNetworkStatusWithLLDP.json').then((nnsResponse) => {
const nns = nnsResponse.items[0];
const ifaceWithLLDP = nns.status.currentState.interfaces.find((iface) => iface.lldp?.enabled);
const ifaceWithoutLLDP = nns.status.currentState.interfaces.find(
(iface) => !iface.lldp?.enabled,
);

cy.visit('/k8s/cluster/nmstate.io~v1beta1~NodeNetworkState');

cy.wait(['@getStatuses'], { timeout: 40000 });

cy.get('table').should('contain', nns.metadata.name);

// open filter toolbar
cy.get(ROW_FILTERS_BUTTON).click();

cy.get(LLDP_ENABLED_FILTER).check();

// close filter toolbar
cy.get(ROW_FILTERS_BUTTON).click();

cy.get('table').should('contain', nns.metadata.name);
cy.get(EXPAND_INTERFACES_LIST_TEST_ID).click();
cy.byTestID(EXPAND_INTERFACE_INFO).find('button').click();

cy.byTestID(`${ifaceWithLLDP.type}-${ifaceWithLLDP.name}-open-drawer`).contains(
ifaceWithLLDP.name,
);

cy.byTestID(`${ifaceWithoutLLDP.type}-expandable-section-toggle`).should('not.exist');
});
});
});
4 changes: 4 additions & 0 deletions cypress/support/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ export const EXPAND_INTERFACES_LIST_TEST_ID = '#expand-interfaces-list0';
export const EXPAND_INTERFACE_INFO = 'ethernet-expandable-section-toggle';
export const INTERFACE_DRAWER_TEST_ID = 'interface-drawer';
export const LLDP_DRAWER_DETAILS_SECTION_TEST_ID = 'lldp-section';

export const ROW_FILTERS_BUTTON = 'button.pf-v5-c-select__toggle';

export const LLDP_ENABLED_FILTER = '#enabled[type="checkbox"]';
8 changes: 7 additions & 1 deletion src/views/states/list/components/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InterfaceType, NodeNetworkConfigurationInterface } from '@types';

import { FILTER_TYPES } from '../constants';
import { FILTER_TYPES, LLDP_ENABLED } from '../constants';
import { searchInterfaceByIP } from '../utilts';

export const interfaceFilters: Record<
Expand All @@ -24,6 +24,12 @@ export const interfaceFilters: Record<

return searchInterfaceByIP(searchIPAddress, obj);
},
[FILTER_TYPES.LLDP]: (selectedInput, obj) => {
if (!selectedInput.length) return true;
return selectedInput.some((status) =>
status === LLDP_ENABLED ? Boolean(obj?.lldp?.enabled) : !obj?.lldp?.enabled,
);
},
} as const;

export const filterInterfaces = (
Expand Down
4 changes: 4 additions & 0 deletions src/views/states/list/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ export const FILTER_TYPES = {
INTERFACE_TYPE: 'interface-type',
IP_FILTER: 'ip-filter',
IP_ADDRESS: 'ip-address',
LLDP: 'lldp',
} as const;

export const LLDP_ENABLED = 'enabled';
export const LLDP_DISABLED = 'disabled';
28 changes: 27 additions & 1 deletion src/views/states/list/hooks/useStateFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useNMStateTranslation } from 'src/utils/hooks/useNMStateTranslation';
import { RowFilter } from '@openshift-console/dynamic-plugin-sdk';
import { InterfaceType, NodeNetworkConfigurationInterface, V1beta1NodeNetworkState } from '@types';

import { FILTER_TYPES } from '../constants';
import { FILTER_TYPES, LLDP_DISABLED, LLDP_ENABLED } from '../constants';
import { searchInterfaceByIP } from '../utilts';

const useStateFilters = (): RowFilter<V1beta1NodeNetworkState>[] => {
Expand All @@ -25,6 +25,32 @@ const useStateFilters = (): RowFilter<V1beta1NodeNetworkState>[] => {
filterGroupName: t('Search IP address'),
items: [],
},
{
filterGroupName: t('LLDP'),
type: FILTER_TYPES.LLDP,
filter: (selectedIpTypes, obj) => {
if (!selectedIpTypes.selected.length) return true;
return selectedIpTypes.selected.some((status) =>
obj?.status?.currentState?.interfaces.some((iface) =>
status === LLDP_ENABLED ? Boolean(iface?.lldp?.enabled) : !iface?.lldp?.enabled,
),
);
},
isMatch: (obj, status) =>
obj?.status?.currentState?.interfaces.some((iface) =>
status === LLDP_ENABLED ? Boolean(iface?.lldp?.enabled) : !iface?.lldp?.enabled,
),
items: [
{
id: LLDP_ENABLED,
title: t('Enabled'),
},
{
id: LLDP_DISABLED,
title: t('Disabled'),
},
],
},
{
filterGroupName: t('Interface state'),
type: FILTER_TYPES.INTERFACE_STATE,
Expand Down

0 comments on commit aaa68f1

Please sign in to comment.