Skip to content

Commit

Permalink
Fix functional test
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal committed Feb 2, 2021
1 parent d6796fc commit 4e4637f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
18 changes: 11 additions & 7 deletions src/plugins/discover/public/application/components/discover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import './discover.scss';
import React, { useState, useRef } from 'react';
import React, { useState, useRef, useMemo, useCallback } from 'react';
import {
EuiButtonEmpty,
EuiButtonIcon,
Expand Down Expand Up @@ -87,8 +87,12 @@ export function Discover({
// collapse icon isn't displayed in mobile view, use it to detect which view is displayed
return collapseIcon && !collapseIcon.current;
};
const toggleHideChart = useCallback(() => {
const newState = { ...state, hideChart: !state.hideChart };
opts.stateContainer.setAppState(newState);
}, [state, opts]);
const hideChart = useMemo(() => state.hideChart, [state]);

const [toggleOn, toggleChart] = useState(true);
const [isSidebarClosed, setIsSidebarClosed] = useState(false);
const services = getServices();
const { TopNavMenu } = services.navigation.ui;
Expand Down Expand Up @@ -198,7 +202,7 @@ export function Discover({
onResetQuery={resetQuery}
/>
</EuiFlexItem>
{toggleOn && (
{!hideChart && (
<EuiFlexItem className="dscResultCount__actions">
<TimechartHeader
dateFormat={opts.config.get('dateFormat')}
Expand All @@ -214,13 +218,13 @@ export function Discover({
<EuiFlexItem className="dscResultCount__toggle" grow={false}>
<EuiButtonEmpty
size="xs"
iconType={toggleOn ? 'eyeClosed' : 'eye'}
iconType={!hideChart ? 'eyeClosed' : 'eye'}
onClick={() => {
toggleChart(!toggleOn);
toggleHideChart();
}}
data-test-subj="discoverChartToggle"
>
{toggleOn
{!hideChart
? i18n.translate('discover.hideChart', {
defaultMessage: 'Hide chart',
})
Expand All @@ -233,7 +237,7 @@ export function Discover({
</EuiFlexGroup>
{isLegacy && <SkipBottomButton onClick={onSkipBottomButtonClick} />}
</EuiFlexItem>
{toggleOn && opts.timefield && (
{!hideChart && opts.timefield && (
<EuiFlexItem grow={false}>
<section
aria-label={i18n.translate(
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/discover/public/application/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
TimeRange,
} from '../../../../data/public';
import { SavedSearch } from '../../saved_searches';
import { AppState } from '../angular/discover_state';
import { AppState, GetStateReturn } from '../angular/discover_state';
import { TopNavMenuData } from '../../../../navigation/public';

export interface DiscoverProps {
Expand Down Expand Up @@ -131,6 +131,10 @@ export interface DiscoverProps {
* Function to set the current state
*/
setAppState: (state: Partial<AppState>) => void;
/**
* State container providing globalState, appState and functions
*/
stateContainer: GetStateReturn;
};
/**
* Function to reset the current query
Expand Down
8 changes: 6 additions & 2 deletions test/functional/apps/discover/_discover_histogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const chartIntervalIconTip = await PageObjects.discover.getChartIntervalWarningIcon();
expect(chartIntervalIconTip).to.be(true);
});
it('should allow hide/show histogram, persisted in url state', async () => {
it('1234 should allow hide/show histogram, persisted in url state', async () => {
const fromTime = 'Jan 01, 2010 @ 00:00:00.000';
const toTime = 'Mar 21, 2019 @ 00:00:00.000';
await prepareTest(fromTime, toTime);
Expand All @@ -84,9 +84,10 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(canvasExists).to.be(false);
await testSubjects.click('discoverChartToggle');
await PageObjects.header.waitUntilLoadingHasFinished();
canvasExists = await elasticChart.canvasExists();
expect(canvasExists).to.be(true);
});
it('should allow hiding the histogram, persisted in saved search', async () => {
it('1234 should allow hiding the histogram, persisted in saved search', async () => {
const fromTime = 'Jan 01, 2010 @ 00:00:00.000';
const toTime = 'Mar 21, 2019 @ 00:00:00.000';
const savedSearch = 'persisted hidden histogram';
Expand All @@ -96,10 +97,13 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(canvasExists).to.be(false);
await PageObjects.discover.saveSearch(savedSearch);
await PageObjects.header.waitUntilLoadingHasFinished();
canvasExists = await elasticChart.canvasExists();
expect(canvasExists).to.be(false);
await testSubjects.click('discoverChartToggle');
canvasExists = await elasticChart.canvasExists();
expect(canvasExists).to.be(true);
await PageObjects.discover.clickResetSavedSearchButton();
await PageObjects.header.waitUntilLoadingHasFinished();
canvasExists = await elasticChart.canvasExists();
expect(canvasExists).to.be(false);
});
Expand Down

0 comments on commit 4e4637f

Please sign in to comment.