Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
calculateCatalogItemRelevanceScore,
getRedHatPriority,
sortCatalogItems,
isCatalogTypeEnabled,
} from '../catalog-utils';
import { CatalogSortOrder } from '../types';

Expand Down Expand Up @@ -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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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];
}
Expand Down