datasetSelectorTabs.spec.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import EventView, {type EventViewOptions} from 'sentry/utils/discover/eventView';
  4. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  5. import {DatasetSelectorTabs} from 'sentry/views/discover/savedQuery/datasetSelectorTabs';
  6. const EVENT_VIEW_CONSTRUCTOR_PROPS: EventViewOptions = {
  7. createdBy: undefined,
  8. end: undefined,
  9. environment: [],
  10. fields: [{field: 'transaction'}, {field: 'project'}],
  11. name: 'Test',
  12. project: [],
  13. query: 'foo:bar',
  14. start: undefined,
  15. team: [],
  16. sorts: [],
  17. statsPeriod: undefined,
  18. topEvents: undefined,
  19. id: undefined,
  20. display: undefined,
  21. };
  22. describe('Discover DatasetSelector', function () {
  23. const {router} = initializeOrg({
  24. organization: {features: ['performance-view']},
  25. });
  26. it('renders tabs', function () {
  27. const eventView = new EventView(EVENT_VIEW_CONSTRUCTOR_PROPS);
  28. render(
  29. <DatasetSelectorTabs
  30. isHomepage={false}
  31. savedQuery={undefined}
  32. eventView={eventView}
  33. />,
  34. {
  35. router,
  36. }
  37. );
  38. expect(screen.getByRole('tab', {name: 'Errors'})).toBeInTheDocument();
  39. expect(screen.getByRole('tab', {name: 'Transactions'})).toBeInTheDocument();
  40. });
  41. it('pushes compatible query', async function () {
  42. const eventView = new EventView({
  43. createdBy: undefined,
  44. end: undefined,
  45. environment: [],
  46. fields: [
  47. {field: 'transaction'},
  48. {field: 'project'},
  49. {field: 'count_unique(error.handled)'},
  50. {field: 'error.mechanism'},
  51. ],
  52. name: 'Test',
  53. project: [],
  54. query: '(error.type:bar AND project:foo)',
  55. start: undefined,
  56. team: [],
  57. sorts: [{field: 'error.mechanism', kind: 'asc'}],
  58. statsPeriod: undefined,
  59. topEvents: undefined,
  60. id: undefined,
  61. display: undefined,
  62. });
  63. render(
  64. <DatasetSelectorTabs
  65. isHomepage={false}
  66. savedQuery={undefined}
  67. eventView={eventView}
  68. />,
  69. {
  70. router,
  71. }
  72. );
  73. await userEvent.click(screen.getByRole('tab', {name: 'Transactions'}));
  74. expect(router.push).toHaveBeenCalledWith(
  75. expect.objectContaining({
  76. query: expect.objectContaining({
  77. project: undefined,
  78. field: ['transaction', 'project'],
  79. query: 'project:foo',
  80. queryDataset: 'transaction-like',
  81. sort: '-transaction',
  82. incompatible: true,
  83. }),
  84. })
  85. );
  86. });
  87. it('only updates dataset if saved query', async function () {
  88. const eventView = new EventView({
  89. ...EVENT_VIEW_CONSTRUCTOR_PROPS,
  90. dataset: DiscoverDatasets.ERRORS,
  91. id: '1',
  92. });
  93. render(
  94. <DatasetSelectorTabs
  95. isHomepage={false}
  96. savedQuery={undefined}
  97. eventView={eventView}
  98. />,
  99. {
  100. router,
  101. }
  102. );
  103. await userEvent.click(screen.getByRole('tab', {name: 'Transactions'}));
  104. expect(router.push).toHaveBeenCalledWith(
  105. expect.objectContaining({
  106. query: expect.objectContaining({
  107. project: undefined,
  108. field: ['transaction', 'project'],
  109. query: 'foo:bar',
  110. queryDataset: 'transaction-like',
  111. }),
  112. })
  113. );
  114. });
  115. });