layout.spec.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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: ['custom-metrics', 'custom-metrics-extraction-rule'],
  34. });
  35. it("already using performance and don't have old custom metrics", async function () {
  36. jest.spyOn(metricsContext, 'useMetricsContext').mockReturnValue({
  37. ...useMetricsContextReturnValueMock,
  38. hasCustomMetrics: false,
  39. hasPerformanceMetrics: true,
  40. isHasMetricsLoading: false,
  41. });
  42. render(<MetricsLayout />, {organization});
  43. // Button: Add New Metric
  44. expect(
  45. await screen.findByRole('button', {name: 'Add New Metric'})
  46. ).toBeInTheDocument();
  47. // Alert: No alert shall be rendered
  48. expect(
  49. screen.queryByText(/there are upcoming changes to the Metrics API/i)
  50. ).not.toBeInTheDocument();
  51. expect(
  52. screen.queryByText(/Metrics using with the old API will stop being ingested/i)
  53. ).not.toBeInTheDocument();
  54. // Main View: Does not display the empty state.
  55. expect(screen.queryByText(/track and solve what matters/i)).not.toBeInTheDocument();
  56. });
  57. it("not using performance and don't have old custom metrics", async function () {
  58. jest.spyOn(metricsContext, 'useMetricsContext').mockReturnValue({
  59. ...useMetricsContextReturnValueMock,
  60. hasCustomMetrics: false,
  61. hasPerformanceMetrics: false,
  62. isHasMetricsLoading: false,
  63. });
  64. render(<MetricsLayout />, {organization});
  65. // Main View: Empty State
  66. expect(await screen.findByText(/track and solve what matters/i)).toBeInTheDocument();
  67. // Button: Set Up Tracing
  68. expect(screen.getByRole('button', {name: 'Set Up Tracing'})).toBeInTheDocument();
  69. // Not in the page: Add New Metric
  70. expect(
  71. screen.queryByRole('button', {name: 'Add New Metric'})
  72. ).not.toBeInTheDocument();
  73. });
  74. it('not using performance and have old custom metrics', async function () {
  75. jest.spyOn(metricsContext, 'useMetricsContext').mockReturnValue({
  76. ...useMetricsContextReturnValueMock,
  77. hasCustomMetrics: true,
  78. hasPerformanceMetrics: false,
  79. isHasMetricsLoading: false,
  80. });
  81. render(<MetricsLayout />, {organization});
  82. // Alert: Old API metrics ingestion ending soon.
  83. expect(
  84. await screen.findByText(/Metrics using with the old API will stop being ingested/i)
  85. ).toBeInTheDocument();
  86. // Button: Add New Metric
  87. expect(screen.getByRole('button', {name: 'Add New Metric'})).toBeInTheDocument();
  88. // Main View: Does not display the empty state.
  89. expect(screen.queryByText(/track and solve what matters/i)).not.toBeInTheDocument();
  90. });
  91. });