From def696c310a0d916b549d0206d0b203f408638c1 Mon Sep 17 00:00:00 2001 From: Tim Klever Date: Tue, 1 Apr 2025 19:00:21 -0700 Subject: [PATCH] tests(entityRouteParams): initial test suite Signed-off-by: Tim Klever --- plugins/catalog-react/src/routes.test.ts | 64 ++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 plugins/catalog-react/src/routes.test.ts diff --git a/plugins/catalog-react/src/routes.test.ts b/plugins/catalog-react/src/routes.test.ts new file mode 100644 index 0000000000..58b8707edd --- /dev/null +++ b/plugins/catalog-react/src/routes.test.ts @@ -0,0 +1,64 @@ +/* + * Copyright 2025 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { DEFAULT_NAMESPACE, Entity } from '@backstage/catalog-model'; +import { entityRouteParams } from './routes'; + +const entity: Entity = { + apiVersion: '1', + kind: 'Component', + metadata: { + name: 'Test-Component', + }, +}; + +const expectedEntityRouteParams = { + kind: 'component', + name: 'Test-Component', + namespace: DEFAULT_NAMESPACE, +}; + +const namespacedEntity = { + apiVersion: '1', + kind: 'Component', + metadata: { + name: 'Test-Namespaced-Component', + namespace: 'Test-Namespace', + }, +}; + +const expectedNamespacedEntityRouteParams = { + kind: 'component', + name: 'Test-Namespaced-Component', + namespace: 'test-namespace', +}; + +describe('entityRouteParams', () => { + it.each([ + ['Entity', entity, expectedEntityRouteParams], + [ + 'namespaced Entity', + namespacedEntity, + expectedNamespacedEntityRouteParams, + ], + ])( + 'should return correct route params for %s', + (_type, entityOrRef, expectedRouteParams) => { + const actualRouteParams = entityRouteParams(entityOrRef); + expect(actualRouteParams).toEqual(expectedRouteParams); + }, + ); +});