diff --git a/public/app/features/explore/ExploreToolbar.test.tsx b/public/app/features/explore/ExploreToolbar.test.tsx new file mode 100644 index 00000000000..00e89983c03 --- /dev/null +++ b/public/app/features/explore/ExploreToolbar.test.tsx @@ -0,0 +1,68 @@ +import React from 'react'; +import { shallow, ShallowWrapper } from 'enzyme'; +import { UnConnectedExploreToolbar } from './ExploreToolbar'; +import { ExploreMode } from '@grafana/data'; +import { ExploreId } from '../../types'; +import { ToggleButtonGroup } from '@grafana/ui'; + +jest.mock('./state/selectors', () => { + return { + __esModule: true, + getExploreDatasources: () => [] as any, + }; +}); + +describe('ExploreToolbar', () => { + it('displays correct modes', () => { + let wrapper = shallow(createToolbar([ExploreMode.Tracing, ExploreMode.Logs])); + checkModes(wrapper, ['Logs', 'Tracing']); + + wrapper = shallow(createToolbar([ExploreMode.Logs])); + checkModes(wrapper, []); + + wrapper = shallow(createToolbar([ExploreMode.Logs, ExploreMode.Tracing, ExploreMode.Metrics])); + checkModes(wrapper, ['Metrics', 'Logs', 'Tracing']); + }); +}); + +function checkModes(wrapper: ShallowWrapper, modes: string[]) { + expect( + wrapper + .find(ToggleButtonGroup) + .children() + .map(node => node.children().text()) + ).toEqual(modes); +} + +function createToolbar(supportedModes: ExploreMode[]) { + return ( + {}) as any} + clearAll={(() => {}) as any} + cancelQueries={(() => {}) as any} + runQueries={(() => {}) as any} + closeSplit={(() => {}) as any} + split={(() => {}) as any} + syncTimes={(() => {}) as any} + changeRefreshInterval={(() => {}) as any} + changeMode={(() => {}) as any} + updateLocation={(() => {}) as any} + setDashboardQueriesToUpdateOnLoad={(() => {}) as any} + exploreId={ExploreId.left} + onChangeTime={(() => {}) as any} + /> + ); +} diff --git a/public/app/features/explore/ExploreToolbar.tsx b/public/app/features/explore/ExploreToolbar.tsx index 2698a570e87..ef6358a9d12 100644 --- a/public/app/features/explore/ExploreToolbar.tsx +++ b/public/app/features/explore/ExploreToolbar.tsx @@ -6,21 +6,20 @@ import classNames from 'classnames'; import { css } from 'emotion'; import { ExploreId, ExploreItemState } from 'app/types/explore'; -import { ToggleButtonGroup, ToggleButton, Tooltip, LegacyForms, SetInterval, Icon, IconButton } from '@grafana/ui'; -const { ButtonSelect } = LegacyForms; -import { RawTimeRange, TimeZone, TimeRange, DataQuery, ExploreMode } from '@grafana/data'; +import { Icon, IconButton, LegacyForms, SetInterval, ToggleButton, ToggleButtonGroup, Tooltip } from '@grafana/ui'; +import { DataQuery, ExploreMode, RawTimeRange, TimeRange, TimeZone } from '@grafana/data'; import { DataSourcePicker } from 'app/core/components/Select/DataSourcePicker'; import { StoreState } from 'app/types/store'; import { - changeDatasource, cancelQueries, + changeDatasource, + changeMode, + changeRefreshInterval, clearQueries, - splitClose, runQueries, + splitClose, splitOpen, syncTimes, - changeRefreshInterval, - changeMode, } from './state/actions'; import { updateLocation } from 'app/core/actions'; import { getTimeZone } from '../profile/state/selectors'; @@ -34,6 +33,8 @@ import { LiveTailControls } from './useLiveTailControls'; import { getExploreDatasources } from './state/selectors'; import { setDashboardQueriesToUpdateOnLoad } from '../dashboard/state/reducers'; +const { ButtonSelect } = LegacyForms; + const getStyles = memoizeOne(() => { return { liveTailButtons: css` @@ -238,22 +239,20 @@ export class UnConnectedExploreToolbar extends PureComponent { {showModeToggle ? (
- - {'Metrics'} - - - {'Logs'} - + {[ExploreMode.Metrics, ExploreMode.Logs, ExploreMode.Tracing] + .filter(mode => supportedModes.includes(mode)) + .map(mode => { + return ( + + {mode} + + ); + })}
) : null}