Skip to content

Commit

Permalink
[8.x] [DataUsage][Serverless] UX/API changes based on demo feedback (#…
Browse files Browse the repository at this point in the history
…200911) (#201486)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[DataUsage][Serverless] UX/API changes based on demo feedback
(#200911)](#200911)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"Ash","email":"1849116+ashokaditya@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-11-23T01:08:24Z","message":"[DataUsage][Serverless]
UX/API changes based on demo feedback (#200911)\n\n## Summary\n\nAdds a
bunch of UX updates based on the feedback after demo. \n\n- [x] Tidy
chart legend action popup and links\n- [x] fix UX date picker invalid
time (UX shows invalid time falsely)\n- [ ] Tooltip for date filter\n- [
] send UTC time to requests (1:1 mapping for date-time picked
vs\ndate-time sent)\n- [x] Remove unusable common date filter
shortcuts\n- [x] data stream filter `select all`\n- [x] data stream
filter `clear all`\n- [x] No charts empty state\n- [x] filter in
datastreams that have greater than `0` bytes storage\nsize\n- [ ] Filter
out system indices from data stream filter?\n- [x] Taller filter popover
list for larger lists\n\nFollow up of
https://github.com/elastic/kibana/pull/200731\n\n### Checklist\n\nCheck
the PR satisfies following conditions. \n\nReviewers should verify this
PR satisfies this list as well.\n\n- [x] Any text added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\n-
[
]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas
added for features that require explanation or tutorials\n- [x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [x] If a plugin
configuration key changed, check if it needs to be\nallowlisted in the
cloud and added to the
[docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n-
[x] This was checked for breaking HTTP API changes, and any
breaking\nchanges have been approved by the breaking-change committee.
The\n`release_note:breaking` label should be applied in these
situations.\n- [ ] [Flaky
Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\nused on any tests changed\n- [x] The PR description includes the
appropriate Release Notes section,\nand the correct `release_node:*`
label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n###
Identify risks\n\nDoes this PR introduce any risks? For example,
consider risks like hard\nto test bugs, performance regression,
potential of data loss.\n\nDescribe the risk, its severity, and
mitigation for each identified\nrisk. Invite stakeholders and evaluate
how to proceed before merging.\n\n- [ ] [See some
risk\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\n-
[ ] ...\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"e48f930ab32b5c325ad38175e41f93ec0b8c4ba7","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","ci:build-serverless-image"],"title":"[DataUsage][Serverless]
UX/API changes based on demo
feedback","number":200911,"url":"https://github.com/elastic/kibana/pull/200911","mergeCommit":{"message":"[DataUsage][Serverless]
UX/API changes based on demo feedback (#200911)\n\n## Summary\n\nAdds a
bunch of UX updates based on the feedback after demo. \n\n- [x] Tidy
chart legend action popup and links\n- [x] fix UX date picker invalid
time (UX shows invalid time falsely)\n- [ ] Tooltip for date filter\n- [
] send UTC time to requests (1:1 mapping for date-time picked
vs\ndate-time sent)\n- [x] Remove unusable common date filter
shortcuts\n- [x] data stream filter `select all`\n- [x] data stream
filter `clear all`\n- [x] No charts empty state\n- [x] filter in
datastreams that have greater than `0` bytes storage\nsize\n- [ ] Filter
out system indices from data stream filter?\n- [x] Taller filter popover
list for larger lists\n\nFollow up of
https://github.com/elastic/kibana/pull/200731\n\n### Checklist\n\nCheck
the PR satisfies following conditions. \n\nReviewers should verify this
PR satisfies this list as well.\n\n- [x] Any text added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\n-
[
]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas
added for features that require explanation or tutorials\n- [x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [x] If a plugin
configuration key changed, check if it needs to be\nallowlisted in the
cloud and added to the
[docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n-
[x] This was checked for breaking HTTP API changes, and any
breaking\nchanges have been approved by the breaking-change committee.
The\n`release_note:breaking` label should be applied in these
situations.\n- [ ] [Flaky
Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\nused on any tests changed\n- [x] The PR description includes the
appropriate Release Notes section,\nand the correct `release_node:*`
label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n###
Identify risks\n\nDoes this PR introduce any risks? For example,
consider risks like hard\nto test bugs, performance regression,
potential of data loss.\n\nDescribe the risk, its severity, and
mitigation for each identified\nrisk. Invite stakeholders and evaluate
how to proceed before merging.\n\n- [ ] [See some
risk\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\n-
[ ] ...\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"e48f930ab32b5c325ad38175e41f93ec0b8c4ba7"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/200911","number":200911,"mergeCommit":{"message":"[DataUsage][Serverless]
UX/API changes based on demo feedback (#200911)\n\n## Summary\n\nAdds a
bunch of UX updates based on the feedback after demo. \n\n- [x] Tidy
chart legend action popup and links\n- [x] fix UX date picker invalid
time (UX shows invalid time falsely)\n- [ ] Tooltip for date filter\n- [
] send UTC time to requests (1:1 mapping for date-time picked
vs\ndate-time sent)\n- [x] Remove unusable common date filter
shortcuts\n- [x] data stream filter `select all`\n- [x] data stream
filter `clear all`\n- [x] No charts empty state\n- [x] filter in
datastreams that have greater than `0` bytes storage\nsize\n- [ ] Filter
out system indices from data stream filter?\n- [x] Taller filter popover
list for larger lists\n\nFollow up of
https://github.com/elastic/kibana/pull/200731\n\n### Checklist\n\nCheck
the PR satisfies following conditions. \n\nReviewers should verify this
PR satisfies this list as well.\n\n- [x] Any text added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\n-
[
]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas
added for features that require explanation or tutorials\n- [x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [x] If a plugin
configuration key changed, check if it needs to be\nallowlisted in the
cloud and added to the
[docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n-
[x] This was checked for breaking HTTP API changes, and any
breaking\nchanges have been approved by the breaking-change committee.
The\n`release_note:breaking` label should be applied in these
situations.\n- [ ] [Flaky
Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\nused on any tests changed\n- [x] The PR description includes the
appropriate Release Notes section,\nand the correct `release_node:*`
label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n###
Identify risks\n\nDoes this PR introduce any risks? For example,
consider risks like hard\nto test bugs, performance regression,
potential of data loss.\n\nDescribe the risk, its severity, and
mitigation for each identified\nrisk. Invite stakeholders and evaluate
how to proceed before merging.\n\n- [ ] [See some
risk\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\n-
[ ] ...\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"e48f930ab32b5c325ad38175e41f93ec0b8c4ba7"}}]}]
BACKPORT-->

Co-authored-by: Ash <1849116+ashokaditya@users.noreply.github.com>
  • Loading branch information
kibanamachine and ashokaditya authored Nov 23, 2024
1 parent d1a0c28 commit 59eb481
Show file tree
Hide file tree
Showing 42 changed files with 655 additions and 184 deletions.
14 changes: 14 additions & 0 deletions x-pack/plugins/data_usage/common/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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.
*/

export const PLUGIN_ID = 'data_usage';

export const DEFAULT_SELECTED_OPTIONS = 50 as const;

export const DATA_USAGE_API_ROUTE_PREFIX = '/api/data_usage/';
export const DATA_USAGE_METRICS_API_ROUTE = `/internal${DATA_USAGE_API_ROUTE_PREFIX}metrics`;
export const DATA_USAGE_DATA_STREAMS_API_ROUTE = `/internal${DATA_USAGE_API_ROUTE_PREFIX}data_streams`;
19 changes: 7 additions & 12 deletions x-pack/plugins/data_usage/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@
* 2.0.
*/

import { i18n } from '@kbn/i18n';

export const PLUGIN_ID = 'data_usage';
export const PLUGIN_NAME = i18n.translate('xpack.dataUsage.name', {
defaultMessage: 'Data Usage',
});

export const DEFAULT_SELECTED_OPTIONS = 50 as const;

export const DATA_USAGE_API_ROUTE_PREFIX = '/api/data_usage/';
export const DATA_USAGE_METRICS_API_ROUTE = `/internal${DATA_USAGE_API_ROUTE_PREFIX}metrics`;
export const DATA_USAGE_DATA_STREAMS_API_ROUTE = `/internal${DATA_USAGE_API_ROUTE_PREFIX}data_streams`;
export {
PLUGIN_ID,
DEFAULT_SELECTED_OPTIONS,
DATA_USAGE_API_ROUTE_PREFIX,
DATA_USAGE_METRICS_API_ROUTE,
DATA_USAGE_DATA_STREAMS_API_ROUTE,
} from './constants';
10 changes: 10 additions & 0 deletions x-pack/plugins/data_usage/common/test_utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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.
*/

export { TestProvider } from './test_provider';
export { dataUsageTestQueryClientOptions } from './test_query_client_options';
export { timeXMinutesAgo } from './time_ago';
13 changes: 13 additions & 0 deletions x-pack/plugins/data_usage/common/test_utils/test_provider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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, { memo } from 'react';
import { I18nProvider } from '@kbn/i18n-react';

export const TestProvider = memo(({ children }: { children?: React.ReactNode }) => {
return <I18nProvider>{children}</I18nProvider>;
});
9 changes: 9 additions & 0 deletions x-pack/plugins/data_usage/common/test_utils/time_ago.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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.
*/

export const timeXMinutesAgo = (x: number) =>
new Date(new Date().getTime() - x * 60 * 1000).toISOString();
10 changes: 10 additions & 0 deletions x-pack/plugins/data_usage/common/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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 dateMath from '@kbn/datemath';
export const dateParser = (date: string) => dateMath.parse(date)?.toISOString();
export const momentDateParser = (date: string) => dateMath.parse(date);
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from '@elastic/charts';
import { i18n } from '@kbn/i18n';
import { LegendAction } from './legend_action';
import { MetricTypes, MetricSeries } from '../../../common/rest_types';
import { type MetricTypes, type MetricSeries } from '../../../common/rest_types';
import { formatBytes } from '../../utils/format_bytes';

// TODO: Remove this when we have a title for each metric type
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/data_usage/public/app/components/charts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
*/
import React, { useCallback, useState } from 'react';
import { EuiFlexGroup } from '@elastic/eui';
import { MetricTypes } from '../../../common/rest_types';
import { ChartPanel } from './chart_panel';
import { UsageMetricsResponseSchemaBody } from '../../../common/rest_types';
import type { UsageMetricsResponseSchemaBody, MetricTypes } from '../../../common/rest_types';
import { useTestIdGenerator } from '../../hooks/use_test_id_generator';
interface ChartsProps {
data: UsageMetricsResponseSchemaBody;
Expand Down
35 changes: 35 additions & 0 deletions x-pack/plugins/data_usage/public/app/components/charts_loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 { EuiFlexGroup, EuiFlexItem, EuiPanel, EuiLoadingChart } from '@elastic/eui';
import { useTestIdGenerator } from '../../hooks/use_test_id_generator';

export const ChartsLoading = ({
'data-test-subj': dataTestSubj,
}: {
'data-test-subj'?: string;
}) => {
const getTestId = useTestIdGenerator(dataTestSubj);
// returns 2 loading icons for the two charts
return (
<EuiFlexGroup
direction="column"
alignItems="center"
data-test-subj={getTestId('charts-loading')}
>
{[...Array(2)].map((i) => (
<EuiFlexItem key={i}>
<EuiPanel paddingSize="xl" hasShadow={false} hasBorder={false}>
<EuiLoadingChart size="l" />
</EuiPanel>
</EuiFlexItem>
))}
</EuiFlexGroup>
);
};

ChartsLoading.displayName = 'ChartsLoading';
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* 2.0.
*/
import React from 'react';
import { render, waitFor } from '@testing-library/react';
import { TestProvider } from '../../../common/test_utils';
import { render, waitFor, within, type RenderResult } from '@testing-library/react';
import userEvent, { type UserEvent } from '@testing-library/user-event';
import { DataUsageMetrics } from './data_usage_metrics';
import { useGetDataUsageMetrics } from '../../hooks/use_get_usage_metrics';
Expand Down Expand Up @@ -102,21 +103,6 @@ jest.mock('@kbn/kibana-react-plugin/public', () => {
to: 'now',
display: 'Last 7 days',
},
{
from: 'now-30d',
to: 'now',
display: 'Last 30 days',
},
{
from: 'now-90d',
to: 'now',
display: 'Last 90 days',
},
{
from: 'now-1y',
to: 'now',
display: 'Last 1 year',
},
],
};
return x[k];
Expand Down Expand Up @@ -156,6 +142,7 @@ describe('DataUsageMetrics', () => {
let user: UserEvent;
const testId = 'test';
const testIdFilter = `${testId}-filter`;
let renderComponent: () => RenderResult;

beforeAll(() => {
jest.useFakeTimers();
Expand All @@ -167,18 +154,24 @@ describe('DataUsageMetrics', () => {

beforeEach(() => {
jest.clearAllMocks();
renderComponent = () =>
render(
<TestProvider>
<DataUsageMetrics data-test-subj={testId} />
</TestProvider>
);
user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime, pointerEventsCheck: 0 });
mockUseGetDataUsageMetrics.mockReturnValue(getBaseMockedDataUsageMetrics);
mockUseGetDataUsageDataStreams.mockReturnValue(getBaseMockedDataStreams);
});

it('renders', () => {
const { getByTestId } = render(<DataUsageMetrics data-test-subj={testId} />);
const { getByTestId } = renderComponent();
expect(getByTestId(`${testId}`)).toBeTruthy();
});

it('should show date filter', () => {
const { getByTestId } = render(<DataUsageMetrics data-test-subj={testId} />);
const { getByTestId } = renderComponent();
const dateFilter = getByTestId(`${testIdFilter}-date-range`);
expect(dateFilter).toBeTruthy();
expect(dateFilter.textContent).toContain('to');
Expand All @@ -190,12 +183,12 @@ describe('DataUsageMetrics', () => {
...getBaseMockedDataStreams,
isFetching: true,
});
const { queryByTestId } = render(<DataUsageMetrics data-test-subj={testId} />);
const { queryByTestId } = renderComponent();
expect(queryByTestId(`${testIdFilter}-dataStreams-popoverButton`)).not.toBeTruthy();
});

it('should show data streams filter', () => {
const { getByTestId } = render(<DataUsageMetrics data-test-subj={testId} />);
const { getByTestId } = renderComponent();
expect(getByTestId(`${testIdFilter}-dataStreams-popoverButton`)).toBeTruthy();
});

Expand All @@ -205,7 +198,7 @@ describe('DataUsageMetrics', () => {
data: generateDataStreams(5),
isFetching: false,
});
const { getByTestId } = render(<DataUsageMetrics data-test-subj={testId} />);
const { getByTestId } = renderComponent();
expect(getByTestId(`${testIdFilter}-dataStreams-popoverButton`)).toHaveTextContent(
'Data streams5'
);
Expand All @@ -217,37 +210,84 @@ describe('DataUsageMetrics', () => {
data: generateDataStreams(100),
isFetching: false,
});
const { getByTestId } = render(<DataUsageMetrics data-test-subj={testId} />);
const { getByTestId } = renderComponent();
const toggleFilterButton = getByTestId(`${testIdFilter}-dataStreams-popoverButton`);

expect(toggleFilterButton).toHaveTextContent('Data streams50');
});

it('should allow de-selecting all but one data stream option', async () => {
it('should allow de-selecting data stream options', async () => {
mockUseGetDataUsageDataStreams.mockReturnValue({
error: undefined,
data: generateDataStreams(5),
data: generateDataStreams(10),
isFetching: false,
});
const { getByTestId, getAllByTestId } = render(<DataUsageMetrics data-test-subj={testId} />);
const { getByTestId, getAllByTestId } = renderComponent();
const toggleFilterButton = getByTestId(`${testIdFilter}-dataStreams-popoverButton`);

expect(toggleFilterButton).toHaveTextContent('Data streams5');
expect(toggleFilterButton).toHaveTextContent('Data streams10');
await user.click(toggleFilterButton);
const allFilterOptions = getAllByTestId('dataStreams-filter-option');
for (let i = 0; i < allFilterOptions.length - 1; i++) {
// deselect 9 options
for (let i = 0; i < allFilterOptions.length; i++) {
await user.click(allFilterOptions[i]);
}

expect(toggleFilterButton).toHaveTextContent('Data streams1');
expect(within(toggleFilterButton).getByRole('marquee').getAttribute('aria-label')).toEqual(
'1 active filters'
);
});

it('should allow selecting/deselecting all data stream options using `select all` and `clear all`', async () => {
mockUseGetDataUsageDataStreams.mockReturnValue({
error: undefined,
data: generateDataStreams(10),
isFetching: false,
});
const { getByTestId } = renderComponent();
const toggleFilterButton = getByTestId(`${testIdFilter}-dataStreams-popoverButton`);

expect(toggleFilterButton).toHaveTextContent('Data streams10');
await user.click(toggleFilterButton);

// all options are selected on load
expect(within(toggleFilterButton).getByRole('marquee').getAttribute('aria-label')).toEqual(
'10 active filters'
);

const selectAllButton = getByTestId(`${testIdFilter}-dataStreams-selectAllButton`);
const clearAllButton = getByTestId(`${testIdFilter}-dataStreams-clearAllButton`);

// select all is disabled
expect(selectAllButton).toBeTruthy();
expect(selectAllButton.getAttribute('disabled')).not.toBeNull();

// clear all is enabled
expect(clearAllButton).toBeTruthy();
expect(clearAllButton.getAttribute('disabled')).toBeNull();
// click clear all and expect all options to be deselected
await user.click(clearAllButton);
expect(within(toggleFilterButton).getByRole('marquee').getAttribute('aria-label')).toEqual(
'10 available filters'
);
// select all is enabled again
expect(await selectAllButton.getAttribute('disabled')).toBeNull();
// click select all
await user.click(selectAllButton);

// all options are selected and clear all is disabled
expect(within(toggleFilterButton).getByRole('marquee').getAttribute('aria-label')).toEqual(
'10 active filters'
);
});

it('should not call usage metrics API if no data streams', async () => {
mockUseGetDataUsageDataStreams.mockReturnValue({
...getBaseMockedDataStreams,
data: [],
});
render(<DataUsageMetrics data-test-subj={testId} />);
renderComponent();
expect(mockUseGetDataUsageMetrics).toHaveBeenCalledWith(
expect.any(Object),
expect.objectContaining({ enabled: false })
Expand All @@ -259,7 +299,7 @@ describe('DataUsageMetrics', () => {
...getBaseMockedDataUsageMetrics,
isFetching: true,
});
const { getByTestId } = render(<DataUsageMetrics data-test-subj={testId} />);
const { getByTestId } = renderComponent();
expect(getByTestId(`${testId}-charts-loading`)).toBeTruthy();
});

Expand Down Expand Up @@ -290,10 +330,19 @@ describe('DataUsageMetrics', () => {
],
},
});
const { getByTestId } = render(<DataUsageMetrics data-test-subj={testId} />);
const { getByTestId } = renderComponent();
expect(getByTestId(`${testId}-charts`)).toBeTruthy();
});

it('should show no charts callout', () => {
mockUseGetDataUsageMetrics.mockReturnValue({
...getBaseMockedDataUsageMetrics,
isFetched: false,
});
const { getByTestId } = renderComponent();
expect(getByTestId(`${testId}-no-charts-callout`)).toBeTruthy();
});

it('should refetch usage metrics with `Refresh` button click', async () => {
const refetch = jest.fn();
mockUseGetDataUsageMetrics.mockReturnValue({
Expand All @@ -306,7 +355,7 @@ describe('DataUsageMetrics', () => {
isFetched: true,
refetch,
});
const { getByTestId } = render(<DataUsageMetrics data-test-subj={testId} />);
const { getByTestId } = renderComponent();
const refreshButton = getByTestId(`${testIdFilter}-super-refresh-button`);
// click refresh 5 times
for (let i = 0; i < 5; i++) {
Expand All @@ -326,7 +375,7 @@ describe('DataUsageMetrics', () => {
isFetched: true,
error: new Error('Uh oh!'),
});
render(<DataUsageMetrics data-test-subj={testId} />);
renderComponent();
await waitFor(() => {
expect(mockServices.notifications.toasts.addDanger).toHaveBeenCalledWith({
title: 'Error getting usage metrics',
Expand All @@ -341,7 +390,7 @@ describe('DataUsageMetrics', () => {
isFetched: true,
error: new Error('Uh oh!'),
});
render(<DataUsageMetrics data-test-subj={testId} />);
renderComponent();
await waitFor(() => {
expect(mockServices.notifications.toasts.addDanger).toHaveBeenCalledWith({
title: 'Error getting data streams',
Expand Down
Loading

0 comments on commit 59eb481

Please sign in to comment.