Skip to content

Commit

Permalink
test(alerts): add test for edited query (#80498)
Browse files Browse the repository at this point in the history
This PR introduces a regression test for #80075. 

It was reported that editing the `query` of an existing alert rule was
broken, but we didn't have test coverage for this. Now we do!
  • Loading branch information
natemoo-re authored Nov 8, 2024
1 parent b649623 commit 2e3b5b3
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions static/app/views/alerts/rules/metric/ruleForm.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jest.mock('sentry/utils/analytics', () => ({
})),
endSpan: jest.fn(),
},
trackAnalytics: jest.fn(),
}));

describe('Incident Rules Form', () => {
Expand Down Expand Up @@ -599,6 +600,32 @@ describe('Incident Rules Form', () => {
);
});

it('edits query', async () => {
createWrapper({
name: 'Query Rule',
projects: ['project-slug'],
eventTypes: ['num_errors'],
thresholdPeriod: 10,
query: 'is:unresolved',
rule,
ruleId: rule.id,
});

await userEvent.type(screen.getByTestId('query-builder-input'), 'has:http.url');
await userEvent.type(screen.getByTestId('query-builder-input'), '{enter}');

await userEvent.click(screen.getByLabelText('Save Rule'));

expect(editRule).toHaveBeenLastCalledWith(
expect.anything(),
expect.objectContaining({
data: expect.objectContaining({
query: 'has:http.url',
}),
})
);
});

it('switches from percent change to count', async () => {
createWrapper({
ruleId: rule.id,
Expand Down

0 comments on commit 2e3b5b3

Please sign in to comment.