spans.spec.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {PageFiltersFixture} from 'sentry-fixture/pageFilters';
  3. import {WidgetFixture} from 'sentry-fixture/widget';
  4. import {waitFor} from 'sentry-test/reactTestingLibrary';
  5. import type {Client} from 'sentry/api';
  6. import type {Organization} from 'sentry/types/organization';
  7. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  8. import {ALLOWED_EXPLORE_VISUALIZE_AGGREGATES, FieldKind} from 'sentry/utils/fields';
  9. import {SpansConfig} from 'sentry/views/dashboards/datasetConfig/spans';
  10. import {WidgetType} from 'sentry/views/dashboards/types';
  11. describe('SpansConfig', () => {
  12. let organization: Organization;
  13. const api: Client = new MockApiClient();
  14. beforeEach(() => {
  15. MockApiClient.clearMockResponses();
  16. organization = OrganizationFixture({
  17. features: ['performance-view'],
  18. });
  19. });
  20. it('returns all of the EAP aggregations as primary options', () => {
  21. const functionOptions = Object.keys(
  22. SpansConfig.getTableFieldOptions(organization, {})
  23. )
  24. .filter(func => func.startsWith('function'))
  25. .map(func => func.split(':')[1]);
  26. expect(functionOptions).toEqual(ALLOWED_EXPLORE_VISUALIZE_AGGREGATES);
  27. });
  28. it('can make a series request with the expected dataset', async () => {
  29. const eventsStatsMock = MockApiClient.addMockResponse({
  30. url: '/organizations/org-slug/events-stats/',
  31. body: [],
  32. });
  33. const widget = WidgetFixture({
  34. widgetType: WidgetType.SPANS,
  35. });
  36. // Trigger request
  37. SpansConfig.getSeriesRequest!(
  38. api,
  39. widget,
  40. 0,
  41. organization,
  42. PageFiltersFixture(),
  43. undefined,
  44. 'test-referrer',
  45. undefined
  46. );
  47. expect(eventsStatsMock).toHaveBeenCalled();
  48. await waitFor(() => {
  49. expect(eventsStatsMock).toHaveBeenCalledWith(
  50. '/organizations/org-slug/events-stats/',
  51. expect.objectContaining({
  52. query: expect.objectContaining({dataset: DiscoverDatasets.SPANS_EAP}),
  53. })
  54. );
  55. });
  56. });
  57. it('returns the string tags as group by options', () => {
  58. const mockTags = {
  59. ['transaction']: {
  60. name: 'transaction',
  61. key: 'transaction',
  62. kind: FieldKind.TAG,
  63. },
  64. ['platform']: {
  65. name: 'platform',
  66. key: 'platform',
  67. kind: FieldKind.TAG,
  68. },
  69. ['span.duration']: {
  70. name: 'span.duration',
  71. key: 'span.duration',
  72. kind: FieldKind.MEASUREMENT,
  73. },
  74. };
  75. const groupByOptions = SpansConfig.getGroupByFieldOptions!(organization, mockTags);
  76. expect(Object.keys(groupByOptions)).toEqual(['tag:transaction', 'tag:platform']);
  77. });
  78. });