widgetCardContextMenu.spec.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import {LocationFixture} from 'sentry-fixture/locationFixture';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {PageFiltersFixture} from 'sentry-fixture/pageFilters';
  4. import {RouterFixture} from 'sentry-fixture/routerFixture';
  5. import {WidgetFixture} from 'sentry-fixture/widget';
  6. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  7. import {MEPSettingProvider} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  8. import {DisplayType, WidgetType} from 'sentry/views/dashboards/types';
  9. import {performanceScoreTooltip} from 'sentry/views/dashboards/utils';
  10. import {DashboardsMEPProvider} from 'sentry/views/dashboards/widgetCard/dashboardsMEPContext';
  11. import WidgetCardContextMenu from 'sentry/views/dashboards/widgetCard/widgetCardContextMenu';
  12. describe('WidgetCardContextMenu', () => {
  13. it('displays performance_score tooltip when widget uses performance_score', async () => {
  14. render(
  15. <MEPSettingProvider>
  16. <DashboardsMEPProvider>
  17. <WidgetCardContextMenu
  18. location={LocationFixture()}
  19. organization={OrganizationFixture({
  20. features: ['discover-basic'],
  21. })}
  22. router={RouterFixture()}
  23. selection={PageFiltersFixture()}
  24. widget={{
  25. displayType: DisplayType.AREA,
  26. interval: '',
  27. queries: [
  28. {
  29. name: '',
  30. fields: ['performance_score(measurements.score.total)'],
  31. aggregates: ['performance_score(measurements.score.total)'],
  32. conditions: '',
  33. columns: [],
  34. orderby: '',
  35. },
  36. ],
  37. title: '',
  38. datasetSource: undefined,
  39. description: undefined,
  40. id: undefined,
  41. layout: undefined,
  42. limit: undefined,
  43. tempId: undefined,
  44. thresholds: undefined,
  45. widgetType: WidgetType.TRANSACTIONS,
  46. }}
  47. widgetLimitReached={false}
  48. showContextMenu
  49. />
  50. </DashboardsMEPProvider>
  51. </MEPSettingProvider>
  52. );
  53. await userEvent.click(await screen.findByLabelText('Widget actions'));
  54. expect(screen.getByText('Open in Discover')).toBeInTheDocument();
  55. await userEvent.hover(screen.getByText('Open in Discover'));
  56. expect(await screen.findByText(performanceScoreTooltip)).toBeInTheDocument();
  57. });
  58. it('disables duplication if limit reached', async function () {
  59. render(
  60. <MEPSettingProvider>
  61. <DashboardsMEPProvider>
  62. <WidgetCardContextMenu
  63. location={LocationFixture()}
  64. organization={OrganizationFixture({
  65. features: ['discover-basic', 'dashboards-edit'],
  66. })}
  67. router={RouterFixture()}
  68. selection={PageFiltersFixture()}
  69. widget={WidgetFixture({
  70. widgetType: WidgetType.DISCOVER,
  71. })}
  72. widgetLimitReached
  73. showContextMenu
  74. />
  75. </DashboardsMEPProvider>
  76. </MEPSettingProvider>
  77. );
  78. await userEvent.click(await screen.findByLabelText('Widget actions'));
  79. const $button = screen.getByRole('menuitemradio', {name: 'Duplicate Widget'});
  80. expect($button).toHaveAttribute('aria-disabled', 'true');
  81. });
  82. it('renders the Open in Explore button for span widgets', async function () {
  83. render(
  84. <MEPSettingProvider>
  85. <DashboardsMEPProvider>
  86. <WidgetCardContextMenu
  87. location={LocationFixture()}
  88. organization={OrganizationFixture({})}
  89. router={RouterFixture()}
  90. selection={PageFiltersFixture()}
  91. widget={WidgetFixture({widgetType: WidgetType.SPANS})}
  92. widgetLimitReached={false}
  93. showContextMenu
  94. />
  95. </DashboardsMEPProvider>
  96. </MEPSettingProvider>
  97. );
  98. await userEvent.click(await screen.findByLabelText('Widget actions'));
  99. expect(await screen.findByText('Open in Explore')).toBeInTheDocument();
  100. });
  101. });