Skip to content

Commit

Permalink
feat(uptime): Add tests for span count in UptimeChecksGrid
Browse files Browse the repository at this point in the history
  • Loading branch information
evanpurkhiser committed Feb 28, 2025
1 parent 7483da5 commit 25a676b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion static/app/views/alerts/rules/uptime/uptimeChecksGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function UptimeChecksGrid({uptimeRule, uptimeChecks}: Props) {
search: new MutableSearch('').addDisjunctionFilterValues('trace', traceIds),
fields: ['trace', 'count()'],
},
'uptime_checks'
'api.uptime-checks-grid'
);

const traceSpanCounts = spanCountLoading
Expand Down
49 changes: 49 additions & 0 deletions static/app/views/issueDetails/groupUptimeChecks.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {UptimeRuleFixture} from 'sentry-fixture/uptimeRule';
import {render, screen} from 'sentry-test/reactTestingLibrary';

import GroupStore from 'sentry/stores/groupStore';
import PageFiltersStore from 'sentry/stores/pageFiltersStore';
import ProjectsStore from 'sentry/stores/projectsStore';
import {IssueCategory, IssueType} from 'sentry/types/group';
import {getShortEventId} from 'sentry/utils/events';
Expand Down Expand Up @@ -53,6 +54,14 @@ describe('GroupUptimeChecks', () => {
url: `/projects/org-slug/project-slug/uptime/123/`,
body: UptimeRuleFixture(),
});
PageFiltersStore.onInitializeUrlState(
{
projects: [Number(project.id)],
environments: [],
datetime: {period: '24h', start: null, end: null, utc: null},
},
new Set()
);
});

it('renders the empty uptime check table', async () => {
Expand All @@ -75,6 +84,14 @@ describe('GroupUptimeChecks', () => {
url: `/projects/${organization.slug}/${project.slug}/uptime/${uptimeRuleId}/checks/`,
body: [uptimeCheck],
});
MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/events/`,
method: 'GET',
body: {
data: [],
},
match: [MockApiClient.matchQuery({referrer: 'api.uptime-checks-grid'})],
});

render(<GroupUptimeChecks />, {organization, router});
expect(await screen.findByText('All Uptime Checks')).toBeInTheDocument();
Expand All @@ -88,5 +105,37 @@ describe('GroupUptimeChecks', () => {
expect(screen.getByText(`${uptimeCheck.durationMs}ms`)).toBeInTheDocument();
expect(screen.getByText(getShortEventId(uptimeCheck.traceId))).toBeInTheDocument();
expect(screen.getByText(uptimeCheck.regionName)).toBeInTheDocument();

// Span counts also need to load
expect(await screen.findByText('0 spans')).toBeInTheDocument();
});

it('indicates when there are spans in a trace', async () => {
const uptimeCheck = UptimeCheckFixture();
MockApiClient.addMockResponse({
url: `/projects/${organization.slug}/${project.slug}/uptime/${uptimeRuleId}/checks/`,
body: [uptimeCheck],
});
MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/events/`,
method: 'GET',
body: {
data: [{trace: uptimeCheck.traceId, 'count()': 10}],
},
match: [MockApiClient.matchQuery({referrer: 'api.uptime-checks-grid'})],
});

render(<GroupUptimeChecks />, {organization, router});
expect(await screen.findByText('All Uptime Checks')).toBeInTheDocument();

const traceId = getShortEventId(uptimeCheck.traceId);

// TraceID is a not link until we know there are spans
expect(screen.getByText(traceId)).toBeInTheDocument();
expect(screen.queryByRole('link', {name: traceId})).not.toBeInTheDocument();

// Once the span count has loaded it will be a link
expect(await screen.findByText('10 spans')).toBeInTheDocument();
expect(screen.getByRole('link', {name: traceId})).toBeInTheDocument();
});
});

0 comments on commit 25a676b

Please sign in to comment.