widgetCardContextMenu.spec.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. });