ruleConditionsForm.spec.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import ProjectsStore from 'sentry/stores/projectsStore';
  4. import RuleConditionsForm from 'sentry/views/alerts/rules/metric/ruleConditionsForm';
  5. import {AlertRuleComparisonType, Dataset} from 'sentry/views/alerts/rules/metric/types';
  6. import type {AlertType} from 'sentry/views/alerts/wizard/options';
  7. describe('RuleConditionsForm', () => {
  8. const {organization, projects, router} = initializeOrg({
  9. organization: {
  10. features: ['search-query-builder-alerts', 'alerts-eap'],
  11. },
  12. });
  13. ProjectsStore.loadInitialData(projects);
  14. const mockSearch = jest.fn();
  15. const props = {
  16. aggregate: 'foo',
  17. alertType: 'errors' as AlertType,
  18. comparisonType: AlertRuleComparisonType.COUNT,
  19. dataset: Dataset.ERRORS,
  20. disabled: false,
  21. isEditing: true,
  22. onComparisonDeltaChange: _ => {},
  23. onFilterSearch: mockSearch,
  24. onMonitorTypeSelect: _ => {},
  25. onTimeWindowChange: _ => {},
  26. project: projects[0],
  27. thresholdChart: <div>chart</div>,
  28. timeWindow: 30,
  29. };
  30. beforeEach(() => {
  31. MockApiClient.addMockResponse({
  32. url: '/organizations/org-slug/tags/',
  33. body: [],
  34. });
  35. MockApiClient.addMockResponse({
  36. url: '/organizations/org-slug/recent-searches/',
  37. body: [],
  38. });
  39. MockApiClient.addMockResponse({
  40. url: '/organizations/org-slug/recent-searches/',
  41. method: 'POST',
  42. body: [],
  43. });
  44. MockApiClient.addMockResponse({
  45. url: '/projects/org-slug/project-slug/environments/',
  46. body: [],
  47. });
  48. });
  49. afterEach(() => {
  50. MockApiClient.clearMockResponses();
  51. jest.clearAllMocks();
  52. });
  53. it('searches with new searchbar (search-query-builder-alerts)', async () => {
  54. render(
  55. <RuleConditionsForm {...props} organization={organization} router={router} />,
  56. {
  57. router,
  58. organization: {...organization, features: ['search-query-builder-alerts']},
  59. }
  60. );
  61. const input = await screen.findByPlaceholderText(
  62. 'Filter events by level, message, and other properties\u2026'
  63. );
  64. expect(input).toBeInTheDocument();
  65. await userEvent.clear(input);
  66. await userEvent.type(input, 'a{enter}');
  67. expect(mockSearch).toHaveBeenCalledTimes(1);
  68. expect(mockSearch).toHaveBeenCalledWith('a', true);
  69. });
  70. it('renders low confidence warning', async () => {
  71. render(
  72. <RuleConditionsForm
  73. {...props}
  74. organization={organization}
  75. router={router}
  76. isLowConfidenceChartData
  77. />,
  78. {
  79. router,
  80. organization: {
  81. ...organization,
  82. features: ['search-query-builder-alerts', 'alerts-eap'],
  83. },
  84. }
  85. );
  86. await screen.findByPlaceholderText(
  87. 'Filter events by level, message, and other properties\u2026'
  88. );
  89. expect(
  90. screen.getByText(
  91. 'Your low sample count may impact the accuracy of this alert. Edit your query or increase your sampling rate.'
  92. )
  93. ).toBeInTheDocument();
  94. });
  95. });