errors.spec.tsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {PageFiltersFixture} from 'sentry-fixture/pageFilters';
  3. import {ProjectFixture} from 'sentry-fixture/project';
  4. import {UserFixture} from 'sentry-fixture/user';
  5. import {WidgetFixture} from 'sentry-fixture/widget';
  6. import {initializeOrg} from 'sentry-test/initializeOrg';
  7. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  8. import type {EventViewOptions} from 'sentry/utils/discover/eventView';
  9. import EventView from 'sentry/utils/discover/eventView';
  10. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  11. import {ErrorsConfig} from 'sentry/views/dashboards/datasetConfig/errors';
  12. describe('ErrorsConfig', function () {
  13. describe('getCustomFieldRenderer', function () {
  14. const {organization, router} = initializeOrg();
  15. const baseEventViewOptions: EventViewOptions = {
  16. start: undefined,
  17. end: undefined,
  18. createdBy: UserFixture(),
  19. display: undefined,
  20. fields: [],
  21. sorts: [],
  22. query: '',
  23. project: [],
  24. environment: [],
  25. yAxis: 'count()',
  26. id: undefined,
  27. name: undefined,
  28. statsPeriod: '14d',
  29. team: [],
  30. topEvents: undefined,
  31. };
  32. it('links trace ids to performance', async function () {
  33. const customFieldRenderer = ErrorsConfig.getCustomFieldRenderer!('trace', {});
  34. render(
  35. customFieldRenderer!(
  36. {trace: 'abcd'},
  37. {
  38. organization,
  39. location: router.location,
  40. eventView: new EventView({
  41. ...baseEventViewOptions,
  42. fields: [{field: 'trace'}],
  43. }),
  44. }
  45. ) as React.ReactElement<any, any>,
  46. {router}
  47. );
  48. await userEvent.click(await screen.findByText('abcd'));
  49. expect(router.push).toHaveBeenCalledWith({
  50. pathname: '/organizations/org-slug/performance/trace/abcd/',
  51. query: {
  52. pageEnd: undefined,
  53. pageStart: undefined,
  54. statsPeriod: '14d',
  55. },
  56. });
  57. });
  58. it('links event ids to event details', async function () {
  59. const project = ProjectFixture();
  60. const customFieldRenderer = ErrorsConfig.getCustomFieldRenderer!('id', {});
  61. render(
  62. customFieldRenderer!(
  63. {id: 'defg', 'project.name': project.slug},
  64. {
  65. organization,
  66. location: router.location,
  67. eventView: new EventView({
  68. ...baseEventViewOptions,
  69. fields: [{field: 'id'}],
  70. project: [parseInt(project.id, 10)],
  71. }),
  72. }
  73. ) as React.ReactElement<any, any>,
  74. {router}
  75. );
  76. await userEvent.click(await screen.findByText('defg'));
  77. expect(router.push).toHaveBeenCalledWith({
  78. pathname: `/organizations/org-slug/discover/${project.slug}:defg/`,
  79. query: {
  80. display: undefined,
  81. environment: undefined,
  82. field: 'id',
  83. id: undefined,
  84. interval: undefined,
  85. name: undefined,
  86. project: project.id,
  87. query: '',
  88. sort: undefined,
  89. topEvents: undefined,
  90. widths: undefined,
  91. yAxis: 'count()',
  92. pageEnd: undefined,
  93. pageStart: undefined,
  94. statsPeriod: '14d',
  95. },
  96. });
  97. });
  98. });
  99. describe('getEventsRequest', function () {
  100. let api, organization, mockEventsRequest;
  101. beforeEach(function () {
  102. MockApiClient.clearMockResponses();
  103. api = new MockApiClient();
  104. organization = OrganizationFixture();
  105. mockEventsRequest = MockApiClient.addMockResponse({
  106. url: '/organizations/org-slug/events/',
  107. body: {
  108. data: [],
  109. },
  110. });
  111. });
  112. it('makes a request to the errors dataset', function () {
  113. const pageFilters = PageFiltersFixture();
  114. const widget = WidgetFixture();
  115. ErrorsConfig.getTableRequest!(
  116. api,
  117. widget,
  118. {
  119. fields: ['count()'],
  120. aggregates: ['count()'],
  121. columns: [],
  122. conditions: '',
  123. name: '',
  124. orderby: '',
  125. },
  126. organization,
  127. pageFilters
  128. );
  129. expect(mockEventsRequest).toHaveBeenCalledWith(
  130. '/organizations/org-slug/events/',
  131. expect.objectContaining({
  132. query: expect.objectContaining({
  133. dataset: DiscoverDatasets.ERRORS,
  134. }),
  135. })
  136. );
  137. });
  138. });
  139. describe('getSeriesRequest', function () {
  140. let api, organization, mockEventsRequest;
  141. beforeEach(function () {
  142. MockApiClient.clearMockResponses();
  143. api = new MockApiClient();
  144. organization = OrganizationFixture();
  145. mockEventsRequest = MockApiClient.addMockResponse({
  146. url: '/organizations/org-slug/events-stats/',
  147. body: {
  148. data: [],
  149. },
  150. });
  151. });
  152. it('makes a request to the errors dataset', function () {
  153. const pageFilters = PageFiltersFixture();
  154. const widget = WidgetFixture({
  155. queries: [
  156. {
  157. fields: ['count()'],
  158. aggregates: ['count()'],
  159. columns: [],
  160. conditions: '',
  161. name: '',
  162. orderby: '',
  163. },
  164. ],
  165. });
  166. ErrorsConfig.getSeriesRequest!(api, widget, 0, organization, pageFilters);
  167. expect(mockEventsRequest).toHaveBeenCalledWith(
  168. '/organizations/org-slug/events-stats/',
  169. expect.objectContaining({
  170. query: expect.objectContaining({
  171. dataset: DiscoverDatasets.ERRORS,
  172. }),
  173. })
  174. );
  175. });
  176. });
  177. });