issueAlertOptions.spec.jsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import IssueAlertOptions from 'sentry/views/projectInstall/issueAlertOptions';
  4. describe('IssueAlertOptions', function () {
  5. const {organization, routerContext} = initializeOrg();
  6. const URL = `/projects/${organization.slug}/rule-conditions/`;
  7. let props;
  8. const baseProps = {
  9. onChange: _ => {},
  10. };
  11. beforeEach(() => {
  12. MockApiClient.clearMockResponses();
  13. MockApiClient.addMockResponse({
  14. url: `/projects/${organization.slug}/rule-conditions/`,
  15. body: TestStubs.MOCK_RESP_VERBOSE,
  16. });
  17. props = {...baseProps};
  18. });
  19. const selectControlVerifier = async (wrapper, dataTestId, optionsText) => {
  20. wrapper
  21. .find(`[data-test-id="${dataTestId}"] input[id*="react-select"]`)
  22. .last()
  23. .simulate('focus');
  24. await tick();
  25. wrapper.update();
  26. expect(
  27. wrapper.find(`InlineSelectControl[data-test-id="${dataTestId}"] Option`)
  28. ).toHaveLength(optionsText.length);
  29. optionsText.forEach((metricText, idx) =>
  30. expect(
  31. wrapper
  32. .find(`InlineSelectControl[data-test-id="${dataTestId}"] Option`)
  33. .at(idx)
  34. .text()
  35. ).toBe(metricText)
  36. );
  37. };
  38. it('should render only the `Default Rule` and `Create Later` option on empty response:[]', () => {
  39. MockApiClient.addMockResponse({
  40. url: URL,
  41. body: [],
  42. });
  43. const wrapper = mountWithTheme(<IssueAlertOptions {...props} />, routerContext);
  44. expect(wrapper.find('RadioLineItem')).toHaveLength(2);
  45. });
  46. it('should render only the `Default Rule` and `Create Later` option on empty response:{}', () => {
  47. MockApiClient.addMockResponse({
  48. url: URL,
  49. body: {},
  50. });
  51. const wrapper = mountWithTheme(<IssueAlertOptions {...props} />, routerContext);
  52. expect(wrapper.find('RadioLineItem')).toHaveLength(2);
  53. });
  54. it('should render only the `Default Rule` and `Create Later` option on responses with different allowable intervals', () => {
  55. MockApiClient.addMockResponse({
  56. url: URL,
  57. body: TestStubs.MOCK_RESP_INCONSISTENT_INTERVALS,
  58. });
  59. const wrapper = mountWithTheme(<IssueAlertOptions {...props} />, routerContext);
  60. expect(wrapper.find('RadioLineItem')).toHaveLength(2);
  61. });
  62. it('should render all(three) options on responses with different placeholder values', () => {
  63. MockApiClient.addMockResponse({
  64. url: URL,
  65. body: TestStubs.MOCK_RESP_INCONSISTENT_PLACEHOLDERS,
  66. });
  67. const wrapper = mountWithTheme(<IssueAlertOptions {...props} />, routerContext);
  68. expect(wrapper.find('RadioLineItem')).toHaveLength(3);
  69. });
  70. it('should ignore conditions that are not `sentry.rules.conditions.event_frequency.EventFrequencyCondition` and `sentry.rules.conditions.event_frequency.EventUniqueUserFrequencyCondition`', () => {
  71. MockApiClient.addMockResponse({
  72. url: URL,
  73. body: TestStubs.MOCK_RESP_ONLY_IGNORED_CONDITIONS_INVALID,
  74. });
  75. const wrapper = mountWithTheme(<IssueAlertOptions {...props} />, routerContext);
  76. expect(wrapper.find('RadioLineItem')).toHaveLength(3);
  77. selectControlVerifier(wrapper, 'metric-select-control', ['users affected by']);
  78. });
  79. it('should render all(three) options on a valid response', () => {
  80. MockApiClient.addMockResponse({
  81. url: URL,
  82. body: TestStubs.MOCK_RESP_VERBOSE,
  83. });
  84. const wrapper = mountWithTheme(<IssueAlertOptions {...props} />, routerContext);
  85. expect(wrapper.find('RadioLineItem')).toHaveLength(3);
  86. });
  87. it('should pre-populate fields from server response', () => {
  88. MockApiClient.addMockResponse({
  89. url: URL,
  90. body: TestStubs.MOCK_RESP_VERBOSE,
  91. });
  92. const wrapper = mountWithTheme(<IssueAlertOptions {...props} />, routerContext);
  93. [
  94. ['metric-select-control', ['occurrences of', 'users affected by']],
  95. [
  96. 'interval-select-control',
  97. ['one minute', 'one hour', 'one day', 'one week', '30 days'],
  98. ],
  99. ].forEach(([dataTestId, options]) =>
  100. selectControlVerifier(wrapper, dataTestId, options)
  101. );
  102. });
  103. it('should not pre-fill threshold value after a valid server response', () => {
  104. MockApiClient.addMockResponse({
  105. url: URL,
  106. body: TestStubs.MOCK_RESP_VERBOSE,
  107. });
  108. const wrapper = mountWithTheme(<IssueAlertOptions {...props} />, routerContext);
  109. expect(wrapper.find('input[data-test-id="range-input"]').props().value).toBe('');
  110. });
  111. });