From 9dfa8c099d14eec6564edaf3220e791797e3667c Mon Sep 17 00:00:00 2001 From: Robb Hamilton Date: Tue, 9 Dec 2025 10:38:42 -0500 Subject: [PATCH] OCPBUGS-67004: fix Search page issues with regard to namespace --- .../tests/app/filtering-and-searching.cy.ts | 45 +++++++++++++------ frontend/public/components/search.tsx | 8 +++- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/frontend/packages/integration-tests-cypress/tests/app/filtering-and-searching.cy.ts b/frontend/packages/integration-tests-cypress/tests/app/filtering-and-searching.cy.ts index 892a02f38c3..00232e23eeb 100644 --- a/frontend/packages/integration-tests-cypress/tests/app/filtering-and-searching.cy.ts +++ b/frontend/packages/integration-tests-cypress/tests/app/filtering-and-searching.cy.ts @@ -7,6 +7,9 @@ import { listPage } from '../../views/list-page'; import { modal } from '../../views/modal'; import * as yamlEditor from '../../views/yaml-editor'; +const SEARCH_NAMESPACE = 'openshift-authentication-operator'; +const SEARCH_DEPLOYMENT_NAME = 'authentication-operator'; + describe('Filtering and Searching', () => { let WORKLOAD_NAME; let WORKLOAD_LABEL; @@ -52,14 +55,13 @@ describe('Filtering and Searching', () => { cy.deleteProjectWithCLI(testName); }); - // disabled as listPage.rows.shouldExist isn't a valid test - xit('filters Pod from object detail', () => { + it('filters Pod from object detail', () => { cy.visit(`/k8s/ns/${testName}/deployments`); - listPage.rows.shouldExist(WORKLOAD_NAME); + listPage.dvRows.shouldExist(WORKLOAD_NAME); cy.visit(`/k8s/ns/${testName}/deployments/${WORKLOAD_NAME}/pods`); - listPage.rows.shouldBeLoaded(); - listPage.filter.byName(WORKLOAD_NAME); - listPage.rows.shouldExist(WORKLOAD_NAME); + listPage.dvRows.shouldBeLoaded(); + listPage.dvFilter.byName(WORKLOAD_NAME); + listPage.dvRows.countShouldBe(3); }); it('filters invalid Pod from object detail', () => { @@ -70,12 +72,28 @@ describe('Filtering and Searching', () => { cy.get('.pf-v6-l-bullseye').should('contain', 'No Pods found'); }); }); - // disabled as listPage.rows.shouldExist isn't a valid test - xit('filters from Pods list', () => { + + it('filters from Pods list', () => { cy.visit(`/k8s/all-namespaces/pods`); - listPage.rows.shouldBeLoaded(); - listPage.filter.byName(WORKLOAD_NAME); - listPage.rows.shouldExist(WORKLOAD_NAME); + listPage.dvRows.shouldBeLoaded(); + listPage.dvFilter.byName(WORKLOAD_NAME); + listPage.dvRows.countShouldBe(3); + }); + + it('displays namespace on Search when All Namespaces is selected', () => { + cy.visit( + `/search/all-namespaces?kind=apps~v1~Deployment&page=1&perPage=50&name=${SEARCH_DEPLOYMENT_NAME}`, + ); + listPage.dvRows.countShouldBe(1); + cy.get(`[data-test-id="${SEARCH_NAMESPACE}"]`).should('exist'); + }); + + it('does not display namespace on Search when namespace is selected', () => { + cy.visit( + `/search/ns/${SEARCH_NAMESPACE}?kind=apps~v1~Deployment&page=1&perPage=50&name=${SEARCH_DEPLOYMENT_NAME}`, + ); + listPage.dvRows.countShouldBe(1); + cy.get(`[data-test-id="${SEARCH_NAMESPACE}"]`).should('not.exist'); }); it('searches for object by kind and label', () => { @@ -83,11 +101,10 @@ describe('Filtering and Searching', () => { listPage.dvRows.shouldExist(WORKLOAD_NAME); }); - // disabled as listPage.rows.shouldExist isn't a valid test - xit('searches for object by kind, label, and name', () => { + it('searches for object by kind, label, and name', () => { cy.visit(`/search/all-namespaces`, { qs: { kind: 'Pod', q: 'app=name', name: WORKLOAD_NAME }, }); - listPage.rows.shouldExist(WORKLOAD_NAME); + listPage.dvRows.countShouldBe(3); }); }); diff --git a/frontend/public/components/search.tsx b/frontend/public/components/search.tsx index 002a85f0fa0..428f5b5980c 100644 --- a/frontend/public/components/search.tsx +++ b/frontend/public/components/search.tsx @@ -49,6 +49,7 @@ import { } from '@console/dynamic-plugin-sdk/src/extensions/pages'; import { useActivePerspective } from '@console/dynamic-plugin-sdk/src/perspective'; import { useActiveNamespace, useK8sModel } from '@console/dynamic-plugin-sdk/src/lib-core'; +import { ALL_NAMESPACES_KEY } from '@console/shared/src/constants/common'; const ResourceList = ({ kind, mock, namespace, selector, nameFilter }) => { const { plural } = useParams<{ plural?: string }>(); @@ -62,7 +63,11 @@ const ResourceList = ({ kind, mock, namespace, selector, nameFilter }) => { referenceForModel(kindObj), () => Promise.resolve(DefaultPage), ); - const ns = kindObj.namespaced ? namespace : undefined; + // When "All Projects" is selected, namespace is ALL_NAMESPACES_KEY. + // For namespaced resources, we need to pass undefined to fetch from all namespaces. + // For cluster-scoped resources, always use undefined. + const ns = kindObj.namespaced && namespace !== ALL_NAMESPACES_KEY ? namespace : undefined; + const showNamespaceOverride = namespace === ALL_NAMESPACES_KEY; return ( { badge={getBadgeFromType(kindObj.badge)} hideNameLabelFilters hideColumnManagement + showNamespaceOverride={showNamespaceOverride} /> ); };