layout.spec.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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'],
  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: Set Up Custom Metric
  44. expect(
  45. await screen.findByRole('button', {name: 'Set Up Custom Metric'})
  46. ).toBeInTheDocument();
  47. expect(
  48. screen.queryByText(/there are upcoming changes to the Metrics API/i)
  49. ).toBeInTheDocument();
  50. // Main View: Displays the empty state.
  51. expect(screen.queryByText(/track and solve what matters/i)).toBeInTheDocument();
  52. expect(
  53. screen.getByRole('button', {name: 'View Performance Metrics'})
  54. ).toBeInTheDocument();
  55. });
  56. it("not using performance and doesn't have custom metrics", async function () {
  57. jest.spyOn(metricsContext, 'useMetricsContext').mockReturnValue({
  58. ...useMetricsContextReturnValueMock,
  59. hasCustomMetrics: false,
  60. hasPerformanceMetrics: false,
  61. isHasMetricsLoading: false,
  62. });
  63. render(<MetricsLayout />, {organization});
  64. // Main View: Empty State
  65. expect(await screen.findByText(/track and solve what matters/i)).toBeInTheDocument();
  66. // Button: Read Docs
  67. expect(screen.getByRole('button', {name: 'Read Docs'})).toBeInTheDocument();
  68. expect(
  69. screen.queryByRole('button', {name: 'Set Up Custom Metric'})
  70. ).toBeInTheDocument();
  71. });
  72. it('not using performance and has custom metrics', async function () {
  73. jest.spyOn(metricsContext, 'useMetricsContext').mockReturnValue({
  74. ...useMetricsContextReturnValueMock,
  75. hasCustomMetrics: true,
  76. hasPerformanceMetrics: false,
  77. isHasMetricsLoading: false,
  78. });
  79. render(<MetricsLayout />, {organization});
  80. // Alert: Old API metrics ingestion ending soon.
  81. expect(
  82. await screen.findByText(
  83. /There are upcoming changes to the Metrics API that may affect your usage/i
  84. )
  85. ).toBeInTheDocument();
  86. // Button: Add Custom Metrics
  87. expect(screen.getByRole('button', {name: 'Add Custom Metrics'})).toBeInTheDocument();
  88. // Main View: Does not display the empty state.
  89. expect(screen.queryByText(/track and solve what matters/i)).not.toBeInTheDocument();
  90. });
  91. });