create.spec.tsx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. import selectEvent from 'react-select-event';
  2. import {EnvironmentsFixture} from 'sentry-fixture/environments';
  3. import {GroupsFixture} from 'sentry-fixture/groups';
  4. import {LocationFixture} from 'sentry-fixture/locationFixture';
  5. import {OrganizationFixture} from 'sentry-fixture/organization';
  6. import {ProjectAlertRuleFixture} from 'sentry-fixture/projectAlertRule';
  7. import {ProjectAlertRuleConfigurationFixture} from 'sentry-fixture/projectAlertRuleConfiguration';
  8. import {RouteComponentPropsFixture} from 'sentry-fixture/routeComponentPropsFixture';
  9. import {initializeOrg} from 'sentry-test/initializeOrg';
  10. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  11. import ProjectsStore from 'sentry/stores/projectsStore';
  12. import TeamStore from 'sentry/stores/teamStore';
  13. import {metric, trackAnalytics} from 'sentry/utils/analytics';
  14. import AlertsContainer from 'sentry/views/alerts';
  15. import AlertBuilderProjectProvider from 'sentry/views/alerts/builder/projectProvider';
  16. import ProjectAlertsCreate from 'sentry/views/alerts/create';
  17. jest.unmock('sentry/utils/recreateRoute');
  18. // updateOnboardingTask triggers an out of band state update
  19. jest.mock('sentry/actionCreators/onboardingTasks');
  20. jest.mock('sentry/actionCreators/members', () => ({
  21. fetchOrgMembers: jest.fn(() => Promise.resolve([])),
  22. indexMembersByProject: jest.fn(() => {
  23. return {};
  24. }),
  25. }));
  26. jest.mock('react-router');
  27. jest.mock('sentry/utils/analytics', () => ({
  28. metric: {
  29. startTransaction: jest.fn(() => ({
  30. setTag: jest.fn(),
  31. setData: jest.fn(),
  32. })),
  33. endTransaction: jest.fn(),
  34. mark: jest.fn(),
  35. measure: jest.fn(),
  36. },
  37. trackAnalytics: jest.fn(),
  38. }));
  39. describe('ProjectAlertsCreate', function () {
  40. beforeEach(function () {
  41. TeamStore.init();
  42. TeamStore.loadInitialData([], false, null);
  43. MockApiClient.addMockResponse({
  44. url: '/projects/org-slug/project-slug/rules/configuration/',
  45. body: ProjectAlertRuleConfigurationFixture(),
  46. });
  47. MockApiClient.addMockResponse({
  48. url: '/projects/org-slug/project-slug/rules/1/',
  49. body: ProjectAlertRuleFixture(),
  50. });
  51. MockApiClient.addMockResponse({
  52. url: '/projects/org-slug/project-slug/environments/',
  53. body: EnvironmentsFixture(),
  54. });
  55. MockApiClient.addMockResponse({
  56. url: `/projects/org-slug/project-slug/?expand=hasAlertIntegration`,
  57. body: {},
  58. });
  59. MockApiClient.addMockResponse({
  60. url: `/projects/org-slug/project-slug/ownership/`,
  61. method: 'GET',
  62. body: {
  63. fallthrough: false,
  64. autoAssignment: false,
  65. },
  66. });
  67. MockApiClient.addMockResponse({
  68. url: '/projects/org-slug/project-slug/rules/preview/',
  69. method: 'POST',
  70. body: [],
  71. });
  72. });
  73. afterEach(function () {
  74. MockApiClient.clearMockResponses();
  75. jest.clearAllMocks();
  76. });
  77. const createWrapper = (props = {}, location = {}) => {
  78. const {organization, project, router, routerContext} = initializeOrg(props);
  79. ProjectsStore.loadInitialData([project]);
  80. const params = {orgId: organization.slug, projectId: project.slug};
  81. const wrapper = render(
  82. <AlertsContainer>
  83. <AlertBuilderProjectProvider
  84. {...RouteComponentPropsFixture()}
  85. params={params}
  86. organization={organization}
  87. hasMetricAlerts={false}
  88. >
  89. <ProjectAlertsCreate
  90. {...RouteComponentPropsFixture()}
  91. hasMetricAlerts={false}
  92. members={[]}
  93. params={params}
  94. organization={organization}
  95. project={project}
  96. location={LocationFixture({
  97. pathname: `/organizations/org-slug/alerts/rules/${project.slug}/new/`,
  98. query: {createFromWizard: 'true'},
  99. ...location,
  100. })}
  101. router={router}
  102. />
  103. </AlertBuilderProjectProvider>
  104. </AlertsContainer>,
  105. {organization, context: routerContext}
  106. );
  107. return {
  108. wrapper,
  109. organization,
  110. project,
  111. router,
  112. };
  113. };
  114. it('adds default parameters if wizard was skipped', async function () {
  115. const location = {query: {}};
  116. const wrapper = createWrapper(undefined, location);
  117. await waitFor(() => {
  118. expect(wrapper.router.replace).toHaveBeenCalledWith(
  119. expect.objectContaining({
  120. pathname: '/organizations/org-slug/alerts/new/metric',
  121. query: {
  122. aggregate: 'count()',
  123. dataset: 'events',
  124. eventTypes: 'error',
  125. project: 'project-slug',
  126. },
  127. })
  128. );
  129. });
  130. });
  131. describe('Issue Alert', function () {
  132. it('loads default values', async function () {
  133. createWrapper();
  134. expect(await screen.findByText('All Environments')).toBeInTheDocument();
  135. expect(await screen.findByText('any')).toBeInTheDocument();
  136. expect(await screen.findByText('all')).toBeInTheDocument();
  137. expect(await screen.findByText('24 hours')).toBeInTheDocument();
  138. });
  139. it('can remove filters', async function () {
  140. createWrapper();
  141. const mock = MockApiClient.addMockResponse({
  142. url: '/projects/org-slug/project-slug/rules/',
  143. method: 'POST',
  144. body: ProjectAlertRuleFixture(),
  145. });
  146. // Change name of alert rule
  147. await userEvent.type(screen.getByPlaceholderText('Enter Alert Name'), 'myname');
  148. // Add a filter and remove it
  149. await selectEvent.select(screen.getByText('Add optional filter...'), [
  150. 'The issue is older or newer than...',
  151. ]);
  152. await userEvent.click(screen.getAllByLabelText('Delete Node')[1]);
  153. await userEvent.click(screen.getByText('Save Rule'));
  154. await waitFor(() => {
  155. expect(mock).toHaveBeenCalledWith(
  156. expect.any(String),
  157. expect.objectContaining({
  158. data: {
  159. actionMatch: 'any',
  160. actions: [],
  161. conditions: [
  162. expect.objectContaining({
  163. id: 'sentry.rules.conditions.first_seen_event.FirstSeenEventCondition',
  164. }),
  165. ],
  166. filterMatch: 'all',
  167. filters: [],
  168. frequency: 60 * 24,
  169. name: 'myname',
  170. owner: null,
  171. },
  172. })
  173. );
  174. });
  175. });
  176. it('can remove triggers', async function () {
  177. const {organization} = createWrapper();
  178. const mock = MockApiClient.addMockResponse({
  179. url: '/projects/org-slug/project-slug/rules/',
  180. method: 'POST',
  181. body: ProjectAlertRuleFixture(),
  182. });
  183. // delete node
  184. await userEvent.click(screen.getByLabelText('Delete Node'));
  185. // Change name of alert rule
  186. await userEvent.type(screen.getByPlaceholderText('Enter Alert Name'), 'myname');
  187. // Add a trigger and remove it
  188. await selectEvent.select(screen.getByText('Add optional trigger...'), [
  189. 'A new issue is created',
  190. ]);
  191. await userEvent.click(screen.getByLabelText('Delete Node'));
  192. await waitFor(() => {
  193. expect(trackAnalytics).toHaveBeenCalledWith('edit_alert_rule.add_row', {
  194. name: 'sentry.rules.conditions.first_seen_event.FirstSeenEventCondition',
  195. organization,
  196. project_id: '2',
  197. type: 'conditions',
  198. });
  199. });
  200. await userEvent.click(screen.getByText('Save Rule'));
  201. await waitFor(() => {
  202. expect(mock).toHaveBeenCalledWith(
  203. expect.any(String),
  204. expect.objectContaining({
  205. data: {
  206. actionMatch: 'any',
  207. actions: [],
  208. conditions: [],
  209. filterMatch: 'all',
  210. filters: [],
  211. frequency: 60 * 24,
  212. name: 'myname',
  213. owner: null,
  214. },
  215. })
  216. );
  217. });
  218. });
  219. it('can remove actions', async function () {
  220. createWrapper();
  221. const mock = MockApiClient.addMockResponse({
  222. url: '/projects/org-slug/project-slug/rules/',
  223. method: 'POST',
  224. body: ProjectAlertRuleFixture(),
  225. });
  226. // Change name of alert rule
  227. await userEvent.type(screen.getByPlaceholderText('Enter Alert Name'), 'myname');
  228. // Add an action and remove it
  229. await selectEvent.select(screen.getByText('Add action...'), [
  230. 'Send a notification to all legacy integrations',
  231. ]);
  232. await userEvent.click(screen.getAllByLabelText('Delete Node')[1]);
  233. await userEvent.click(screen.getByText('Save Rule'));
  234. await waitFor(() => {
  235. expect(mock).toHaveBeenCalledWith(
  236. expect.any(String),
  237. expect.objectContaining({
  238. data: {
  239. actionMatch: 'any',
  240. actions: [],
  241. conditions: [
  242. expect.objectContaining({
  243. id: 'sentry.rules.conditions.first_seen_event.FirstSeenEventCondition',
  244. }),
  245. ],
  246. filterMatch: 'all',
  247. filters: [],
  248. frequency: 60 * 24,
  249. name: 'myname',
  250. owner: null,
  251. },
  252. })
  253. );
  254. });
  255. });
  256. describe('updates and saves', function () {
  257. let mock;
  258. beforeEach(function () {
  259. mock = MockApiClient.addMockResponse({
  260. url: '/projects/org-slug/project-slug/rules/',
  261. method: 'POST',
  262. body: ProjectAlertRuleFixture(),
  263. });
  264. });
  265. afterEach(function () {
  266. jest.clearAllMocks();
  267. });
  268. it('environment, async action and filter match', async function () {
  269. const wrapper = createWrapper();
  270. // Change target environment
  271. await selectEvent.select(screen.getByText('All Environments'), ['production']);
  272. // Change actionMatch and filterMatch dropdown
  273. const anyDropdown = screen.getByText('any');
  274. expect(anyDropdown).toBeInTheDocument();
  275. const allDropdown = screen.getByText('all');
  276. expect(allDropdown).toBeInTheDocument();
  277. await selectEvent.select(anyDropdown, ['all']);
  278. await selectEvent.select(allDropdown, ['any']);
  279. // Change name of alert rule
  280. await userEvent.type(screen.getByPlaceholderText('Enter Alert Name'), 'myname');
  281. await userEvent.click(screen.getByText('Save Rule'));
  282. expect(mock).toHaveBeenCalledWith(
  283. expect.any(String),
  284. expect.objectContaining({
  285. data: {
  286. actionMatch: 'all',
  287. filterMatch: 'any',
  288. conditions: [
  289. expect.objectContaining({
  290. id: 'sentry.rules.conditions.first_seen_event.FirstSeenEventCondition',
  291. }),
  292. ],
  293. actions: [],
  294. filters: [],
  295. environment: 'production',
  296. frequency: 60 * 24,
  297. name: 'myname',
  298. owner: null,
  299. },
  300. })
  301. );
  302. expect(metric.startTransaction).toHaveBeenCalledWith({name: 'saveAlertRule'});
  303. await waitFor(() => {
  304. expect(wrapper.router.push).toHaveBeenCalledWith({
  305. pathname: '/organizations/org-slug/alerts/rules/project-slug/1/details/',
  306. });
  307. });
  308. });
  309. it('new condition', async function () {
  310. const wrapper = createWrapper();
  311. // Change name of alert rule
  312. await userEvent.click(screen.getByPlaceholderText('Enter Alert Name'));
  313. await userEvent.paste('myname');
  314. // Add another condition
  315. await selectEvent.select(screen.getByText('Add optional filter...'), [
  316. "The event's tags match {key} {match} {value}",
  317. ]);
  318. // Edit new Condition
  319. await userEvent.click(screen.getByPlaceholderText('key'));
  320. await userEvent.paste('conditionKey');
  321. await userEvent.click(screen.getByPlaceholderText('value'));
  322. await userEvent.paste('conditionValue');
  323. await selectEvent.select(screen.getByText('contains'), ['does not equal']);
  324. await userEvent.click(screen.getByText('Save Rule'));
  325. expect(mock).toHaveBeenCalledWith(
  326. expect.any(String),
  327. expect.objectContaining({
  328. data: {
  329. actionMatch: 'any',
  330. actions: [],
  331. conditions: [
  332. expect.objectContaining({
  333. id: 'sentry.rules.conditions.first_seen_event.FirstSeenEventCondition',
  334. }),
  335. ],
  336. filterMatch: 'all',
  337. filters: [
  338. {
  339. id: 'sentry.rules.filters.tagged_event.TaggedEventFilter',
  340. key: 'conditionKey',
  341. match: 'ne',
  342. value: 'conditionValue',
  343. },
  344. ],
  345. frequency: 60 * 24,
  346. name: 'myname',
  347. owner: null,
  348. },
  349. })
  350. );
  351. expect(metric.startTransaction).toHaveBeenCalledWith({name: 'saveAlertRule'});
  352. await waitFor(() => {
  353. expect(wrapper.router.push).toHaveBeenCalledWith({
  354. pathname: '/organizations/org-slug/alerts/rules/project-slug/1/details/',
  355. });
  356. });
  357. });
  358. it('new filter', async function () {
  359. const wrapper = createWrapper();
  360. // Change name of alert rule
  361. await userEvent.click(screen.getByPlaceholderText('Enter Alert Name'));
  362. await userEvent.paste('myname');
  363. // delete one condition
  364. await userEvent.click(screen.getAllByLabelText('Delete Node')[0]);
  365. // Add a new filter
  366. await selectEvent.select(screen.getByText('Add optional filter...'), [
  367. 'The issue is older or newer than...',
  368. ]);
  369. await userEvent.click(screen.getByPlaceholderText('10'));
  370. await userEvent.paste('12');
  371. await userEvent.click(screen.getByText('Save Rule'));
  372. expect(mock).toHaveBeenCalledWith(
  373. expect.any(String),
  374. expect.objectContaining({
  375. data: {
  376. actionMatch: 'any',
  377. filterMatch: 'all',
  378. filters: [
  379. {
  380. id: 'sentry.rules.filters.age_comparison.AgeComparisonFilter',
  381. comparison_type: 'older',
  382. time: 'minute',
  383. value: '12',
  384. },
  385. ],
  386. actions: [],
  387. conditions: [],
  388. frequency: 60 * 24,
  389. name: 'myname',
  390. owner: null,
  391. },
  392. })
  393. );
  394. expect(metric.startTransaction).toHaveBeenCalledWith({name: 'saveAlertRule'});
  395. await waitFor(() => {
  396. expect(wrapper.router.push).toHaveBeenCalledWith({
  397. pathname: '/organizations/org-slug/alerts/rules/project-slug/1/details/',
  398. });
  399. });
  400. });
  401. it('new action', async function () {
  402. const wrapper = createWrapper();
  403. // Change name of alert rule
  404. await userEvent.type(screen.getByPlaceholderText('Enter Alert Name'), 'myname');
  405. // Add a new action
  406. await selectEvent.select(screen.getByText('Add action...'), [
  407. 'Suggested Assignees, Team, or Member',
  408. ]);
  409. // Update action interval
  410. await selectEvent.select(screen.getByText('24 hours'), ['60 minutes']);
  411. await userEvent.click(screen.getByText('Save Rule'));
  412. expect(mock).toHaveBeenCalledWith(
  413. expect.any(String),
  414. expect.objectContaining({
  415. data: {
  416. actionMatch: 'any',
  417. actions: [
  418. {id: 'sentry.mail.actions.NotifyEmailAction', targetType: 'IssueOwners'},
  419. ],
  420. conditions: [
  421. expect.objectContaining({
  422. id: 'sentry.rules.conditions.first_seen_event.FirstSeenEventCondition',
  423. }),
  424. ],
  425. filterMatch: 'all',
  426. filters: [],
  427. frequency: '60',
  428. name: 'myname',
  429. owner: null,
  430. },
  431. })
  432. );
  433. expect(metric.startTransaction).toHaveBeenCalledWith({name: 'saveAlertRule'});
  434. await waitFor(() => {
  435. expect(wrapper.router.push).toHaveBeenCalledWith({
  436. pathname: '/organizations/org-slug/alerts/rules/project-slug/1/details/',
  437. });
  438. });
  439. });
  440. });
  441. });
  442. describe('test preview chart', () => {
  443. it('valid preview table', async () => {
  444. const groups = GroupsFixture();
  445. const date = new Date();
  446. for (let i = 0; i < groups.length; i++) {
  447. groups[i].lastTriggered = String(date);
  448. }
  449. const mock = MockApiClient.addMockResponse({
  450. url: '/projects/org-slug/project-slug/rules/preview/',
  451. method: 'POST',
  452. body: groups,
  453. headers: {
  454. 'X-Hits': String(groups.length),
  455. Endpoint: 'endpoint',
  456. },
  457. });
  458. createWrapper();
  459. await waitFor(() => {
  460. expect(mock).toHaveBeenCalledWith(
  461. expect.any(String),
  462. expect.objectContaining({
  463. data: {
  464. actionMatch: 'any',
  465. conditions: [
  466. expect.objectContaining({
  467. id: 'sentry.rules.conditions.first_seen_event.FirstSeenEventCondition',
  468. }),
  469. ],
  470. filterMatch: 'all',
  471. filters: [],
  472. frequency: 60 * 24,
  473. endpoint: null,
  474. },
  475. })
  476. );
  477. });
  478. expect(
  479. screen.getByText('4 issues would have triggered this rule in the past 14 days', {
  480. exact: false,
  481. })
  482. ).toBeInTheDocument();
  483. for (const group of groups) {
  484. expect(screen.getByText(group.shortId)).toBeInTheDocument();
  485. }
  486. expect(screen.getAllByText('3mo ago')[0]).toBeInTheDocument();
  487. });
  488. it('invalid preview alert', async () => {
  489. const mock = MockApiClient.addMockResponse({
  490. url: '/projects/org-slug/project-slug/rules/preview/',
  491. method: 'POST',
  492. statusCode: 400,
  493. });
  494. createWrapper();
  495. // delete existion condition
  496. await userEvent.click(screen.getAllByLabelText('Delete Node')[0]);
  497. await waitFor(() => {
  498. expect(mock).toHaveBeenCalled();
  499. });
  500. expect(
  501. screen.getByText('Select a condition to generate a preview')
  502. ).toBeInTheDocument();
  503. await selectEvent.select(screen.getByText('Add optional trigger...'), [
  504. 'A new issue is created',
  505. ]);
  506. expect(
  507. await screen.findByText('Preview is not supported for these conditions')
  508. ).toBeInTheDocument();
  509. });
  510. it('empty preview table', async () => {
  511. const mock = MockApiClient.addMockResponse({
  512. url: '/projects/org-slug/project-slug/rules/preview/',
  513. method: 'POST',
  514. body: [],
  515. headers: {
  516. 'X-Hits': '0',
  517. Endpoint: 'endpoint',
  518. },
  519. });
  520. createWrapper();
  521. await waitFor(() => {
  522. expect(mock).toHaveBeenCalled();
  523. });
  524. expect(
  525. screen.getByText("We couldn't find any issues that would've triggered your rule")
  526. ).toBeInTheDocument();
  527. });
  528. });
  529. describe('test incompatible conditions', () => {
  530. const errorText =
  531. 'The conditions highlighted in red are in conflict. They may prevent the alert from ever being triggered.';
  532. it('shows error for incompatible conditions', async () => {
  533. createWrapper();
  534. const anyDropdown = screen.getByText('any');
  535. expect(anyDropdown).toBeInTheDocument();
  536. await selectEvent.select(anyDropdown, ['all']);
  537. await selectEvent.select(screen.getByText('Add optional trigger...'), [
  538. 'The issue changes state from resolved to unresolved',
  539. ]);
  540. expect(screen.getByText(errorText)).toBeInTheDocument();
  541. expect(screen.getByRole('button', {name: 'Save Rule'})).toHaveAttribute(
  542. 'aria-disabled',
  543. 'true'
  544. );
  545. await userEvent.click(screen.getAllByLabelText('Delete Node')[0]);
  546. expect(screen.queryByText(errorText)).not.toBeInTheDocument();
  547. });
  548. it('test any filterMatch', async () => {
  549. createWrapper();
  550. const allDropdown = screen.getByText('all');
  551. await selectEvent.select(allDropdown, ['any']);
  552. await selectEvent.select(screen.getByText('Add optional filter...'), [
  553. 'The issue is older or newer than...',
  554. ]);
  555. await userEvent.type(screen.getByPlaceholderText('10'), '10');
  556. await userEvent.click(document.body);
  557. await selectEvent.select(screen.getByText('Add optional filter...'), [
  558. 'The issue has happened at least {x} times (Note: this is approximate)',
  559. ]);
  560. expect(screen.getByText(errorText)).toBeInTheDocument();
  561. await userEvent.click(screen.getAllByLabelText('Delete Node')[1]);
  562. await userEvent.clear(screen.getByDisplayValue('10'));
  563. await userEvent.click(document.body);
  564. expect(screen.queryByText(errorText)).not.toBeInTheDocument();
  565. });
  566. });
  567. it('shows archived to escalating instead of ignored to unresolved', async () => {
  568. createWrapper({
  569. organization: OrganizationFixture(),
  570. });
  571. await selectEvent.select(screen.getByText('Add optional trigger...'), [
  572. 'The issue changes state from archived to escalating',
  573. ]);
  574. expect(
  575. screen.getByText('The issue changes state from archived to escalating')
  576. ).toBeInTheDocument();
  577. });
  578. it('displays noisy alert checkbox for no conditions + filters', async function () {
  579. const mock = MockApiClient.addMockResponse({
  580. url: '/projects/org-slug/project-slug/rules/',
  581. method: 'POST',
  582. body: ProjectAlertRuleFixture(),
  583. });
  584. createWrapper({organization: {features: ['noisy-alert-warning']}});
  585. await userEvent.click((await screen.findAllByLabelText('Delete Node'))[0]);
  586. await selectEvent.select(screen.getByText('Add action...'), [
  587. 'Suggested Assignees, Team, or Member',
  588. ]);
  589. expect(
  590. screen.getByText(/Alerts without conditions can fire too frequently/)
  591. ).toBeInTheDocument();
  592. expect(trackAnalytics).toHaveBeenCalledWith(
  593. 'alert_builder.noisy_warning_viewed',
  594. expect.anything()
  595. );
  596. await userEvent.click(screen.getByText('Save Rule'));
  597. expect(mock).not.toHaveBeenCalled();
  598. await userEvent.click(
  599. screen.getByRole('checkbox', {name: 'Yes, I don’t mind if this alert gets noisy'})
  600. );
  601. await userEvent.click(screen.getByText('Save Rule'));
  602. expect(mock).toHaveBeenCalled();
  603. expect(trackAnalytics).toHaveBeenCalledWith(
  604. 'alert_builder.noisy_warning_agreed',
  605. expect.anything()
  606. );
  607. });
  608. it('does not display noisy alert banner for legacy integrations', async function () {
  609. createWrapper({organization: {features: ['noisy-alert-warning']}});
  610. await userEvent.click((await screen.findAllByLabelText('Delete Node'))[0]);
  611. await selectEvent.select(screen.getByText('Add action...'), [
  612. 'Send a notification to all legacy integrations',
  613. ]);
  614. expect(
  615. screen.queryByText(/Alerts without conditions can fire too frequently/)
  616. ).not.toBeInTheDocument();
  617. await selectEvent.select(screen.getByText('Add action...'), [
  618. 'Suggested Assignees, Team, or Member',
  619. ]);
  620. expect(
  621. screen.getByText(/Alerts without conditions can fire too frequently/)
  622. ).toBeInTheDocument();
  623. });
  624. it('displays duplicate error banner with link', async function () {
  625. MockApiClient.addMockResponse({
  626. url: '/projects/org-slug/project-slug/rules/',
  627. method: 'POST',
  628. statusCode: 400,
  629. body: {
  630. name: [
  631. "This rule is an exact duplicate of 'test alert' in this project and may not be created.",
  632. ],
  633. ruleId: [1337],
  634. },
  635. });
  636. createWrapper();
  637. await userEvent.click(screen.getByText('Save Rule'));
  638. const bannerLink = await screen.findByRole('link', {
  639. name: /rule fully duplicates "test alert"/,
  640. });
  641. expect(bannerLink).toBeInTheDocument();
  642. expect(bannerLink).toHaveAttribute(
  643. 'href',
  644. '/organizations/org-slug/alerts/rules/project-slug/1337/details/'
  645. );
  646. });
  647. });