layout.spec.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import * as metricsContext from 'sentry/views/metrics/context';
  4. import {MetricsLayout} from 'sentry/views/metrics/layout';
  5. const useMetricsContextReturnValueMock = {
  6. addWidget: () => {},
  7. duplicateWidget: () => {},
  8. focusArea: {},
  9. hasCustomMetrics: false,
  10. hasPerformanceMetrics: false,
  11. highlightedSampleId: undefined,
  12. isDefaultQuery: false,
  13. isMultiChartMode: false,
  14. isHasMetricsLoading: true,
  15. metricsSamples: [],
  16. removeWidget: () => {},
  17. selectedWidgetIndex: 0,
  18. setDefaultQuery: () => {},
  19. setHighlightedSampleId: () => {},
  20. setIsMultiChartMode: () => {},
  21. setMetricsSamples: () => {},
  22. setSelectedWidgetIndex: () => {},
  23. showQuerySymbols: false,
  24. updateWidget: () => {},
  25. widgets: [],
  26. toggleWidgetVisibility: () => {},
  27. };
  28. jest.mock('sentry/views/metrics/useCreateDashboard');
  29. jest.mock('sentry/views/metrics/scratchpad');
  30. jest.mock('sentry/views/metrics/queries');
  31. describe('Metrics Layout', function () {
  32. const organization = OrganizationFixture({
  33. features: [
  34. 'custom-metrics',
  35. 'custom-metrics-extraction-rule',
  36. 'custom-metrics-extraction-rule-ui',
  37. ],
  38. });
  39. it("already using performance and don't have old custom metrics", async function () {
  40. jest.spyOn(metricsContext, 'useMetricsContext').mockReturnValue({
  41. ...useMetricsContextReturnValueMock,
  42. hasCustomMetrics: false,
  43. hasPerformanceMetrics: true,
  44. isHasMetricsLoading: false,
  45. });
  46. render(<MetricsLayout />, {organization});
  47. // Button: Create Metric
  48. expect(
  49. await screen.findByRole('button', {name: 'Create Metric'})
  50. ).toBeInTheDocument();
  51. // Alert: No alert shall be rendered
  52. expect(
  53. screen.queryByText(/there are upcoming changes to the Metrics API/i)
  54. ).not.toBeInTheDocument();
  55. expect(
  56. screen.queryByText(/Metrics using with the old API will stop being ingested/i)
  57. ).not.toBeInTheDocument();
  58. // Main View: Does not display the empty state.
  59. expect(screen.queryByText(/track and solve what matters/i)).not.toBeInTheDocument();
  60. });
  61. it("not using performance and don't have old custom metrics", async function () {
  62. jest.spyOn(metricsContext, 'useMetricsContext').mockReturnValue({
  63. ...useMetricsContextReturnValueMock,
  64. hasCustomMetrics: false,
  65. hasPerformanceMetrics: false,
  66. isHasMetricsLoading: false,
  67. });
  68. render(<MetricsLayout />, {organization});
  69. // Main View: Empty State
  70. expect(await screen.findByText(/track and solve what matters/i)).toBeInTheDocument();
  71. // Button: Set Up Tracing
  72. expect(screen.getByRole('button', {name: 'Set Up Tracing'})).toBeInTheDocument();
  73. // Not in the page: Create Metric
  74. expect(screen.queryByRole('button', {name: 'Create Metric'})).not.toBeInTheDocument();
  75. });
  76. it('not using performance and have old custom metrics', async function () {
  77. jest.spyOn(metricsContext, 'useMetricsContext').mockReturnValue({
  78. ...useMetricsContextReturnValueMock,
  79. hasCustomMetrics: true,
  80. hasPerformanceMetrics: false,
  81. isHasMetricsLoading: false,
  82. });
  83. render(<MetricsLayout />, {organization});
  84. // Alert: Old API metrics ingestion ending soon.
  85. expect(
  86. await screen.findByText(/Metrics using with the old API will stop being ingested/i)
  87. ).toBeInTheDocument();
  88. // Button: Create Metric
  89. expect(screen.getByRole('button', {name: 'Create Metric'})).toBeInTheDocument();
  90. // Main View: Does not display the empty state.
  91. expect(screen.queryByText(/track and solve what matters/i)).not.toBeInTheDocument();
  92. });
  93. });