ruleConditionsForm.spec.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. it('searches with new searchbar (search-query-builder-alerts)', async () => {
  9. const {organization, projects, router} = initializeOrg({
  10. organization: {features: ['search-query-builder-alerts']},
  11. });
  12. ProjectsStore.loadInitialData(projects);
  13. MockApiClient.addMockResponse({
  14. url: '/organizations/org-slug/tags/',
  15. body: [],
  16. });
  17. MockApiClient.addMockResponse({
  18. url: '/organizations/org-slug/recent-searches/',
  19. body: [],
  20. });
  21. MockApiClient.addMockResponse({
  22. url: '/organizations/org-slug/recent-searches/',
  23. method: 'POST',
  24. body: [],
  25. });
  26. MockApiClient.addMockResponse({
  27. url: '/projects/org-slug/project-slug/environments/',
  28. body: [],
  29. });
  30. const mockSearch = jest.fn();
  31. const props = {
  32. aggregate: 'foo',
  33. alertType: 'errors' as AlertType,
  34. comparisonType: AlertRuleComparisonType.COUNT,
  35. dataset: Dataset.ERRORS,
  36. disabled: false,
  37. isEditing: true,
  38. onComparisonDeltaChange: _ => {},
  39. onFilterSearch: mockSearch,
  40. onMonitorTypeSelect: _ => {},
  41. onTimeWindowChange: _ => {},
  42. project: projects[0],
  43. thresholdChart: <div>chart</div>,
  44. timeWindow: 30,
  45. };
  46. render(
  47. <RuleConditionsForm {...props} organization={organization} router={router} />,
  48. {
  49. router,
  50. organization: {...organization, features: ['search-query-builder-alerts']},
  51. }
  52. );
  53. const input = await screen.findByPlaceholderText(
  54. 'Filter events by level, message, and other properties\u2026'
  55. );
  56. expect(input).toBeInTheDocument();
  57. await userEvent.clear(input);
  58. await userEvent.type(input, 'a{enter}');
  59. expect(mockSearch).toHaveBeenCalledTimes(1);
  60. expect(mockSearch).toHaveBeenCalledWith('a', true);
  61. });
  62. });