incompatibleAlertQuery.spec.tsx 4.1 KB

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