Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .tmp/proof/issue-139-pulse-check.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 82 additions & 0 deletions packages/app/src/components/pulse-check/PulseCheckPage.test.tsx
Original file line number Diff line number Diff line change
@@ -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(
<TestApiProvider apis={[[catalogApiRef, { getEntities }]]}>
<PulseCheckPage />
</TestApiProvider>,
);

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();
});
});
18 changes: 15 additions & 3 deletions packages/app/src/components/pulse-check/PulseCheckPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -22,6 +23,14 @@ import {
import { IncidentTimeline, Incident } from './IncidentTimeline';
import { DeploymentMetrics, DeploymentStats } from './DeploymentMetrics';

const SampleDataNotice = () => (
<Alert severity="info" sx={{ mb: 3 }}>
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.
</Alert>
);

const getSystemMessage = (status: HealthStatus): string | undefined => {
if (status === 'degraded') {
return 'Elevated error rates detected';
Expand Down Expand Up @@ -138,9 +147,10 @@ export const PulseCheckPage = () => {
<Page themeId="tool">
<Header
title="Pulse Check"
subtitle="Monitor the health and status of your services"
subtitle="Explore a service health dashboard with sample data"
/>
<Content>
<SampleDataNotice />
<Box
sx={{
display: 'flex',
Expand All @@ -161,9 +171,10 @@ export const PulseCheckPage = () => {
<Page themeId="tool">
<Header
title="Pulse Check"
subtitle="Monitor the health and status of your services"
subtitle="Explore a service health dashboard with sample data"
/>
<Content>
<SampleDataNotice />
<Box sx={{ textAlign: 'center', py: 4 }}>
<Typography color="error">
Error loading services: {error.message}
Expand All @@ -178,9 +189,10 @@ export const PulseCheckPage = () => {
<Page themeId="tool">
<Header
title="Pulse Check"
subtitle="Monitor the health and status of your services"
subtitle="Explore a service health dashboard with sample data"
/>
<Content>
<SampleDataNotice />
<Box sx={{ mb: 5 }}>
<Box
sx={{
Expand Down
Loading