123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- import {EventFixture} from 'sentry-fixture/event';
- import {GroupFixture} from 'sentry-fixture/group';
- import {OrganizationFixture} from 'sentry-fixture/organization';
- import {ProjectFixture} from 'sentry-fixture/project';
- import {render, screen} from 'sentry-test/reactTestingLibrary';
- import {IssueCategory, IssueType} from 'sentry/types/group';
- import {IssueDetailsContext} from 'sentry/views/issueDetails/streamline/context';
- import {
- DetectorSection,
- getDetectorDetails,
- } from 'sentry/views/issueDetails/streamline/sidebar/detectorSection';
- describe('DetectorSection', () => {
- const detectorId = '123';
- const organization = OrganizationFixture();
- const project = ProjectFixture();
- const issueDetailsContext = {
- sectionData: {},
- detectorDetails: {},
- isSidebarOpen: true,
- navScrollMargin: 0,
- eventCount: 0,
- dispatch: jest.fn(),
- };
- it('does not display detector details when no detector is found', () => {
- const event = EventFixture();
- const group = GroupFixture();
- const detectorDetails = getDetectorDetails({event, organization, project});
- const {container} = render(
- <IssueDetailsContext.Provider value={{...issueDetailsContext, detectorDetails}}>
- <DetectorSection group={group} project={project} />
- </IssueDetailsContext.Provider>
- );
- expect(container).toBeEmptyDOMElement();
- });
- it('displays the detector details for a metric issue', () => {
- const event = EventFixture({
- contexts: {
- metric_alert: {
- alert_rule_id: '123',
- },
- },
- });
- const group = GroupFixture({
- issueCategory: IssueCategory.METRIC_ALERT,
- issueType: IssueType.METRIC_ISSUE_POC,
- });
- const detectorDetails = getDetectorDetails({event, organization, project});
- render(
- <IssueDetailsContext.Provider value={{...issueDetailsContext, detectorDetails}}>
- <DetectorSection group={group} project={project} />
- </IssueDetailsContext.Provider>
- );
- expect(screen.getByText('Metric Alert Detector')).toBeInTheDocument();
- const link = screen.getByRole('button', {name: 'View detector details'});
- expect(link).toHaveAttribute(
- 'href',
- `/organizations/${organization.slug}/alerts/rules/details/${detectorId}/`
- );
- expect(
- screen.getByText(
- 'This issue was created by a metric alert detector. View the detector details to learn more.'
- )
- ).toBeInTheDocument();
- });
- it('displays the detector details for a cron monitor', () => {
- const event = EventFixture({
- tags: [
- {
- key: 'monitor.slug',
- value: detectorId,
- },
- ],
- });
- const group = GroupFixture({
- issueCategory: IssueCategory.CRON,
- issueType: IssueType.MONITOR_CHECK_IN_FAILURE,
- });
- const detectorDetails = getDetectorDetails({event, organization, project});
- render(
- <IssueDetailsContext.Provider value={{...issueDetailsContext, detectorDetails}}>
- <DetectorSection group={group} project={project} />
- </IssueDetailsContext.Provider>
- );
- expect(screen.getByText('Cron Monitor')).toBeInTheDocument();
- const link = screen.getByRole('button', {name: 'View monitor details'});
- expect(link).toHaveAttribute(
- 'href',
- `/organizations/${organization.slug}/alerts/rules/crons/${project.slug}/${detectorId}/details/`
- );
- expect(
- screen.getByText(
- 'This issue was created by a cron monitor. View the monitor details to learn more.'
- )
- ).toBeInTheDocument();
- });
- it('displays the detector details for an uptime monitor', () => {
- const event = EventFixture({
- tags: [
- {
- key: 'uptime_rule',
- value: detectorId,
- },
- ],
- });
- const group = GroupFixture({
- issueCategory: IssueCategory.UPTIME,
- issueType: IssueType.UPTIME_DOMAIN_FAILURE,
- });
- const detectorDetails = getDetectorDetails({event, organization, project});
- render(
- <IssueDetailsContext.Provider value={{...issueDetailsContext, detectorDetails}}>
- <DetectorSection group={group} project={project} />
- </IssueDetailsContext.Provider>
- );
- expect(screen.getByText('Uptime Monitor')).toBeInTheDocument();
- const link = screen.getByRole('button', {name: 'View alert details'});
- expect(link).toHaveAttribute(
- 'href',
- `/organizations/${organization.slug}/alerts/rules/uptime/${project.slug}/${detectorId}/details/`
- );
- expect(
- screen.getByText(
- 'This issue was created by an uptime monitoring alert rule after detecting 3 consecutive failed checks.'
- )
- ).toBeInTheDocument();
- });
- });
|