incompatibleAlertQuery.spec.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import EventView from 'sentry/utils/discover/eventView';
  3. import {IncompatibleAlertQuery} from 'sentry/views/alerts/rules/metric/incompatibleAlertQuery';
  4. import {ALL_VIEWS, DEFAULT_EVENT_VIEW} from 'sentry/views/eventsV2/data';
  5. function renderComponent(eventView: EventView) {
  6. const organization = TestStubs.Organization();
  7. return render(
  8. <IncompatibleAlertQuery orgSlug={organization.slug} eventView={eventView} />
  9. );
  10. }
  11. describe('IncompatibleAlertQuery', () => {
  12. it('should call onClose', () => {
  13. const eventView = EventView.fromSavedQuery({
  14. ...DEFAULT_EVENT_VIEW,
  15. query: 'event.type:error',
  16. });
  17. const wrapper = renderComponent(eventView);
  18. userEvent.click(screen.getByRole('button', {name: 'Close'}));
  19. expect(wrapper.container).toBeEmptyDOMElement();
  20. });
  21. it('should warn when project is not selected', () => {
  22. const eventView = EventView.fromSavedQuery({
  23. ...DEFAULT_EVENT_VIEW,
  24. query: 'event.type:error',
  25. });
  26. renderComponent(eventView);
  27. expect(screen.getByText('No project was selected')).toBeInTheDocument();
  28. });
  29. it('should warn when all projects are selected (-1)', () => {
  30. const eventView = EventView.fromSavedQuery({
  31. ...DEFAULT_EVENT_VIEW,
  32. query: 'event.type:error',
  33. projects: [-1],
  34. });
  35. renderComponent(eventView);
  36. expect(screen.getByText('No project was selected')).toBeInTheDocument();
  37. });
  38. it('should warn when event.type is not specified', () => {
  39. const eventView = EventView.fromSavedQuery({
  40. ...DEFAULT_EVENT_VIEW,
  41. query: '',
  42. projects: [2],
  43. });
  44. renderComponent(eventView);
  45. expect(screen.getByText("An event type wasn't selected")).toBeInTheDocument();
  46. });
  47. it('should warn when yAxis is not allowed', () => {
  48. const eventView = EventView.fromSavedQuery({
  49. ...DEFAULT_EVENT_VIEW,
  50. ...ALL_VIEWS.find(view => view.name === 'Errors by URL'),
  51. query: 'event.type:error',
  52. yAxis: ['count_unique(issue)'],
  53. projects: [2],
  54. });
  55. expect(eventView.getYAxis()).toBe('count_unique(issue)');
  56. renderComponent(eventView);
  57. expect(screen.getByText('An alert can’t use the metric')).toBeInTheDocument();
  58. expect(screen.getByText('count_unique(issue)')).toBeInTheDocument();
  59. });
  60. it('should allow yAxis with a number as the parameter', () => {
  61. const eventView = EventView.fromSavedQuery({
  62. ...DEFAULT_EVENT_VIEW,
  63. query: 'event.type:transaction',
  64. yAxis: ['apdex(300)'],
  65. fields: [...DEFAULT_EVENT_VIEW.fields, 'apdex(300)'],
  66. projects: [2],
  67. });
  68. expect(eventView.getYAxis()).toBe('apdex(300)');
  69. const wrapper = renderComponent(eventView);
  70. expect(wrapper.container).toBeEmptyDOMElement();
  71. });
  72. it('should allow yAxis with a measurement as the parameter', () => {
  73. const eventView = EventView.fromSavedQuery({
  74. ...DEFAULT_EVENT_VIEW,
  75. query: 'event.type:transaction',
  76. yAxis: ['p75(measurements.fcp)'],
  77. fields: [...DEFAULT_EVENT_VIEW.fields, 'p75(measurements.fcp)'],
  78. projects: [2],
  79. });
  80. expect(eventView.getYAxis()).toBe('p75(measurements.fcp)');
  81. const wrapper = renderComponent(eventView);
  82. expect(wrapper.container).toBeEmptyDOMElement();
  83. });
  84. it('should warn with multiple errors, missing event.type and project', () => {
  85. const eventView = EventView.fromSavedQuery({
  86. ...DEFAULT_EVENT_VIEW,
  87. ...ALL_VIEWS.find(view => view.name === 'Errors by URL'),
  88. query: '',
  89. yAxis: ['count_unique(issue.id)'],
  90. projects: [],
  91. });
  92. renderComponent(eventView);
  93. expect(screen.getByText('No project was selected')).toBeInTheDocument();
  94. expect(screen.getByText("An event type wasn't selected")).toBeInTheDocument();
  95. });
  96. });