Skip to content

Commit

Permalink
[data] Clean up QueryStringInput unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DianaDerevyankina committed Feb 28, 2020
1 parent 2b9dc43 commit fc36c1f
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 4,537 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { QueryLanguageSwitcher } from './language_switcher';
import { KibanaContextProvider } from 'src/plugins/kibana_react/public';
import { coreMock } from '../../../../../core/public/mocks';
import { mountWithIntl } from 'test_utils/enzyme_helpers';
import { EuiButtonEmpty, EuiPopover } from '@elastic/eui';
const startMock = coreMock.createStart();

describe('LanguageSwitcher', () => {
Expand All @@ -47,8 +48,9 @@ describe('LanguageSwitcher', () => {
},
})
);

expect(component).toMatchSnapshot();
component.find(EuiButtonEmpty).simulate('click');
expect(component.find(EuiPopover).prop('isOpen')).toBe(true);
expect(component.find('[data-test-subj="languageToggle"]').get(0).props.checked).toBeFalsy();
});

it('should toggle on if language is kuery', () => {
Expand All @@ -60,7 +62,8 @@ describe('LanguageSwitcher', () => {
},
})
);

expect(component).toMatchSnapshot();
component.find(EuiButtonEmpty).simulate('click');
expect(component.find(EuiPopover).prop('isOpen')).toBe(true);
expect(component.find('[data-test-subj="languageToggle"]').get(0).props.checked).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function wrapQueryBarTopRowInContext(testProps: any) {
return (
<I18nProvider>
<KibanaContextProvider services={services}>
<QueryBarTopRow.WrappedComponent {...defaultOptions} {...testProps} />
<QueryBarTopRow {...defaultOptions} {...testProps} />
</KibanaContextProvider>
</I18nProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import dateMath from '@elastic/datemath';
import classNames from 'classnames';
import React, { useState } from 'react';
import { i18n } from '@kbn/i18n';

import {
EuiButton,
EuiFlexGroup,
Expand All @@ -31,7 +33,7 @@ import {
} from '@elastic/eui';
// @ts-ignore
import { EuiSuperUpdateButton, OnRefreshProps } from '@elastic/eui';
import { FormattedMessage, InjectedIntl, injectI18n } from '@kbn/i18n/react';
import { FormattedMessage } from '@kbn/i18n/react';
import { Toast } from 'src/core/public';
import { IDataPluginServices, IIndexPattern, TimeRange, TimeHistoryContract, Query } from '../..';
import { useKibana, toMountPoint } from '../../../../kibana_react/public';
Expand All @@ -48,7 +50,6 @@ interface Props {
disableAutoFocus?: boolean;
screenTitle?: string;
indexPatterns?: Array<IIndexPattern | string>;
intl: InjectedIntl;
isLoading?: boolean;
prepend?: React.ComponentProps<typeof EuiFieldText>['prepend'];
showQueryInput?: boolean;
Expand All @@ -64,7 +65,7 @@ interface Props {
timeHistory?: TimeHistoryContract;
}

function QueryBarTopRowUI(props: Props) {
export function QueryBarTopRow(props: Props) {
const [isDateRangeInvalid, setIsDateRangeInvalid] = useState(false);

const kibana = useKibana<IDataPluginServices>();
Expand Down Expand Up @@ -285,7 +286,6 @@ function QueryBarTopRowUI(props: Props) {

function handleLuceneSyntaxWarning() {
if (!props.query) return;
const { intl } = props;
const { query, language } = props.query;
if (
language === 'kuery' &&
Expand All @@ -294,8 +294,7 @@ function QueryBarTopRowUI(props: Props) {
doesKueryExpressionHaveLuceneSyntaxError(query)
) {
const toast = notifications!.toasts.addWarning({
title: intl.formatMessage({
id: 'data.query.queryBar.luceneSyntaxWarningTitle',
title: i18n.translate('data.query.queryBar.luceneSyntaxWarningTitle', {
defaultMessage: 'Lucene syntax warning',
}),
text: toMountPoint(
Expand Down Expand Up @@ -357,10 +356,8 @@ function QueryBarTopRowUI(props: Props) {
);
}

QueryBarTopRowUI.defaultProps = {
QueryBarTopRow.defaultProps = {
showQueryInput: true,
showDatePicker: true,
showAutoRefreshOnly: false,
};

export const QueryBarTopRow = injectI18n(QueryBarTopRowUI);
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ describe('QueryStringInput', () => {
indexPatterns: [stubIndexPatternWithFields],
})
);

expect(component).toMatchSnapshot();
expect(component.find(EuiFieldText).props().value).toBe(kqlQuery.query);
expect(component.find(QueryLanguageSwitcher).prop('language')).toBe(kqlQuery.language);
});

it('Should pass the query language to the language switcher', () => {
Expand All @@ -114,8 +114,7 @@ describe('QueryStringInput', () => {
indexPatterns: [stubIndexPatternWithFields],
})
);

expect(component).toMatchSnapshot();
expect(component.find(QueryLanguageSwitcher).prop('language')).toBe(luceneQuery.language);
});

it('Should disable autoFocus on EuiFieldText when disableAutoFocus prop is true', () => {
Expand All @@ -127,8 +126,7 @@ describe('QueryStringInput', () => {
disableAutoFocus: true,
})
);

expect(component).toMatchSnapshot();
expect(component.find(EuiFieldText).prop('autoFocus')).toBeFalsy();
});

it('Should create a unique PersistedLog based on the appName and query language', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
EuiLink,
} from '@elastic/eui';

import { InjectedIntl, injectI18n, FormattedMessage } from '@kbn/i18n/react';
import { FormattedMessage } from '@kbn/i18n/react';
import { debounce, compact, isEqual } from 'lodash';
import { Toast } from 'src/core/public';
import { IDataPluginServices, IIndexPattern, SuggestionsComponent, Query } from '../..';
Expand All @@ -44,7 +44,6 @@ import { PersistedLog, getQueryLog, matchPairs, toUser, fromUser } from '../../q

interface Props {
kibana: KibanaReactContextValue<IDataPluginServices>;
intl: InjectedIntl;
indexPatterns: Array<IIndexPattern | string>;
query: Query;
disableAutoFocus?: boolean;
Expand Down Expand Up @@ -356,8 +355,7 @@ export class QueryStringInputUI extends Component<Props, State> {

if (notifications && docLinks) {
const toast = notifications.toasts.add({
title: this.props.intl.formatMessage({
id: 'data.query.queryBar.KQLNestedQuerySyntaxInfoTitle',
title: i18n.translate('data.query.queryBar.KQLNestedQuerySyntaxInfoTitle', {
defaultMessage: 'KQL nested query syntax',
}),
text: toMountPoint(
Expand Down Expand Up @@ -584,4 +582,4 @@ export class QueryStringInputUI extends Component<Props, State> {
}
}

export const QueryStringInput = injectI18n(withKibana(QueryStringInputUI));
export const QueryStringInput = withKibana(QueryStringInputUI);

0 comments on commit fc36c1f

Please sign in to comment.