incompatibleAlertQuery.spec.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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/discover/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', async () => {
  13. const eventView = EventView.fromSavedQuery({
  14. ...DEFAULT_EVENT_VIEW,
  15. query: 'event.type:error',
  16. });
  17. const wrapper = renderComponent(eventView);
  18. await 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/)).toHaveTextContent(
  46. "An event type wasn't selected. event.type:error has been set as the default"
  47. );
  48. });
  49. it('should warn when yAxis is not allowed', () => {
  50. const eventView = EventView.fromSavedQuery({
  51. ...DEFAULT_EVENT_VIEW,
  52. ...ALL_VIEWS.find(view => view.name === 'Errors by URL'),
  53. query: 'event.type:error',
  54. yAxis: ['count_unique(issue)'],
  55. projects: [2],
  56. });
  57. expect(eventView.getYAxis()).toBe('count_unique(issue)');
  58. renderComponent(eventView);
  59. expect(
  60. screen.getByText('An alert can’t use the metric just yet.')
  61. ).toBeInTheDocument();
  62. expect(screen.getByText('count_unique(issue)')).toBeInTheDocument();
  63. });
  64. it('should allow yAxis with a number as the parameter', () => {
  65. const eventView = EventView.fromSavedQuery({
  66. ...DEFAULT_EVENT_VIEW,
  67. query: 'event.type:transaction',
  68. yAxis: ['apdex(300)'],
  69. fields: [...DEFAULT_EVENT_VIEW.fields, 'apdex(300)'],
  70. projects: [2],
  71. });
  72. expect(eventView.getYAxis()).toBe('apdex(300)');
  73. const wrapper = renderComponent(eventView);
  74. expect(wrapper.container).toBeEmptyDOMElement();
  75. });
  76. it('should allow yAxis with a measurement as the parameter', () => {
  77. const eventView = EventView.fromSavedQuery({
  78. ...DEFAULT_EVENT_VIEW,
  79. query: 'event.type:transaction',
  80. yAxis: ['p75(measurements.fcp)'],
  81. fields: [...DEFAULT_EVENT_VIEW.fields, 'p75(measurements.fcp)'],
  82. projects: [2],
  83. });
  84. expect(eventView.getYAxis()).toBe('p75(measurements.fcp)');
  85. const wrapper = renderComponent(eventView);
  86. expect(wrapper.container).toBeEmptyDOMElement();
  87. });
  88. it('should warn with multiple errors, missing event.type and project', () => {
  89. const eventView = EventView.fromSavedQuery({
  90. ...DEFAULT_EVENT_VIEW,
  91. ...ALL_VIEWS.find(view => view.name === 'Errors by URL'),
  92. query: '',
  93. yAxis: ['count_unique(issue.id)'],
  94. projects: [],
  95. });
  96. renderComponent(eventView);
  97. expect(screen.getByText('No project was selected')).toBeInTheDocument();
  98. expect(screen.getByText(/An event type wasn't selected/)).toHaveTextContent(
  99. "An event type wasn't selected. event.type:error has been set as the default"
  100. );
  101. });
  102. });