duplicate.spec.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import {Fragment} from 'react';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import GlobalModal from 'sentry/components/globalModal';
  5. import MetricRulesDuplicate from 'sentry/views/alerts/rules/metric/duplicate';
  6. import {AlertRuleTriggerType} from 'sentry/views/alerts/rules/metric/types';
  7. describe('Incident Rules Duplicate', function () {
  8. beforeAll(function () {
  9. MockApiClient.addMockResponse({
  10. url: '/organizations/org-slug/users/',
  11. body: [],
  12. });
  13. MockApiClient.addMockResponse({
  14. url: '/organizations/org-slug/tags/',
  15. body: [],
  16. });
  17. MockApiClient.addMockResponse({
  18. url: '/projects/org-slug/project-slug/environments/',
  19. body: [],
  20. });
  21. MockApiClient.addMockResponse({
  22. url: '/organizations/org-slug/events-stats/',
  23. body: null,
  24. });
  25. MockApiClient.addMockResponse({
  26. url: '/organizations/org-slug/events-meta/',
  27. body: {count: 5},
  28. });
  29. MockApiClient.addMockResponse({
  30. url: '/organizations/org-slug/alert-rules/available-actions/',
  31. body: [
  32. {
  33. allowedTargetTypes: ['user', 'team'],
  34. integrationName: null,
  35. type: 'email',
  36. integrationId: null,
  37. },
  38. ],
  39. });
  40. MockApiClient.addMockResponse({
  41. url: '/organizations/org-slug/members/',
  42. body: [TestStubs.Member()],
  43. });
  44. });
  45. it('renders new alert form with values copied over', function () {
  46. const rule = TestStubs.MetricRule();
  47. rule.triggers.push({
  48. label: AlertRuleTriggerType.WARNING,
  49. alertThreshold: 60,
  50. actions: [],
  51. });
  52. rule.resolveThreshold = 50;
  53. const {organization, project, router} = initializeOrg({
  54. organization: {
  55. access: ['alerts:write'],
  56. features: ['alert-wizard-v3', 'duplicate-alert-rule'],
  57. },
  58. router: {
  59. // we need this to be set to make sure org in context is same as
  60. // current org in URL
  61. params: {orgId: 'org-slug'},
  62. location: {
  63. query: {
  64. createFromDuplicate: true,
  65. duplicateRuleId: `${rule.id}`,
  66. },
  67. },
  68. },
  69. project: rule.projects[0],
  70. projects: rule.projects,
  71. });
  72. const req = MockApiClient.addMockResponse({
  73. url: `/organizations/${organization.slug}/alert-rules/${rule.id}/`,
  74. body: rule,
  75. });
  76. render(
  77. <Fragment>
  78. <GlobalModal />
  79. <MetricRulesDuplicate
  80. params={{orgId: organization.slug}}
  81. route={{}}
  82. routeParams={router.params}
  83. router={router}
  84. routes={router.routes}
  85. location={router.location}
  86. organization={organization}
  87. project={project}
  88. userTeamIds={[]}
  89. />
  90. </Fragment>
  91. );
  92. // Duplicated alert has been called
  93. expect(req).toHaveBeenCalled();
  94. // Has correct values copied from the duplicated alert
  95. expect(screen.getByTestId('critical-threshold')).toHaveValue('70');
  96. expect(screen.getByTestId('warning-threshold')).toHaveValue('60');
  97. expect(screen.getByTestId('resolve-threshold')).toHaveValue('50');
  98. // Has the updated alert rule name
  99. expect(screen.getByTestId('alert-name')).toHaveValue(`${rule.name} copy`);
  100. });
  101. });