layout.spec.tsx 3.4 KB

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