From f88981fb1deeba517b04df2da2ae4e0e8344f7e7 Mon Sep 17 00:00:00 2001 From: Brian Fletcher Date: Fri, 9 Dec 2022 14:13:57 +0000 Subject: [PATCH] add unit test for peek ahead popover Signed-off-by: Brian Fletcher --- .../EntityPeekAheadPopover.test.tsx | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 plugins/catalog-react/src/components/EntityPeekAheadPopover/EntityPeekAheadPopover.test.tsx diff --git a/plugins/catalog-react/src/components/EntityPeekAheadPopover/EntityPeekAheadPopover.test.tsx b/plugins/catalog-react/src/components/EntityPeekAheadPopover/EntityPeekAheadPopover.test.tsx new file mode 100644 index 0000000000..7053969a09 --- /dev/null +++ b/plugins/catalog-react/src/components/EntityPeekAheadPopover/EntityPeekAheadPopover.test.tsx @@ -0,0 +1,72 @@ +/* + * Copyright 2021 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 { fireEvent, render, screen } from '@testing-library/react'; +import React from 'react'; +import { EntityPeekAheadPopover } from './EntityPeekAheadPopover'; +import { ApiProvider } from '@backstage/core-app-api'; +import { TestApiRegistry } from '@backstage/test-utils'; +import { catalogApiRef } from '../../api'; +import { CompoundEntityRef, Entity } from '@backstage/catalog-model'; +import { CatalogApi } from '@backstage/catalog-client'; + +const catalogApi: Partial = { + getEntityByRef: async ( + entityRef: CompoundEntityRef, + ): Promise => { + if ( + entityRef === + { name: 'service1', namespace: 'default', kind: 'component ' } + ) { + return { + apiVersion: '', + kind: 'Component', + metadata: { + namespace: 'default', + name: 'service1', + }, + spec: { + tags: ['java'], + }, + }; + } + return undefined; + }, +}; + +const apis = TestApiRegistry.from([catalogApiRef, catalogApi]); + +describe('', () => { + it('renders all owners', async () => { + render( + + +
asdf
+
+
, + ); + expect(screen.getByText('asdf')).toBeInTheDocument(); + expect(screen.queryByText('service1')).toBeNull(); + fireEvent.mouseOver(screen.getByTestId('popover')); + expect(screen.getByText('service1')).toBeInTheDocument(); + }); +});