errors.spec.tsx 5.7 KB

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