incompatibleAlertQuery.spec.tsx 4.0 KB

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