Skip to content

Commit

Permalink
fix: rollback test
Browse files Browse the repository at this point in the history
  • Loading branch information
nlatipov committed May 17, 2022
1 parent a7aab00 commit 1572e5d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
*/

import { IUiSettingsClient, CoreSetup } from '@kbn/core/public';
import { stubFields } from '@kbn/data-views-plugin/common/stubs';
import { stubDataView } from '@kbn/data-views-plugin/common/data_view.stub';
import { stubIndexPattern, stubFields } from '@kbn/data-plugin/public/stubs';
import type { TimefilterSetup } from '@kbn/data-plugin/public';
import { UI_SETTINGS } from '@kbn/data-plugin/common';
import { setupValueSuggestionProvider } from './value_suggestion_provider';
Expand Down Expand Up @@ -49,7 +48,7 @@ describe('FieldSuggestions', () => {

it('should return an empty array', async () => {
const suggestions = await getValueSuggestions({
indexPattern: stubDataView,
indexPattern: stubIndexPattern,
field: stubFields[0],
query: '',
});
Expand All @@ -65,7 +64,7 @@ describe('FieldSuggestions', () => {
it('should return true/false for boolean fields', async () => {
const [field] = stubFields.filter(({ type }) => type === 'boolean');
const suggestions = await getValueSuggestions({
indexPattern: stubDataView,
indexPattern: stubIndexPattern,
field,
query: '',
});
Expand All @@ -77,7 +76,7 @@ describe('FieldSuggestions', () => {
it('should return an empty array if the field type is not a string or boolean', async () => {
const [field] = stubFields.filter(({ type }) => type !== 'string' && type !== 'boolean');
const suggestions = await getValueSuggestions({
indexPattern: stubDataView,
indexPattern: stubIndexPattern,
field,
query: '',
});
Expand All @@ -89,7 +88,7 @@ describe('FieldSuggestions', () => {
it('should return an empty array if the field is not aggregatable', async () => {
const [field] = stubFields.filter(({ aggregatable }) => !aggregatable);
const suggestions = await getValueSuggestions({
indexPattern: stubDataView,
indexPattern: stubIndexPattern,
field,
query: '',
});
Expand All @@ -104,7 +103,7 @@ describe('FieldSuggestions', () => {
);

await getValueSuggestions({
indexPattern: stubDataView,
indexPattern: stubIndexPattern,
field,
query: '',
useTimeRange: false,
Expand All @@ -118,7 +117,7 @@ describe('FieldSuggestions', () => {
({ type, aggregatable }) => type === 'string' && aggregatable
);
const args = {
indexPattern: stubDataView,
indexPattern: stubIndexPattern,
field,
query: '',
useTimeRange: false,
Expand All @@ -135,7 +134,7 @@ describe('FieldSuggestions', () => {
({ type, aggregatable }) => type === 'string' && aggregatable
);
const args = {
indexPattern: stubDataView,
indexPattern: stubIndexPattern,
field,
query: '',
useTimeRange: false,
Expand All @@ -159,34 +158,35 @@ describe('FieldSuggestions', () => {
);

await getValueSuggestions({
indexPattern: stubDataView,
indexPattern: stubIndexPattern,
field: fields[0],
query: '',
useTimeRange: false,
});
await getValueSuggestions({
indexPattern: stubDataView,
indexPattern: stubIndexPattern,
field: fields[0],
query: 'query',
useTimeRange: false,
});
await getValueSuggestions({
indexPattern: stubDataView,
indexPattern: stubIndexPattern,
field: fields[1],
query: '',
useTimeRange: false,
});
await getValueSuggestions({
indexPattern: stubDataView,
indexPattern: stubIndexPattern,
field: fields[1],
query: 'query',
useTimeRange: false,
});

const customIndexPattern = Object.assign({}, stubDataView, {
const customIndexPattern = {
...stubIndexPattern,
title: 'customIndexPattern',
useTimeRange: false,
});
};

await getValueSuggestions({
indexPattern: customIndexPattern,
Expand Down Expand Up @@ -222,7 +222,7 @@ describe('FieldSuggestions', () => {
);

await getValueSuggestions({
indexPattern: stubDataView,
indexPattern: stubIndexPattern,
field,
query: '',
useTimeRange: true,
Expand All @@ -243,7 +243,7 @@ describe('FieldSuggestions', () => {
);

await getValueSuggestions({
indexPattern: stubDataView,
indexPattern: stubIndexPattern,
field,
query: '',
useTimeRange: true,
Expand All @@ -263,7 +263,7 @@ describe('FieldSuggestions', () => {
);

await getValueSuggestions({
indexPattern: stubDataView,
indexPattern: stubIndexPattern,
field,
query: '',
useTimeRange: true,
Expand All @@ -283,7 +283,7 @@ describe('FieldSuggestions', () => {
);

await getValueSuggestions({
indexPattern: stubDataView,
indexPattern: stubIndexPattern,
field,
query: '',
useTimeRange: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import {
phraseFilter,
phrasesFilter,
rangeFilter,
stubIndexPattern,
stubFields,
} from '@kbn/data-plugin/common/stubs';
import { stubDataView } from '@kbn/data-views-plugin/common/data_view.stub';
import { stubFields } from '@kbn/data-views-plugin/common/stubs';

import { toggleFilterNegated } from '@kbn/es-query';
import { toggleFilterNegated } from '@kbn/data-plugin/common';
import {
getFieldFromFilter,
getFilterableFields,
Expand All @@ -29,7 +28,7 @@ import { existsOperator, isBetweenOperator, isOneOfOperator, isOperator } from '
describe('Filter editor utils', () => {
describe('getFieldFromFilter', () => {
it('should return the field from the filter', () => {
const field = getFieldFromFilter(phraseFilter, stubDataView);
const field = getFieldFromFilter(phraseFilter, stubIndexPattern);
expect(field).not.toBeUndefined();
expect(field && field.name).toBe(phraseFilter.meta.key);
});
Expand Down Expand Up @@ -99,12 +98,12 @@ describe('Filter editor utils', () => {

describe('getFilterableFields', () => {
it('returns the list of fields from the given index pattern', () => {
const fieldOptions = getFilterableFields(stubDataView);
const fieldOptions = getFilterableFields(stubIndexPattern);
expect(fieldOptions.length).toBeGreaterThan(0);
});

it('limits the fields to the filterable fields', () => {
const fieldOptions = getFilterableFields(stubDataView);
const fieldOptions = getFilterableFields(stubIndexPattern);
const nonFilterableFields = fieldOptions.filter((field) => !field.filterable);
expect(nonFilterableFields.length).toBe(0);
});
Expand Down Expand Up @@ -140,63 +139,63 @@ describe('Filter editor utils', () => {
});

it('should return false if field is not provided', () => {
const isValid = isFilterValid(stubDataView, undefined, isOperator, 'foo');
const isValid = isFilterValid(stubIndexPattern, undefined, isOperator, 'foo');
expect(isValid).toBe(false);
});

it('should return false if operator is not provided', () => {
const isValid = isFilterValid(stubDataView, stubFields[0], undefined, 'foo');
const isValid = isFilterValid(stubIndexPattern, stubFields[0], undefined, 'foo');
expect(isValid).toBe(false);
});

it('should return false for phrases filter without phrases', () => {
const isValid = isFilterValid(stubDataView, stubFields[0], isOneOfOperator, []);
const isValid = isFilterValid(stubIndexPattern, stubFields[0], isOneOfOperator, []);
expect(isValid).toBe(false);
});

it('should return true for phrases filter with phrases', () => {
const isValid = isFilterValid(stubDataView, stubFields[0], isOneOfOperator, ['foo']);
const isValid = isFilterValid(stubIndexPattern, stubFields[0], isOneOfOperator, ['foo']);
expect(isValid).toBe(true);
});

it('should return false for range filter without range', () => {
const isValid = isFilterValid(stubDataView, stubFields[0], isBetweenOperator, undefined);
const isValid = isFilterValid(stubIndexPattern, stubFields[0], isBetweenOperator, undefined);
expect(isValid).toBe(false);
});

it('should return true for range filter with from', () => {
const isValid = isFilterValid(stubDataView, stubFields[0], isBetweenOperator, {
const isValid = isFilterValid(stubIndexPattern, stubFields[0], isBetweenOperator, {
from: 'foo',
});
expect(isValid).toBe(true);
});

it('should return true for range filter with from/to', () => {
const isValid = isFilterValid(stubDataView, stubFields[0], isBetweenOperator, {
const isValid = isFilterValid(stubIndexPattern, stubFields[0], isBetweenOperator, {
from: 'foo',
to: 'goo',
});
expect(isValid).toBe(true);
});

it('should return false for date range filter with bad from', () => {
const isValid = isFilterValid(stubDataView, stubFields[4], isBetweenOperator, {
const isValid = isFilterValid(stubIndexPattern, stubFields[4], isBetweenOperator, {
from: 'foo',
to: 'now',
});
expect(isValid).toBe(false);
});

it('should return false for date range filter with bad to', () => {
const isValid = isFilterValid(stubDataView, stubFields[4], isBetweenOperator, {
const isValid = isFilterValid(stubIndexPattern, stubFields[4], isBetweenOperator, {
from: '2020-01-01',
to: 'mau',
});
expect(isValid).toBe(false);
});

it('should return true for exists filter without params', () => {
const isValid = isFilterValid(stubDataView, stubFields[0], existsOperator);
const isValid = isFilterValid(stubIndexPattern, stubFields[0], existsOperator);
expect(isValid).toBe(true);
});
});
Expand Down
Loading

0 comments on commit 1572e5d

Please sign in to comment.