diff --git a/frontend/packages/console-shared/src/components/catalog/utils/__tests__/catalog-utils.spec.tsx b/frontend/packages/console-shared/src/components/catalog/utils/__tests__/catalog-utils.spec.tsx index ade76508bec..cfb55f640d0 100644 --- a/frontend/packages/console-shared/src/components/catalog/utils/__tests__/catalog-utils.spec.tsx +++ b/frontend/packages/console-shared/src/components/catalog/utils/__tests__/catalog-utils.spec.tsx @@ -4,6 +4,7 @@ import { calculateCatalogItemRelevanceScore, getRedHatPriority, sortCatalogItems, + isCatalogTypeEnabled, } from '../catalog-utils'; import { CatalogSortOrder } from '../types'; @@ -466,3 +467,64 @@ describe('sortCatalogItems', () => { }); }); }); + +describe('isCatalogTypeEnabled - case-insensitive matching', () => { + let originalDeveloperCatalogTypes; + + beforeEach(() => { + originalDeveloperCatalogTypes = window.SERVER_FLAGS.developerCatalogTypes; + delete window.SERVER_FLAGS.developerCatalogTypes; + }); + + afterEach(() => { + if (originalDeveloperCatalogTypes !== undefined) { + window.SERVER_FLAGS.developerCatalogTypes = originalDeveloperCatalogTypes; + } else { + delete window.SERVER_FLAGS.developerCatalogTypes; + } + }); + + it('should return true when no developerCatalogTypes configuration exists', () => { + expect(isCatalogTypeEnabled('operator')).toBe(true); + expect(isCatalogTypeEnabled('HelmChart')).toBe(true); + }); + + it('should perform case-insensitive matching for enabled types', () => { + window.SERVER_FLAGS.developerCatalogTypes = JSON.stringify({ + state: 'Enabled', + enabled: ['operator', 'HelmChart', 'Template'], + }); + + // Exact case match + expect(isCatalogTypeEnabled('operator')).toBe(true); + expect(isCatalogTypeEnabled('HelmChart')).toBe(true); + + // Different capitalization should still match + expect(isCatalogTypeEnabled('Operator')).toBe(true); + expect(isCatalogTypeEnabled('OPERATOR')).toBe(true); + expect(isCatalogTypeEnabled('helmchart')).toBe(true); + expect(isCatalogTypeEnabled('template')).toBe(true); + expect(isCatalogTypeEnabled('TEMPLATE')).toBe(true); + + // Non-enabled type should return false + expect(isCatalogTypeEnabled('Devfile')).toBe(false); + }); + + it('should perform case-insensitive matching for disabled types', () => { + window.SERVER_FLAGS.developerCatalogTypes = JSON.stringify({ + state: 'Disabled', + disabled: ['operator', 'HelmChart'], + }); + + // Disabled types should return false regardless of capitalization + expect(isCatalogTypeEnabled('operator')).toBe(false); + expect(isCatalogTypeEnabled('Operator')).toBe(false); + expect(isCatalogTypeEnabled('OPERATOR')).toBe(false); + expect(isCatalogTypeEnabled('helmchart')).toBe(false); + expect(isCatalogTypeEnabled('HelmChart')).toBe(false); + + // Non-disabled types should return true + expect(isCatalogTypeEnabled('Template')).toBe(true); + expect(isCatalogTypeEnabled('template')).toBe(true); + }); +}); diff --git a/frontend/packages/console-shared/src/components/catalog/utils/catalog-utils.tsx b/frontend/packages/console-shared/src/components/catalog/utils/catalog-utils.tsx index 337fd03e6c7..df4481a9297 100644 --- a/frontend/packages/console-shared/src/components/catalog/utils/catalog-utils.tsx +++ b/frontend/packages/console-shared/src/components/catalog/utils/catalog-utils.tsx @@ -398,15 +398,22 @@ export const applyCatalogItemMetadata = ( export const isCatalogTypeEnabled = (catalogType: string): boolean => { const softwareCatalogTypes = getSoftwareCatalogTypes(); if (softwareCatalogTypes) { + // Normalize catalog type to lowercase for case-insensitive comparison + const normalizedCatalogType = catalogType?.toLowerCase(); + if ( softwareCatalogTypes?.state === CatalogVisibilityState.Enabled && softwareCatalogTypes?.enabled?.length > 0 ) { - return softwareCatalogTypes?.enabled.includes(catalogType); + return softwareCatalogTypes?.enabled.some( + (type) => type.toLowerCase() === normalizedCatalogType, + ); } if (softwareCatalogTypes?.state === CatalogVisibilityState.Disabled) { if (softwareCatalogTypes?.disabled?.length > 0) { - return !softwareCatalogTypes?.disabled.includes(catalogType); + return !softwareCatalogTypes?.disabled.some( + (type) => type.toLowerCase() === normalizedCatalogType, + ); } return false; } @@ -427,7 +434,8 @@ export const useGetAllDisabledSubCatalogs = () => { softwareCatalogTypes?.enabled?.length > 0 ) { const disabledSubCatalogs = catalogTypeExtensions.filter( - (val) => !softwareCatalogTypes?.enabled.includes(val), + (val) => + !softwareCatalogTypes?.enabled.some((type) => type.toLowerCase() === val.toLowerCase()), ); return [disabledSubCatalogs]; }