Skip to content

Commit 1a0937f

Browse files
committed
add and update tests
1 parent a3115d3 commit 1a0937f

File tree

4 files changed

+125
-7
lines changed

4 files changed

+125
-7
lines changed

static/app/views/alerts/rules/metric/edit.spec.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ describe('MetricRulesEdit', () => {
267267
).toBeInTheDocument();
268268
});
269269

270-
it('preserves SERVER_WEIGHTED extrapolation mode when editing and saving', async () => {
270+
it('changes SERVER_WEIGHTED extrapolation mode to UNKNOWN when editing and saving', async () => {
271271
const {organization, project} = initializeOrg();
272272
const ruleWithExtrapolation = MetricRuleFixture({
273273
id: '5',
@@ -317,7 +317,7 @@ describe('MetricRulesEdit', () => {
317317
'/organizations/org-slug/events-stats/',
318318
expect.objectContaining({
319319
query: expect.objectContaining({
320-
extrapolationMode: 'serverOnly',
320+
extrapolationMode: 'sampleWeighted',
321321
sampling: SAMPLING_MODE.NORMAL,
322322
}),
323323
})
@@ -335,14 +335,14 @@ describe('MetricRulesEdit', () => {
335335
expect.anything(),
336336
expect.objectContaining({
337337
data: expect.objectContaining({
338-
extrapolationMode: ExtrapolationMode.SERVER_WEIGHTED,
338+
extrapolationMode: ExtrapolationMode.UNKNOWN,
339339
}),
340340
method: 'PUT',
341341
})
342342
);
343343
});
344344

345-
it('preserves NONE extrapolation mode when editing and saving', async () => {
345+
it('changes NONE extrapolation mode to UNKNOWN when editing and saving', async () => {
346346
const {organization, project} = initializeOrg();
347347
const ruleWithNoExtrapolation = MetricRuleFixture({
348348
id: '6',
@@ -392,8 +392,8 @@ describe('MetricRulesEdit', () => {
392392
'/organizations/org-slug/events-stats/',
393393
expect.objectContaining({
394394
query: expect.objectContaining({
395-
extrapolationMode: 'none',
396-
sampling: SAMPLING_MODE.HIGH_ACCURACY,
395+
extrapolationMode: 'sampleWeighted',
396+
sampling: SAMPLING_MODE.NORMAL,
397397
}),
398398
})
399399
);
@@ -410,7 +410,7 @@ describe('MetricRulesEdit', () => {
410410
expect.anything(),
411411
expect.objectContaining({
412412
data: expect.objectContaining({
413-
extrapolationMode: ExtrapolationMode.NONE,
413+
extrapolationMode: ExtrapolationMode.UNKNOWN,
414414
}),
415415
method: 'PUT',
416416
})

static/app/views/alerts/rules/metric/ruleConditionsForm.spec.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
AlertRuleComparisonType,
88
Dataset,
99
EventTypes,
10+
ExtrapolationMode,
1011
} from 'sentry/views/alerts/rules/metric/types';
1112
import type {AlertType} from 'sentry/views/alerts/wizard/options';
1213

@@ -111,4 +112,31 @@ describe('RuleConditionsForm', () => {
111112
)
112113
).toBeInTheDocument();
113114
});
115+
116+
it('renders extrapolation mode warning', async () => {
117+
render(
118+
<RuleConditionsForm
119+
{...props}
120+
eventTypes={[EventTypes.TRACE_ITEM_SPAN]}
121+
dataset={Dataset.EVENTS_ANALYTICS_PLATFORM}
122+
extrapolationMode={ExtrapolationMode.SERVER_WEIGHTED}
123+
organization={organization}
124+
router={router}
125+
isLowConfidenceChartData
126+
/>,
127+
{
128+
organization: {
129+
...organization,
130+
features: ['search-query-builder-alerts', 'visibility-explore-view'],
131+
},
132+
}
133+
);
134+
135+
await screen.findByPlaceholderText(
136+
'Filter transactions by URL, tags, and other properties\u2026'
137+
);
138+
expect(
139+
screen.getByText(/This chart may look different from the alert details chart./)
140+
).toBeInTheDocument();
141+
});
114142
});

static/app/views/alerts/rules/metric/ruleForm.spec.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
AlertRuleSensitivity,
1919
Dataset,
2020
EventTypes,
21+
ExtrapolationMode,
2122
} from 'sentry/views/alerts/rules/metric/types';
2223

2324
jest.mock('sentry/actionCreators/indicator');
@@ -711,6 +712,45 @@ describe('Incident Rules Form', () => {
711712
);
712713
});
713714

715+
it('changes extrapolation mode when editing migrated transaction alert rule', async () => {
716+
organization.features = [
717+
...organization.features,
718+
'performance-view',
719+
'visibility-explore-view',
720+
'discover-saved-queries-deprecation',
721+
];
722+
const metricRule = MetricRuleFixture();
723+
createWrapper({
724+
rule: {
725+
...metricRule,
726+
aggregate: 'count(span.duration)',
727+
eventTypes: ['trace_item_span'],
728+
dataset: 'events_analytics_platform',
729+
extrapolationMode: ExtrapolationMode.SERVER_WEIGHTED,
730+
},
731+
ruleId: rule.id,
732+
});
733+
734+
await userEvent.click(screen.getByLabelText('Save Rule'));
735+
736+
expect(editRule).toHaveBeenLastCalledWith(
737+
expect.anything(),
738+
expect.objectContaining({
739+
data: expect.objectContaining({
740+
aggregate: 'count(span.duration)',
741+
dataset: 'events_analytics_platform',
742+
eventTypes: ['trace_item_span'],
743+
id: '4',
744+
name: 'My Incident Rule',
745+
projects: ['project-slug'],
746+
query: '',
747+
queryType: 1,
748+
extrapolationMode: ExtrapolationMode.UNKNOWN,
749+
}),
750+
})
751+
);
752+
});
753+
714754
it('switches from percent change to count', async () => {
715755
createWrapper({
716756
ruleId: rule.id,

static/app/views/alerts/rules/metric/triggers/chart/index.spec.tsx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
AlertRuleComparisonType,
1010
AlertRuleThresholdType,
1111
Dataset,
12+
ExtrapolationMode,
1213
} from 'sentry/views/alerts/rules/metric/types';
1314
import {SAMPLING_MODE} from 'sentry/views/explore/hooks/useProgressiveQuery';
1415
import {TraceItemDataset} from 'sentry/views/explore/types';
@@ -260,4 +261,53 @@ describe('Incident Rules Create', () => {
260261
})
261262
);
262263
});
264+
265+
it('uses unknown extrapolation mode for editing a migrated alert', async () => {
266+
const {organization, project, router} = initializeOrg();
267+
268+
render(
269+
<TriggersChart
270+
theme={theme}
271+
api={api}
272+
location={router.location}
273+
organization={organization}
274+
projects={[project]}
275+
query=""
276+
timeWindow={1}
277+
aggregate="count(span.duration)"
278+
dataset={Dataset.EVENTS_ANALYTICS_PLATFORM}
279+
triggers={[]}
280+
environment={null}
281+
comparisonType={AlertRuleComparisonType.COUNT}
282+
resolveThreshold={null}
283+
thresholdType={AlertRuleThresholdType.BELOW}
284+
newAlertOrQuery
285+
onDataLoaded={() => {}}
286+
isQueryValid
287+
showTotalCount
288+
traceItemType={TraceItemDataset.SPANS}
289+
extrapolationMode={ExtrapolationMode.NONE}
290+
/>
291+
);
292+
293+
expect(await screen.findByTestId('area-chart')).toBeInTheDocument();
294+
expect(await screen.findByTestId('alert-total-events')).toBeInTheDocument();
295+
296+
expect(eventStatsMock).toHaveBeenCalledWith(
297+
expect.anything(),
298+
expect.objectContaining({
299+
query: {
300+
interval: '1m',
301+
project: [2],
302+
query: '',
303+
statsPeriod: '14d',
304+
yAxis: 'count(span.duration)',
305+
referrer: 'api.organization-event-stats',
306+
dataset: 'spans',
307+
sampling: SAMPLING_MODE.NORMAL,
308+
extrapolationMode: 'sampleWeighted',
309+
},
310+
})
311+
);
312+
});
263313
});

0 commit comments

Comments
 (0)