123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- import {OrganizationFixture} from 'sentry-fixture/organization';
- import {render, screen} from 'sentry-test/reactTestingLibrary';
- import * as metricsContext from 'sentry/views/metrics/context';
- import {MetricsLayout} from 'sentry/views/metrics/layout';
- const useMetricsContextReturnValueMock = {
- addWidget: () => {},
- duplicateWidget: () => {},
- focusArea: {},
- hasCustomMetrics: false,
- hasPerformanceMetrics: false,
- highlightedSampleId: undefined,
- isDefaultQuery: false,
- isMultiChartMode: false,
- isHasMetricsLoading: true,
- metricsSamples: [],
- removeWidget: () => {},
- selectedWidgetIndex: 0,
- setDefaultQuery: () => {},
- setHighlightedSampleId: () => {},
- setIsMultiChartMode: () => {},
- setMetricsSamples: () => {},
- setSelectedWidgetIndex: () => {},
- showQuerySymbols: false,
- updateWidget: () => {},
- widgets: [],
- toggleWidgetVisibility: () => {},
- };
- jest.mock('sentry/views/metrics/useCreateDashboard');
- jest.mock('sentry/views/metrics/scratchpad');
- jest.mock('sentry/views/metrics/queries');
- describe('Metrics Layout', function () {
- const organization = OrganizationFixture({
- features: [
- 'custom-metrics',
- 'custom-metrics-extraction-rule',
- 'custom-metrics-extraction-rule-ui',
- ],
- });
- it("already using performance and don't have old custom metrics", async function () {
- jest.spyOn(metricsContext, 'useMetricsContext').mockReturnValue({
- ...useMetricsContextReturnValueMock,
- hasCustomMetrics: false,
- hasPerformanceMetrics: true,
- isHasMetricsLoading: false,
- });
- render(<MetricsLayout />, {organization});
- // Button: Create Metric
- expect(
- await screen.findByRole('button', {name: 'Create Metric'})
- ).toBeInTheDocument();
- // Alert: No alert shall be rendered
- expect(
- screen.queryByText(/there are upcoming changes to the Metrics API/i)
- ).not.toBeInTheDocument();
- expect(
- screen.queryByText(/Metrics using with the old API will stop being ingested/i)
- ).not.toBeInTheDocument();
- // Main View: Does not display the empty state.
- expect(screen.queryByText(/track and solve what matters/i)).not.toBeInTheDocument();
- });
- it("not using performance and don't have old custom metrics", async function () {
- jest.spyOn(metricsContext, 'useMetricsContext').mockReturnValue({
- ...useMetricsContextReturnValueMock,
- hasCustomMetrics: false,
- hasPerformanceMetrics: false,
- isHasMetricsLoading: false,
- });
- render(<MetricsLayout />, {organization});
- // Main View: Empty State
- expect(await screen.findByText(/track and solve what matters/i)).toBeInTheDocument();
- // Button: Set Up Tracing
- expect(screen.getByRole('button', {name: 'Set Up Tracing'})).toBeInTheDocument();
- // Not in the page: Create Metric
- expect(screen.queryByRole('button', {name: 'Create Metric'})).not.toBeInTheDocument();
- });
- it('not using performance and have old custom metrics', async function () {
- jest.spyOn(metricsContext, 'useMetricsContext').mockReturnValue({
- ...useMetricsContextReturnValueMock,
- hasCustomMetrics: true,
- hasPerformanceMetrics: false,
- isHasMetricsLoading: false,
- });
- render(<MetricsLayout />, {organization});
- // Alert: Old API metrics ingestion ending soon.
- expect(
- await screen.findByText(/Metrics using with the old API will stop being ingested/i)
- ).toBeInTheDocument();
- // Button: Create Metric
- expect(screen.getByRole('button', {name: 'Create Metric'})).toBeInTheDocument();
- // Main View: Does not display the empty state.
- expect(screen.queryByText(/track and solve what matters/i)).not.toBeInTheDocument();
- });
- });
|