ruleForm.spec.tsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. import {EventsStatsFixture} from 'sentry-fixture/events';
  2. import {IncidentTriggerFixture} from 'sentry-fixture/incidentTrigger';
  3. import {MetricRuleFixture} from 'sentry-fixture/metricRule';
  4. import {initializeOrg} from 'sentry-test/initializeOrg';
  5. import {act, render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  6. import selectEvent from 'sentry-test/selectEvent';
  7. import {addErrorMessage} from 'sentry/actionCreators/indicator';
  8. import type FormModel from 'sentry/components/forms/model';
  9. import ProjectsStore from 'sentry/stores/projectsStore';
  10. import {ActivationConditionType, MonitorType} from 'sentry/types/alerts';
  11. import {metric} from 'sentry/utils/analytics';
  12. import RuleFormContainer from 'sentry/views/alerts/rules/metric/ruleForm';
  13. import {
  14. AlertRuleComparisonType,
  15. AlertRuleSeasonality,
  16. AlertRuleSensitivity,
  17. Dataset,
  18. } from 'sentry/views/alerts/rules/metric/types';
  19. import {permissionAlertText} from 'sentry/views/settings/project/permissionAlert';
  20. jest.mock('sentry/actionCreators/indicator');
  21. jest.mock('sentry/utils/analytics', () => ({
  22. metric: {
  23. startSpan: jest.fn(() => ({
  24. setTag: jest.fn(),
  25. setData: jest.fn(),
  26. })),
  27. endSpan: jest.fn(),
  28. },
  29. }));
  30. describe('Incident Rules Form', () => {
  31. let organization, project, router, location;
  32. // create wrapper
  33. const createWrapper = props =>
  34. render(
  35. <RuleFormContainer
  36. params={{orgId: organization.slug, projectId: project.slug}}
  37. organization={organization}
  38. location={location}
  39. project={project}
  40. {...props}
  41. />,
  42. {router, organization}
  43. );
  44. beforeEach(() => {
  45. const initialData = initializeOrg({
  46. organization: {features: ['metric-alert-threshold-period', 'change-alerts']},
  47. });
  48. organization = initialData.organization;
  49. project = initialData.project;
  50. location = initialData.router.location;
  51. ProjectsStore.loadInitialData([project]);
  52. router = initialData.router;
  53. MockApiClient.addMockResponse({
  54. url: '/organizations/org-slug/tags/',
  55. body: [],
  56. });
  57. MockApiClient.addMockResponse({
  58. url: '/organizations/org-slug/users/',
  59. body: [],
  60. });
  61. MockApiClient.addMockResponse({
  62. url: '/projects/org-slug/project-slug/environments/',
  63. body: [],
  64. });
  65. MockApiClient.addMockResponse({
  66. url: '/organizations/org-slug/events-stats/',
  67. body: EventsStatsFixture({
  68. isMetricsData: true,
  69. }),
  70. });
  71. MockApiClient.addMockResponse({
  72. url: '/organizations/org-slug/events-meta/',
  73. body: {count: 5},
  74. });
  75. MockApiClient.addMockResponse({
  76. url: '/organizations/org-slug/alert-rules/available-actions/',
  77. body: [
  78. {
  79. allowedTargetTypes: ['user', 'team'],
  80. integrationName: null,
  81. type: 'email',
  82. integrationId: null,
  83. },
  84. ],
  85. });
  86. MockApiClient.addMockResponse({
  87. url: '/organizations/org-slug/metrics-estimation-stats/',
  88. body: EventsStatsFixture(),
  89. });
  90. });
  91. afterEach(() => {
  92. MockApiClient.clearMockResponses();
  93. jest.clearAllMocks();
  94. });
  95. describe('Viewing the rule', () => {
  96. const rule = MetricRuleFixture();
  97. it('is enabled without org-level alerts:write', async () => {
  98. organization.access = [];
  99. project.access = [];
  100. createWrapper({rule});
  101. expect(await screen.findByText(permissionAlertText)).toBeInTheDocument();
  102. expect(screen.queryByLabelText('Save Rule')).toBeDisabled();
  103. });
  104. it('is enabled with org-level alerts:write', async () => {
  105. organization.access = ['alerts:write'];
  106. project.access = [];
  107. createWrapper({rule});
  108. expect(await screen.findByLabelText('Save Rule')).toBeEnabled();
  109. expect(screen.queryByText(permissionAlertText)).not.toBeInTheDocument();
  110. });
  111. it('is enabled with project-level alerts:write', async () => {
  112. organization.access = [];
  113. project.access = ['alerts:write'];
  114. createWrapper({rule});
  115. expect(await screen.findByLabelText('Save Rule')).toBeEnabled();
  116. expect(screen.queryByText(permissionAlertText)).not.toBeInTheDocument();
  117. });
  118. it('renders time window', async () => {
  119. createWrapper({rule});
  120. expect(await screen.findByText('1 hour interval')).toBeInTheDocument();
  121. });
  122. it('renders time window for activated alerts', async () => {
  123. createWrapper({
  124. rule: {
  125. ...rule,
  126. monitorType: MonitorType.CONTINUOUS,
  127. },
  128. });
  129. expect(await screen.findByText('1 hour interval')).toBeInTheDocument();
  130. });
  131. });
  132. describe('Creating a new rule', () => {
  133. let createRule;
  134. beforeEach(() => {
  135. ProjectsStore.loadInitialData([
  136. project,
  137. {
  138. ...project,
  139. id: '10',
  140. slug: 'project-slug-2',
  141. },
  142. ]);
  143. createRule = MockApiClient.addMockResponse({
  144. url: '/organizations/org-slug/alert-rules/',
  145. method: 'POST',
  146. });
  147. MockApiClient.addMockResponse({
  148. url: '/projects/org-slug/project-slug-2/environments/',
  149. body: [],
  150. });
  151. });
  152. /**
  153. * Note this isn't necessarily the desired behavior, as it is just documenting the behavior
  154. */
  155. it('creates a rule', async () => {
  156. const rule = MetricRuleFixture();
  157. createWrapper({
  158. rule: {
  159. ...rule,
  160. id: undefined,
  161. eventTypes: ['default'],
  162. },
  163. });
  164. // Clear field
  165. await userEvent.clear(screen.getByPlaceholderText('Enter Alert Name'));
  166. // Enter in name so we can submit
  167. await userEvent.type(
  168. screen.getByPlaceholderText('Enter Alert Name'),
  169. 'Incident Rule'
  170. );
  171. // Set thresholdPeriod
  172. await selectEvent.select(screen.getAllByText('For 1 minute')[0], 'For 10 minutes');
  173. await userEvent.click(screen.getByLabelText('Save Rule'));
  174. expect(createRule).toHaveBeenCalledWith(
  175. expect.anything(),
  176. expect.objectContaining({
  177. data: expect.objectContaining({
  178. name: 'Incident Rule',
  179. projects: ['project-slug'],
  180. eventTypes: ['default'],
  181. thresholdPeriod: 10,
  182. }),
  183. })
  184. );
  185. expect(metric.startSpan).toHaveBeenCalledWith({name: 'saveAlertRule'});
  186. });
  187. it('can create a rule for a different project', async () => {
  188. const rule = MetricRuleFixture();
  189. createWrapper({
  190. rule: {
  191. ...rule,
  192. id: undefined,
  193. eventTypes: ['default'],
  194. },
  195. });
  196. // Clear field
  197. await userEvent.clear(screen.getByPlaceholderText('Enter Alert Name'));
  198. // Enter in name so we can submit
  199. await userEvent.type(
  200. screen.getByPlaceholderText('Enter Alert Name'),
  201. 'Incident Rule'
  202. );
  203. // Change project
  204. await userEvent.click(screen.getByText('project-slug'));
  205. await userEvent.click(screen.getByText('project-slug-2'));
  206. await userEvent.click(screen.getByLabelText('Save Rule'));
  207. expect(createRule).toHaveBeenCalledWith(
  208. expect.anything(),
  209. expect.objectContaining({
  210. data: expect.objectContaining({
  211. name: 'Incident Rule',
  212. projects: ['project-slug-2'],
  213. }),
  214. })
  215. );
  216. expect(metric.startSpan).toHaveBeenCalledWith({name: 'saveAlertRule'});
  217. });
  218. it('creates a rule with generic_metrics dataset', async () => {
  219. organization.features = [...organization.features, 'mep-rollout-flag'];
  220. const rule = MetricRuleFixture();
  221. createWrapper({
  222. rule: {
  223. ...rule,
  224. id: undefined,
  225. aggregate: 'count()',
  226. eventTypes: ['transaction'],
  227. dataset: 'transactions',
  228. },
  229. });
  230. expect(await screen.findByTestId('alert-total-events')).toHaveTextContent('Total5');
  231. await userEvent.click(screen.getByLabelText('Save Rule'));
  232. expect(createRule).toHaveBeenCalledWith(
  233. expect.anything(),
  234. expect.objectContaining({
  235. data: expect.objectContaining({
  236. name: 'My Incident Rule',
  237. projects: ['project-slug'],
  238. aggregate: 'count()',
  239. eventTypes: ['transaction'],
  240. dataset: 'generic_metrics',
  241. thresholdPeriod: 1,
  242. }),
  243. })
  244. );
  245. });
  246. // Activation condition
  247. it('creates a rule with an activation condition', async () => {
  248. organization.features = [
  249. ...organization.features,
  250. 'mep-rollout-flag',
  251. 'activated-alert-rules',
  252. ];
  253. const rule = MetricRuleFixture({
  254. monitorType: MonitorType.ACTIVATED,
  255. activationCondition: ActivationConditionType.RELEASE_CREATION,
  256. });
  257. createWrapper({
  258. rule: {
  259. ...rule,
  260. id: undefined,
  261. aggregate: 'count()',
  262. eventTypes: ['transaction'],
  263. dataset: 'transactions',
  264. },
  265. });
  266. expect(await screen.findByTestId('alert-total-events')).toHaveTextContent('Total5');
  267. await userEvent.click(screen.getByLabelText('Save Rule'));
  268. expect(createRule).toHaveBeenCalledWith(
  269. expect.anything(),
  270. expect.objectContaining({
  271. data: expect.objectContaining({
  272. name: 'My Incident Rule',
  273. projects: ['project-slug'],
  274. aggregate: 'count()',
  275. eventTypes: ['transaction'],
  276. dataset: 'generic_metrics',
  277. thresholdPeriod: 1,
  278. }),
  279. })
  280. );
  281. });
  282. it('creates a continuous rule with activated rules enabled', async () => {
  283. organization.features = [
  284. ...organization.features,
  285. 'mep-rollout-flag',
  286. 'activated-alert-rules',
  287. ];
  288. const rule = MetricRuleFixture({
  289. monitorType: MonitorType.CONTINUOUS,
  290. });
  291. createWrapper({
  292. rule: {
  293. ...rule,
  294. id: undefined,
  295. aggregate: 'count()',
  296. eventTypes: ['transaction'],
  297. dataset: 'transactions',
  298. },
  299. });
  300. expect(await screen.findByTestId('alert-total-events')).toHaveTextContent('Total5');
  301. await userEvent.click(screen.getByLabelText('Save Rule'));
  302. expect(createRule).toHaveBeenCalledWith(
  303. expect.anything(),
  304. expect.objectContaining({
  305. data: expect.objectContaining({
  306. name: 'My Incident Rule',
  307. projects: ['project-slug'],
  308. aggregate: 'count()',
  309. eventTypes: ['transaction'],
  310. dataset: 'generic_metrics',
  311. thresholdPeriod: 1,
  312. }),
  313. })
  314. );
  315. });
  316. it('creates an anomaly detection rule', async () => {
  317. organization.features = [...organization.features, 'anomaly-detection-alerts'];
  318. const rule = MetricRuleFixture({
  319. sensitivity: AlertRuleSensitivity.MEDIUM,
  320. seasonality: AlertRuleSeasonality.AUTO,
  321. });
  322. createWrapper({
  323. rule: {
  324. ...rule,
  325. id: undefined,
  326. aggregate: 'count()',
  327. eventTypes: ['error'],
  328. dataset: 'events',
  329. },
  330. });
  331. expect(
  332. await screen.findByLabelText(
  333. 'Anomaly: whenever values are outside of expected bounds'
  334. )
  335. ).toBeChecked();
  336. expect(
  337. await screen.findByRole('textbox', {name: 'Level of responsiveness'})
  338. ).toBeInTheDocument();
  339. await userEvent.click(screen.getByLabelText('Save Rule'));
  340. expect(createRule).toHaveBeenLastCalledWith(
  341. expect.anything(),
  342. expect.objectContaining({
  343. data: expect.objectContaining({
  344. aggregate: 'count()',
  345. dataset: 'events',
  346. environment: null,
  347. eventTypes: ['error'],
  348. detectionType: AlertRuleComparisonType.DYNAMIC,
  349. sensitivity: AlertRuleSensitivity.MEDIUM,
  350. seasonality: AlertRuleSeasonality.AUTO,
  351. }),
  352. })
  353. );
  354. });
  355. it('switches to custom metric and selects event.type:error', async () => {
  356. organization.features = [...organization.features, 'performance-view'];
  357. const rule = MetricRuleFixture();
  358. createWrapper({
  359. rule: {
  360. ...rule,
  361. id: undefined,
  362. eventTypes: ['default'],
  363. },
  364. });
  365. await userEvent.click(screen.getAllByText('Number of Errors').at(1)!);
  366. await userEvent.click(await screen.findByText('Custom Measurement'));
  367. await userEvent.click(screen.getAllByText('event.type:transaction').at(1)!);
  368. await userEvent.click(await screen.findByText('event.type:error'));
  369. expect(screen.getAllByText('Custom Measurement')).toHaveLength(2);
  370. await userEvent.click(screen.getByLabelText('Save Rule'));
  371. expect(createRule).toHaveBeenLastCalledWith(
  372. expect.anything(),
  373. expect.objectContaining({
  374. data: expect.objectContaining({
  375. aggregate: 'count()',
  376. alertType: 'custom_transactions',
  377. dataset: 'events',
  378. datasource: 'error',
  379. environment: null,
  380. eventTypes: ['error'],
  381. name: 'My Incident Rule',
  382. projectId: '2',
  383. projects: ['project-slug'],
  384. query: '',
  385. }),
  386. })
  387. );
  388. });
  389. });
  390. describe('Editing a rule', () => {
  391. let editRule;
  392. let editTrigger;
  393. const rule = MetricRuleFixture();
  394. beforeEach(() => {
  395. editRule = MockApiClient.addMockResponse({
  396. url: `/organizations/org-slug/alert-rules/${rule.id}/`,
  397. method: 'PUT',
  398. body: rule,
  399. });
  400. editTrigger = MockApiClient.addMockResponse({
  401. url: `/organizations/org-slug/alert-rules/${rule.id}/triggers/1/`,
  402. method: 'PUT',
  403. body: IncidentTriggerFixture({id: '1'}),
  404. });
  405. });
  406. afterEach(() => {
  407. editRule.mockReset();
  408. editTrigger.mockReset();
  409. });
  410. it('edits metric', async () => {
  411. createWrapper({
  412. ruleId: rule.id,
  413. rule,
  414. });
  415. // Clear field
  416. await userEvent.clear(screen.getByPlaceholderText('Enter Alert Name'));
  417. await userEvent.type(screen.getByPlaceholderText('Enter Alert Name'), 'new name');
  418. await userEvent.click(screen.getByLabelText('Save Rule'));
  419. expect(editRule).toHaveBeenLastCalledWith(
  420. expect.anything(),
  421. expect.objectContaining({
  422. data: expect.objectContaining({
  423. name: 'new name',
  424. }),
  425. })
  426. );
  427. });
  428. it('switches from percent change to count', async () => {
  429. createWrapper({
  430. ruleId: rule.id,
  431. rule: {
  432. ...rule,
  433. timeWindow: 60,
  434. comparisonDelta: 100,
  435. eventTypes: ['error'],
  436. resolution: 2,
  437. },
  438. });
  439. expect(screen.getByLabelText('Static: above or below {x}')).not.toBeChecked();
  440. await userEvent.click(screen.getByText('Static: above or below {x}'));
  441. await waitFor(() =>
  442. expect(screen.getByLabelText('Static: above or below {x}')).toBeChecked()
  443. );
  444. await userEvent.click(screen.getByLabelText('Save Rule'));
  445. expect(editRule).toHaveBeenLastCalledWith(
  446. expect.anything(),
  447. expect.objectContaining({
  448. data: expect.objectContaining({
  449. // Comparison delta is reset
  450. comparisonDelta: null,
  451. }),
  452. })
  453. );
  454. });
  455. it('switches to anomaly detection threshold', async () => {
  456. organization.features = [...organization.features, 'anomaly-detection-alerts'];
  457. createWrapper({
  458. rule: {
  459. ...rule,
  460. id: undefined,
  461. eventTypes: ['default'],
  462. },
  463. });
  464. const anomaly_option = await screen.findByText(
  465. 'Anomaly: whenever values are outside of expected bounds'
  466. );
  467. expect(anomaly_option).toBeInTheDocument();
  468. });
  469. it('switches event type from error to default', async () => {
  470. createWrapper({
  471. ruleId: rule.id,
  472. rule: {
  473. ...rule,
  474. eventTypes: ['error', 'default'],
  475. },
  476. });
  477. await userEvent.click(screen.getByText('event.type:error OR event.type:default'));
  478. await userEvent.click(await screen.findByText('event.type:default'));
  479. expect(screen.getAllByText('Number of Errors')).toHaveLength(2);
  480. await userEvent.click(screen.getByLabelText('Save Rule'));
  481. expect(editRule).toHaveBeenLastCalledWith(
  482. expect.anything(),
  483. expect.objectContaining({
  484. data: expect.objectContaining({
  485. eventTypes: ['default'],
  486. }),
  487. })
  488. );
  489. });
  490. it('saves a valid on demand metric rule', async () => {
  491. const validOnDemandMetricRule = MetricRuleFixture({
  492. query: 'transaction.duration:<1s',
  493. });
  494. const onSubmitSuccess = jest.fn();
  495. createWrapper({
  496. ruleId: validOnDemandMetricRule.id,
  497. rule: {
  498. ...validOnDemandMetricRule,
  499. eventTypes: ['transaction'],
  500. },
  501. onSubmitSuccess,
  502. });
  503. await userEvent.click(screen.getByLabelText('Save Rule'), {delay: null});
  504. expect(onSubmitSuccess).toHaveBeenCalled();
  505. });
  506. it('hides fields when migrating error metric alerts to filter archived issues', async () => {
  507. const errorAlert = MetricRuleFixture({
  508. dataset: Dataset.ERRORS,
  509. query: 'example-error',
  510. });
  511. location = {...location, query: {migration: '1'}};
  512. const onSubmitSuccess = jest.fn();
  513. createWrapper({
  514. ruleId: errorAlert.id,
  515. rule: {
  516. ...errorAlert,
  517. eventTypes: ['transaction'],
  518. },
  519. onSubmitSuccess,
  520. });
  521. expect(
  522. await screen.findByText(/please make sure the current thresholds are still valid/)
  523. ).toBeInTheDocument();
  524. await userEvent.click(screen.getByLabelText('Looks good to me!'), {delay: null});
  525. expect(onSubmitSuccess).toHaveBeenCalled();
  526. const formModel = onSubmitSuccess.mock.calls[0][1] as FormModel;
  527. expect(formModel.getData()).toEqual(
  528. expect.objectContaining({query: 'is:unresolved example-error'})
  529. );
  530. });
  531. });
  532. describe('Slack async lookup', () => {
  533. const uuid = 'xxxx-xxxx-xxxx';
  534. beforeEach(() => {
  535. jest.useFakeTimers();
  536. });
  537. afterEach(() => {
  538. jest.useRealTimers();
  539. });
  540. it('success status updates the rule', async () => {
  541. const alertRule = MetricRuleFixture({name: 'Slack Alert Rule'});
  542. MockApiClient.addMockResponse({
  543. url: `/organizations/org-slug/alert-rules/${alertRule.id}/`,
  544. method: 'PUT',
  545. body: {uuid},
  546. statusCode: 202,
  547. });
  548. MockApiClient.addMockResponse({
  549. url: `/projects/org-slug/project-slug/alert-rule-task/${uuid}/`,
  550. body: {
  551. status: 'success',
  552. alertRule,
  553. },
  554. });
  555. const onSubmitSuccess = jest.fn();
  556. createWrapper({
  557. ruleId: alertRule.id,
  558. rule: alertRule,
  559. onSubmitSuccess,
  560. });
  561. act(jest.runAllTimers);
  562. await userEvent.type(
  563. await screen.findByPlaceholderText('Enter Alert Name'),
  564. 'Slack Alert Rule',
  565. {delay: null}
  566. );
  567. await userEvent.click(screen.getByLabelText('Save Rule'), {delay: null});
  568. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  569. act(jest.runAllTimers);
  570. await waitFor(
  571. () => {
  572. expect(onSubmitSuccess).toHaveBeenCalledWith(
  573. expect.objectContaining({
  574. id: alertRule.id,
  575. name: alertRule.name,
  576. }),
  577. expect.anything()
  578. );
  579. },
  580. {timeout: 2000, interval: 10}
  581. );
  582. });
  583. it('pending status keeps loading true', async () => {
  584. const alertRule = MetricRuleFixture({name: 'Slack Alert Rule'});
  585. MockApiClient.addMockResponse({
  586. url: `/organizations/org-slug/alert-rules/${alertRule.id}/`,
  587. method: 'PUT',
  588. body: {uuid},
  589. statusCode: 202,
  590. });
  591. MockApiClient.addMockResponse({
  592. url: `/projects/org-slug/project-slug/alert-rule-task/${uuid}/`,
  593. body: {
  594. status: 'pending',
  595. },
  596. });
  597. const onSubmitSuccess = jest.fn();
  598. createWrapper({
  599. ruleId: alertRule.id,
  600. rule: alertRule,
  601. onSubmitSuccess,
  602. });
  603. act(jest.runAllTimers);
  604. expect(await screen.findByTestId('loading-indicator')).toBeInTheDocument();
  605. expect(onSubmitSuccess).not.toHaveBeenCalled();
  606. });
  607. it('failed status renders error message', async () => {
  608. const alertRule = MetricRuleFixture({name: 'Slack Alert Rule'});
  609. MockApiClient.addMockResponse({
  610. url: `/organizations/org-slug/alert-rules/${alertRule.id}/`,
  611. method: 'PUT',
  612. body: {uuid},
  613. statusCode: 202,
  614. });
  615. MockApiClient.addMockResponse({
  616. url: `/projects/org-slug/project-slug/alert-rule-task/${uuid}/`,
  617. body: {
  618. status: 'failed',
  619. error: 'An error occurred',
  620. },
  621. });
  622. const onSubmitSuccess = jest.fn();
  623. createWrapper({
  624. ruleId: alertRule.id,
  625. rule: alertRule,
  626. onSubmitSuccess,
  627. });
  628. act(jest.runAllTimers);
  629. await userEvent.type(
  630. await screen.findByPlaceholderText('Enter Alert Name'),
  631. 'Slack Alert Rule',
  632. {delay: null}
  633. );
  634. await userEvent.click(screen.getByLabelText('Save Rule'), {delay: null});
  635. act(jest.runAllTimers);
  636. await waitFor(
  637. () => {
  638. expect(addErrorMessage).toHaveBeenCalledWith('An error occurred');
  639. },
  640. {timeout: 2000, interval: 10}
  641. );
  642. expect(onSubmitSuccess).not.toHaveBeenCalled();
  643. });
  644. });
  645. });