Skip to content
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

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import numeral from '@elastic/numeral';
import { render, screen, waitFor, within } from '@testing-library/react';
import { render, screen, waitFor } from '@testing-library/react';
import React from 'react';

import { EMPTY_STAT } from '../../constants';
Expand All @@ -22,8 +22,6 @@ import {
} from '../../mock/test_providers/test_providers';
import { PatternRollup } from '../../types';
import { Props, IndicesDetails } from '.';
import userEvent from '@testing-library/user-event';
import { HISTORICAL_RESULTS_TOUR_IS_DISMISSED_STORAGE_KEY } from './constants';

const defaultBytesFormat = '0,0.[0]b';
const formatBytes = (value: number | undefined) =>
Expand Down Expand Up @@ -70,7 +68,6 @@ const defaultProps: Props = {
describe('IndicesDetails', () => {
beforeEach(async () => {
jest.clearAllMocks();
localStorage.removeItem(HISTORICAL_RESULTS_TOUR_IS_DISMISSED_STORAGE_KEY);

render(
<TestExternalProviders>
Expand All @@ -91,55 +88,4 @@ describe('IndicesDetails', () => {
expect(screen.getByTestId(`${pattern}PatternPanel`)).toBeInTheDocument();
});
});

describe('tour', () => {
test('it renders the tour wrapping view history button of first row of first non-empty pattern', async () => {
const wrapper = await screen.findByTestId('historicalResultsTour');
const button = within(wrapper).getByTestId(
'viewHistoryAction-.internal.alerts-security.alerts-default-000001'
);
expect(button).toHaveAttribute('data-tour-element', patterns[1]);

expect(screen.getByTestId('historicalResultsTourPanel')).toHaveTextContent(
'Introducing data quality history'
);
});

describe('when the tour is dismissed', () => {
test('it hides the tour and persists in localStorage', async () => {
const wrapper = screen.getByTestId('historicalResultsTourPanel');
const button = within(wrapper).getByText('Close');
await userEvent.click(button);

await waitFor(() => expect(screen.queryByTestId('historicalResultsTour')).toBeNull());

expect(localStorage.getItem(HISTORICAL_RESULTS_TOUR_IS_DISMISSED_STORAGE_KEY)).toEqual(
'true'
);
});
});

describe('when the first pattern is toggled', () => {
test('it renders the tour wrapping view history button of first row of second non-empty pattern', async () => {
const firstNonEmptyPatternAccordionWrapper = await screen.findByTestId(
`${patterns[1]}PatternPanel`
);
const accordionToggle = within(firstNonEmptyPatternAccordionWrapper).getByTestId(
'indexResultBadge'
);
await userEvent.click(accordionToggle);

const secondPatternAccordionWrapper = screen.getByTestId(`${patterns[2]}PatternPanel`);
const historicalResultsWrapper = await within(secondPatternAccordionWrapper).findByTestId(
'historicalResultsTour'
);
const button = within(historicalResultsWrapper).getByTestId(
`viewHistoryAction-${patternIndexNames[patterns[2]][0]}`
);
expect(button).toHaveAttribute('data-tour-element', patterns[2]);

expect(screen.getByTestId('historicalResultsTourPanel')).toBeInTheDocument();
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
* 2.0.
*/

import React from 'react';
import { EuiFlexItem } from '@elastic/eui';
import React, { useState, useCallback, useEffect } from 'react';
import styled from 'styled-components';

import { useResultsRollupContext } from '../../contexts/results_rollup_context';
import { Pattern } from './pattern';
import { SelectedIndex } from '../../types';
import { useDataQualityContext } from '../../data_quality_context';
import { useIsHistoricalResultsTourActive } from './hooks/use_is_historical_results_tour_active';

const StyledPatternWrapperFlexItem = styled(EuiFlexItem)`
margin-bottom: ${({ theme }) => theme.eui.euiSize};
Expand All @@ -35,41 +34,6 @@ const IndicesDetailsComponent: React.FC<Props> = ({
const { patternRollups, patternIndexNames } = useResultsRollupContext();
const { patterns } = useDataQualityContext();

const [isTourActive, setIsTourActive] = useIsHistoricalResultsTourActive();

const handleDismissTour = useCallback(() => {
setIsTourActive(false);
}, [setIsTourActive]);

const [openPatterns, setOpenPatterns] = useState<
Array<{ name: string; isOpen: boolean; isEmpty: boolean }>
>(() => {
return patterns.map((pattern) => ({ name: pattern, isOpen: true, isEmpty: false }));
});

const handleAccordionToggle = useCallback(
(patternName: string, isOpen: boolean, isEmpty: boolean) => {
setOpenPatterns((prevOpenPatterns) => {
return prevOpenPatterns.map((p) =>
p.name === patternName ? { ...p, isOpen, isEmpty } : p
);
});
},
[]
);

const firstOpenNonEmptyPattern = openPatterns.find((pattern) => {
return pattern.isOpen && !pattern.isEmpty;
})?.name;

const [openPatternsUpdatedAt, setOpenPatternsUpdatedAt] = useState<number>(Date.now());

useEffect(() => {
if (firstOpenNonEmptyPattern) {
setOpenPatternsUpdatedAt(Date.now());
}
}, [openPatterns, firstOpenNonEmptyPattern]);

return (
<div data-test-subj="indicesDetails">
{patterns.map((pattern) => (
Expand All @@ -80,16 +44,6 @@ const IndicesDetailsComponent: React.FC<Props> = ({
patternRollup={patternRollups[pattern]}
chartSelectedIndex={chartSelectedIndex}
setChartSelectedIndex={setChartSelectedIndex}
isTourActive={isTourActive}
isFirstOpenNonEmptyPattern={pattern === firstOpenNonEmptyPattern}
onAccordionToggle={handleAccordionToggle}
onDismissTour={handleDismissTour}
// TODO: remove this hack when EUI popover is fixed
// https://github.com/elastic/eui/issues/5226
//
// this information is used to force the tour guide popover to reposition
// when surrounding accordions get toggled and affect the layout
{...(pattern === firstOpenNonEmptyPattern && { openPatternsUpdatedAt })}
/>
</StyledPatternWrapperFlexItem>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ export const MIN_PAGE_SIZE = 10;

export const HISTORY_TAB_ID = 'history';
export const LATEST_CHECK_TAB_ID = 'latest_check';

export const HISTORICAL_RESULTS_TOUR_SELECTOR_KEY = 'data-tour-element';

This file was deleted.

This file was deleted.

Loading