diff --git a/plugins/catalog-react/src/components/EntityPeekAheadPopover/EntityPeekAheadPopover.stories.tsx b/plugins/catalog-react/src/components/EntityPeekAheadPopover/EntityPeekAheadPopover.stories.tsx new file mode 100644 index 0000000000..c31e5320ef --- /dev/null +++ b/plugins/catalog-react/src/components/EntityPeekAheadPopover/EntityPeekAheadPopover.stories.tsx @@ -0,0 +1,114 @@ +/* + * Copyright 2020 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 React, { ComponentType } from 'react'; +import { + EntityPeekAheadPopover, + EntityPeekAheadPopoverProps, +} from './EntityPeekAheadPopover'; +import Button from '@material-ui/core/Button'; +import { wrapInTestApp, TestApiProvider } from '@backstage/test-utils'; +import { catalogApiRef } from '../../api'; +import { CompoundEntityRef } from '@backstage/catalog-model'; +import { entityRouteRef } from '../../routes'; +import { CatalogApi } from '@backstage/catalog-client'; + +const mockCatalogApi = { + getEntityByRef: async (entityRef: CompoundEntityRef) => { + if ( + entityRef.namespace === 'default' && + entityRef.name === 'playback' && + entityRef.kind === 'component' + ) { + return { + kind: 'Component', + metadata: { + name: 'playback', + namespace: 'default', + description: 'Details about the playback service', + }, + }; + } + if ( + entityRef.namespace === 'default' && + entityRef.name === 'fname.lname' && + entityRef.kind === 'user' + ) { + return { + kind: 'User', + metadata: { + name: 'fname.lname', + namespace: 'default', + }, + spec: { + profile: { + email: 'fname.lname@example.com', + }, + }, + }; + } + return undefined; + }, +}; + +const defaultArgs = { + entityRef: { + namespace: 'default', + name: 'playback', + kind: 'component', + }, +}; + +export default { + title: 'Catalog /PeekAheadPopover', + decorators: [ + (Story: ComponentType<{}>) => + wrapInTestApp( + <> + + + + , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name': entityRouteRef, + }, + }, + ), + ], +}; + +export const Default = (args: EntityPeekAheadPopoverProps) => ( + + + +); +Default.args = defaultArgs; + +export const User = (args: EntityPeekAheadPopoverProps) => ( + + + +); +User.args = { + entityRef: { + kind: 'user', + namespace: 'default', + name: 'fname.lname', + }, +}; diff --git a/storybook/.storybook/main.js b/storybook/.storybook/main.js index e523b68337..3d92237438 100644 --- a/storybook/.storybook/main.js +++ b/storybook/.storybook/main.js @@ -12,6 +12,7 @@ const BACKSTAGE_CORE_STORIES = [ 'plugins/search-react', 'plugins/home', 'plugins/stack-overflow', + 'plugins/catalog-react', ]; // Some configuration needs to be available directly on the exported object