Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.16] [Exploratory view] Only show metric loading for relevant series (#118299) #118460

Merged
merged 1 commit into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ObservabilityPublicPluginsStart } from '../../../plugin';
import { EuiThemeProvider } from '../../../../../../../src/plugins/kibana_react/common';
import { lensPluginMock } from '../../../../../lens/public/mocks';
import * as useAppIndexPatternHook from './hooks/use_app_index_pattern';
import { IndexPatternContextProvider } from './hooks/use_app_index_pattern';
import { IndexPatternContext, IndexPatternContextProvider } from './hooks/use_app_index_pattern';
import { AllSeries, SeriesContextValue, UrlStorageContext } from './hooks/use_series_storage';

import * as fetcherHook from '../../../hooks/use_fetcher';
Expand Down Expand Up @@ -234,7 +234,7 @@ export const mockUseHasData = () => {
return { spy, onRefreshTimeRange };
};

export const mockAppIndexPattern = () => {
export const mockAppIndexPattern = (props?: Partial<IndexPatternContext>) => {
const loadIndexPattern = jest.fn();
const spy = jest.spyOn(useAppIndexPatternHook, 'useAppIndexPatternContext').mockReturnValue({
indexPattern: mockIndexPattern,
Expand All @@ -244,6 +244,7 @@ export const mockAppIndexPattern = () => {
loadIndexPattern,
indexPatterns: { ux: mockIndexPattern } as unknown as Record<AppDataType, IndexPattern>,
indexPatternErrors: {} as any,
...(props || {}),
});
return { spy, loadIndexPattern };
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';
import { screen } from '@testing-library/react';
import { mockAppIndexPattern, mockIndexPattern, mockUxSeries, render } from '../rtl_helpers';
import { getDefaultConfigs } from '../configurations/default_configs';
import { PERCENTILE } from '../configurations/constants';
import { ReportMetricOptions } from './report_metric_options';

describe('ReportMetricOptions', function () {
const dataViewSeries = getDefaultConfigs({
reportType: 'kpi-over-time',
indexPattern: mockIndexPattern,
dataType: 'ux',
});

it('should render properly', async function () {
render(
<ReportMetricOptions seriesId={0} seriesConfig={dataViewSeries} series={mockUxSeries} />
);

expect(await screen.findByText('No data available')).toBeInTheDocument();
});

it('should display loading if index pattern is not available and is loading', async function () {
mockAppIndexPattern({ loading: true, indexPatterns: undefined });
const { container } = render(
<ReportMetricOptions
seriesId={0}
seriesConfig={{ ...dataViewSeries, hasOperationType: true }}
series={{ ...mockUxSeries, breakdown: PERCENTILE }}
/>
);

expect(container.getElementsByClassName('euiLoadingSpinner').length).toBe(1);
});

it('should not display loading if index pattern is already loaded', async function () {
mockAppIndexPattern({ loading: true });
render(
<ReportMetricOptions
seriesId={0}
seriesConfig={{ ...dataViewSeries, hasOperationType: true }}
series={{ ...mockUxSeries, breakdown: PERCENTILE }}
/>
);

expect(await screen.findByText('Page load time')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function ReportMetricOptions({ seriesId, series, seriesConfig }: Props) {
</EuiPopover>
)}
{series.selectedMetricField &&
(indexPattern && !loading ? (
(indexPattern ? (
<EuiBadge
iconType="cross"
iconSide="right"
Expand Down