Skip to content

Commit

Permalink
✅ Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dej611 committed Dec 21, 2023
1 parent 0b2e30b commit bfc66f0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { parse } from '@kbn/tinymath';
import { monaco } from '@kbn/monaco';
import { unifiedSearchPluginMock } from '@kbn/unified-search-plugin/public/mocks';
import { dataViewPluginMocks } from '@kbn/data-views-plugin/public/mocks';
import { tinymathFunctions } from '@kbn/lens-formula-docs';
import { createMockedIndexPattern } from '../../../../mocks';
import { GenericOperationDefinition } from '../..';
import type { OperationMetadata, IndexPatternField } from '../../../../../../types';
import { tinymathFunctions } from '../util';
import {
getSignatureHelp,
getHover,
Expand Down Expand Up @@ -48,11 +48,6 @@ const operationDefinitionMap: Record<string, GenericOperationDefinition> = {
getPossibleOperationForField: jest.fn((field: IndexPatternField) =>
field.type === 'number' ? numericOperation() : undefined
),
documentation: {
section: 'elasticsearch',
signature: 'field: string',
description: 'description',
},
}),
count: createOperationDefinitionMock('count', {
getPossibleOperationForField: (field: IndexPatternField) =>
Expand Down Expand Up @@ -93,7 +88,7 @@ const operationDefinitionMap: Record<string, GenericOperationDefinition> = {
),
};

describe('math completion', () => {
describe('[Lens formula] math completion', () => {
describe('signature help', () => {
function unwrapSignatures(signatureResult: monaco.languages.SignatureHelpResult) {
return signatureResult.value.signatures[0];
Expand All @@ -106,15 +101,21 @@ describe('math completion', () => {
it('should return a signature for a field-based ES function', () => {
expect(unwrapSignatures(getSignatureHelp('sum()', 4, operationDefinitionMap))).toEqual({
label: 'sum(field: string)',
documentation: { value: 'description' },
documentation: {
value: `
Returns the sum of a field. This function only works for number fields.`,
},
parameters: [{ label: 'field' }],
});
});

it('should return a signature for count', () => {
expect(unwrapSignatures(getSignatureHelp('count()', 6, operationDefinitionMap))).toEqual({
label: 'count(undefined)',
documentation: { value: '' },
label: 'count([field: string])',
documentation: {
value: `
The total number of documents. When you provide a field, the total number of field values is counted. When you use the Count function for fields that have multiple values in a single document, all values are counted.`,
},
parameters: [],
});
});
Expand All @@ -126,7 +127,11 @@ describe('math completion', () => {
)
).toEqual({
label: expect.stringContaining('moving_average('),
documentation: { value: '' },
documentation: {
value: `
Calculates the moving average of a metric over time, averaging the last n-th values to calculate the current value. To use this function, you need to configure a date histogram dimension as well.
The default window value is 5.`,
},
parameters: [
{ label: 'function' },
{
Expand All @@ -145,7 +150,10 @@ describe('math completion', () => {
).toEqual({
label: expect.stringContaining('count('),
parameters: [],
documentation: { value: '' },
documentation: {
value: `
The total number of documents. When you provide a field, the total number of field values is counted. When you use the Count function for fields that have multiple values in a single document, all values are counted.`,
},
});
});

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

import { tinymathFunctions } from '@kbn/lens-formula-docs';
import { createMockedIndexPattern } from '../../../mocks';
import {
formulaOperation,
Expand All @@ -15,7 +16,6 @@ import type { FormulaIndexPatternColumn } from './formula';
import { insertOrReplaceFormulaColumn } from './parse';
import type { FormBasedLayer } from '../../../types';
import { IndexPattern } from '../../../../../types';
import { tinymathFunctions } from './util';
import { TermsIndexPatternColumn } from '../terms';
import { MovingAverageIndexPatternColumn } from '../calculations';
import { StaticValueIndexPatternColumn } from '../static_value';
Expand Down Expand Up @@ -82,7 +82,7 @@ const operationDefinitionMap: Record<string, GenericOperationDefinition> = {
}),
};

describe('formula', () => {
describe('[Lens] formula', () => {
let layer: FormBasedLayer;

beforeEach(() => {
Expand Down

0 comments on commit bfc66f0

Please sign in to comment.