diff --git a/plugins/home/report.api.md b/plugins/home/report.api.md index 023c649ab4..878d8ef646 100644 --- a/plugins/home/report.api.md +++ b/plugins/home/report.api.md @@ -187,6 +187,17 @@ export type LayoutConfiguration = { // @public export type Operators = '<' | '<=' | '==' | '!=' | '>' | '>=' | 'contains'; +// @public +export type QuickStartCardProps = { + modalTitle?: string | React_2.JSX.Element; + docsLinkTitle?: string; + docsLink?: string; + video?: React_2.JSX.Element; + image: React_2.JSX.Element; + cardDescription?: string; + downloadImage?: React_2.JSX.Element; +}; + // @public @deprecated (undocumented) export type RendererProps = RendererProps_2; diff --git a/plugins/home/src/homePageComponents/QuickStart/Content.test.tsx b/plugins/home/src/homePageComponents/QuickStart/Content.test.tsx index 9a923f2481..3394c46da7 100644 --- a/plugins/home/src/homePageComponents/QuickStart/Content.test.tsx +++ b/plugins/home/src/homePageComponents/QuickStart/Content.test.tsx @@ -16,52 +16,59 @@ import { Content } from './Content'; import React from 'react'; -import { catalogApiRef, entityRouteRef } from '@backstage/plugin-catalog-react'; +import userEvent from '@testing-library/user-event'; import { renderInTestApp, TestApiProvider } from '@backstage/test-utils'; -import { catalogApiMock } from '@backstage/plugin-catalog-react/testUtils'; +import ContentImage from './static/backstageSystemModel.png'; -const docsEntities = [ - { - apiVersion: '1', - kind: 'Location', - metadata: { - name: 'getting-started-with-idp', - title: 'Getting Started Docs', - }, - spec: { - type: 'documentation', - }, - }, -]; - -describe('', () => { +describe('', () => { const Wrapper = ({ children }: { children?: React.ReactNode }) => ( - - {children} - + {children} ); - - it('should show expected featured doc and title', async () => { - const { getByTestId, getByText } = await renderInTestApp( + const renderContent = async () => { + return await renderInTestApp( + } + docsLinkTitle="Testing docs link" /> , - { - mountedRoutes: { - '/home': entityRouteRef, - }, - }, ); - const docsCardContent = getByTestId('docs-card-content'); - const docsEntity = getByText('getting-started-with-idp'); - expect(docsCardContent).toContainElement(docsEntity); + }; + + it('should have expected card content', async () => { + const { getByTestId } = await renderContent(); + const docsLink = getByTestId('quick-start-link-to-docs'); + expect(docsLink).toHaveTextContent('Testing docs link'); + expect(docsLink).toHaveAttribute('target', '_blank'); + }); + + it('clicking the link opens the modal', async () => { + const { getByTestId, getByText } = await renderContent(); + // Find the link element + const link = getByText('Onboarding'); + // Simulate a click event on the link + await userEvent.click(link); + // Assert that the modal is visible + const modal = getByTestId('content-modal-open'); + expect(modal).toBeVisible(); + }); + + it('clicking the image opens the modal', async () => { + const { getByTestId } = await renderContent(); + // Find the link element + const link = getByTestId('quick-start-image'); + // Simulate a click event on the link + await userEvent.click(link); + // Assert that the modal is visible + const modal = getByTestId('content-modal-open'); + expect(modal).toBeVisible(); }); }); diff --git a/plugins/home/src/homePageComponents/QuickStart/Content.tsx b/plugins/home/src/homePageComponents/QuickStart/Content.tsx index f6c103a1fc..5de85db1ac 100644 --- a/plugins/home/src/homePageComponents/QuickStart/Content.tsx +++ b/plugins/home/src/homePageComponents/QuickStart/Content.tsx @@ -69,7 +69,7 @@ export const Content = (props: QuickStartCardProps): JSX.Element => { { const [open, setOpen] = useState(false); return ( - + { open={open} onClose={() => setOpen(false)} aria-labelledby="content-modal" - data-cy="content-modal" + data-testid="content-modal" > - + {modalContent}