diff --git a/.tmp/proof/issue-139-pulse-check.png b/.tmp/proof/issue-139-pulse-check.png new file mode 100644 index 0000000..498b4b8 Binary files /dev/null and b/.tmp/proof/issue-139-pulse-check.png differ diff --git a/packages/app/src/components/pulse-check/PulseCheckPage.test.tsx b/packages/app/src/components/pulse-check/PulseCheckPage.test.tsx new file mode 100644 index 0000000..c53ab30 --- /dev/null +++ b/packages/app/src/components/pulse-check/PulseCheckPage.test.tsx @@ -0,0 +1,82 @@ +import { screen } from '@testing-library/react'; +import { renderInTestApp, TestApiProvider } from '@backstage/test-utils'; +import { catalogApiRef } from '@backstage/plugin-catalog-react'; +import { PulseCheckPage } from './PulseCheckPage'; + +describe('PulseCheckPage', () => { + const getEntities = jest.fn(); + + const renderPage = () => + renderInTestApp( + + + , + ); + + const expectSampleDataNotice = () => { + expect(screen.getByRole('alert')).toHaveTextContent( + 'Sample data only. Service names come from the catalog. Health and uptime are simulated; incidents and deployment metrics are examples. This page does not report live service status.', + ); + expect( + screen.getByText('Explore a service health dashboard with sample data'), + ).toBeInTheDocument(); + }; + + beforeEach(() => { + getEntities.mockReset(); + }); + + it('identifies simulated health and fixture metrics on the populated dashboard', async () => { + getEntities.mockResolvedValue({ + items: [ + { + apiVersion: 'backstage.io/v1alpha1', + kind: 'Component', + metadata: { name: 'demo-service' }, + spec: { type: 'service', lifecycle: 'experimental', owner: 'guest' }, + }, + ], + }); + + await renderPage(); + + expectSampleDataNotice(); + expect(screen.getByText('demo-service')).toBeInTheDocument(); + expect(screen.getByText('Database connection timeout')).toBeInTheDocument(); + expect(screen.getByText('Total Deployments')).toBeInTheDocument(); + expect(screen.queryByRole('progressbar')).not.toBeInTheDocument(); + }); + + it('keeps the sample-data notice visible while services load', async () => { + getEntities.mockReturnValue(new Promise(() => {})); + + await renderPage(); + + expectSampleDataNotice(); + expect(screen.getByRole('progressbar')).toBeInTheDocument(); + }); + + it('keeps the sample-data notice visible when the catalog fails', async () => { + getEntities.mockRejectedValue(new Error('Catalog unavailable')); + + await renderPage(); + + expectSampleDataNotice(); + expect( + screen.getByText('Error loading services: Catalog unavailable'), + ).toBeInTheDocument(); + expect(screen.queryByText('Total Deployments')).not.toBeInTheDocument(); + }); + + it('identifies example metrics even when the catalog has no services', async () => { + getEntities.mockResolvedValue({ items: [] }); + + await renderPage(); + + expectSampleDataNotice(); + expect( + screen.getByText('No services found in the catalog.'), + ).toBeInTheDocument(); + expect(screen.getByText('Total Deployments')).toBeInTheDocument(); + }); +}); diff --git a/packages/app/src/components/pulse-check/PulseCheckPage.tsx b/packages/app/src/components/pulse-check/PulseCheckPage.tsx index 68cd1b4..e60a623 100644 --- a/packages/app/src/components/pulse-check/PulseCheckPage.tsx +++ b/packages/app/src/components/pulse-check/PulseCheckPage.tsx @@ -5,6 +5,7 @@ import Grid from '@mui/material/Grid'; import CircularProgress from '@mui/material/CircularProgress'; import Card from '@mui/material/Card'; import CardContent from '@mui/material/CardContent'; +import Alert from '@mui/material/Alert'; import { useTheme } from '@mui/material/styles'; import { Page, Header, Content } from '@backstage/core-components'; import { useApi } from '@backstage/core-plugin-api'; @@ -22,6 +23,14 @@ import { import { IncidentTimeline, Incident } from './IncidentTimeline'; import { DeploymentMetrics, DeploymentStats } from './DeploymentMetrics'; +const SampleDataNotice = () => ( + + Sample data only. Service names come from the catalog. Health and uptime are + simulated; incidents and deployment metrics are examples. This page does not + report live service status. + +); + const getSystemMessage = (status: HealthStatus): string | undefined => { if (status === 'degraded') { return 'Elevated error rates detected'; @@ -138,9 +147,10 @@ export const PulseCheckPage = () => {
+ {
+ Error loading services: {error.message} @@ -178,9 +189,10 @@ export const PulseCheckPage = () => {
+