ruleConditionsForm.spec.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. onTimeWindowChange: () => {},
  25. project: projects[0]!,
  26. thresholdChart: <div>chart</div>,
  27. timeWindow: 30,
  28. };
  29. beforeEach(() => {
  30. MockApiClient.addMockResponse({
  31. url: '/organizations/org-slug/tags/',
  32. body: [],
  33. });
  34. MockApiClient.addMockResponse({
  35. url: '/organizations/org-slug/recent-searches/',
  36. body: [],
  37. });
  38. MockApiClient.addMockResponse({
  39. url: '/organizations/org-slug/recent-searches/',
  40. method: 'POST',
  41. body: [],
  42. });
  43. MockApiClient.addMockResponse({
  44. url: '/projects/org-slug/project-slug/environments/',
  45. body: [],
  46. });
  47. });
  48. afterEach(() => {
  49. MockApiClient.clearMockResponses();
  50. jest.clearAllMocks();
  51. });
  52. it('searches with new searchbar (search-query-builder-alerts)', async () => {
  53. render(
  54. <RuleConditionsForm {...props} organization={organization} router={router} />,
  55. {
  56. router,
  57. organization: {...organization, features: ['search-query-builder-alerts']},
  58. }
  59. );
  60. const input = await screen.findByPlaceholderText(
  61. 'Filter events by level, message, and other properties\u2026'
  62. );
  63. expect(input).toBeInTheDocument();
  64. await userEvent.clear(input);
  65. await userEvent.type(input, 'a{enter}');
  66. expect(mockSearch).toHaveBeenCalledTimes(1);
  67. expect(mockSearch).toHaveBeenCalledWith('a', true);
  68. });
  69. it('renders low confidence warning', async () => {
  70. render(
  71. <RuleConditionsForm
  72. {...props}
  73. organization={organization}
  74. router={router}
  75. isLowConfidenceChartData
  76. />,
  77. {
  78. router,
  79. organization: {
  80. ...organization,
  81. features: ['search-query-builder-alerts', 'alerts-eap'],
  82. },
  83. }
  84. );
  85. await screen.findByPlaceholderText(
  86. 'Filter events by level, message, and other properties\u2026'
  87. );
  88. expect(
  89. screen.getByText(
  90. 'Your low sample count may impact the accuracy of this alert. Edit your query or increase your sampling rate.'
  91. )
  92. ).toBeInTheDocument();
  93. });
  94. });