Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Aug 29, 2024
1 parent 4e3aa27 commit cfa7363
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { ESQL_COMMON_NUMERIC_TYPES, ESQL_NUMBER_TYPES } from '../../shared/esql_types';
import { ADD_DATE_HISTOGRAM_SNIPPET } from '../factories';
import { roundParameterTypes } from './constants';
import { setup, getFunctionSignaturesByReturnType, getFieldNamesByType } from './helpers';

Expand Down Expand Up @@ -213,6 +214,7 @@ describe('autocomplete.suggest', () => {
const { assertSuggestions } = await setup();
const expected = [
'var0 = ',
ADD_DATE_HISTOGRAM_SNIPPET,
...getFieldNamesByType('any').map((field) => `${field} `),
...allEvaFunctions,
...allGroupingFunctions,
Expand All @@ -235,6 +237,7 @@ describe('autocomplete.suggest', () => {
const fields = getFieldNamesByType('any').map((field) => `${field} `);
await assertSuggestions('from a | stats a=c by d, /', [
'var0 = ',
ADD_DATE_HISTOGRAM_SNIPPET,
...fields,
...allEvaFunctions,
...allGroupingFunctions,
Expand All @@ -246,6 +249,7 @@ describe('autocomplete.suggest', () => {
]);
await assertSuggestions('from a | stats avg(b) by c, /', [
'var0 = ',
ADD_DATE_HISTOGRAM_SNIPPET,
...fields,
...getFunctionSignaturesByReturnType('eval', 'any', { scalar: true }),
...allGroupingFunctions,
Expand All @@ -267,11 +271,13 @@ describe('autocomplete.suggest', () => {
...allGroupingFunctions,
]);
await assertSuggestions('from a | stats avg(b) by var0 = /', [
ADD_DATE_HISTOGRAM_SNIPPET,
...getFieldNamesByType('any').map((field) => `${field} `),
...allEvaFunctions,
...allGroupingFunctions,
]);
await assertSuggestions('from a | stats avg(b) by c, var0 = /', [
ADD_DATE_HISTOGRAM_SNIPPET,
...getFieldNamesByType('any').map((field) => `${field} `),
...allEvaFunctions,
...allGroupingFunctions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import { suggest } from './autocomplete';
import { evalFunctionDefinitions } from '../definitions/functions';
import { timeUnitsToSuggest } from '../definitions/literals';
import { commandDefinitions as unmodifiedCommandDefinitions } from '../definitions/commands';
import { getSafeInsertText, TIME_SYSTEM_PARAMS, TRIGGER_SUGGESTION_COMMAND } from './factories';
import {
ADD_DATE_HISTOGRAM_SNIPPET,
getSafeInsertText,
TIME_SYSTEM_PARAMS,
TRIGGER_SUGGESTION_COMMAND,
} from './factories';
import { camelCase } from 'lodash';
import { getAstAndSyntaxErrors } from '@kbn/esql-ast';
import {
Expand Down Expand Up @@ -638,6 +643,7 @@ describe('autocomplete', () => {
// STATS argument BY expression
testSuggestions('FROM index1 | STATS field BY f/', [
'var0 = ',
ADD_DATE_HISTOGRAM_SNIPPET,
...getFunctionSignaturesByReturnType('stats', 'any', { grouping: true, scalar: true }),
...getFieldNamesByType('any').map((field) => `${field} `),
]);
Expand Down Expand Up @@ -850,6 +856,7 @@ describe('autocomplete', () => {
'by'
);
testSuggestions('FROM a | STATS AVG(numberField) BY /', [
'BUCKET($0, 20, ?start, ?end)',
attachTriggerCommand('var0 = '),
...getFieldNamesByType('any')
.map((field) => `${field} `)
Expand All @@ -859,6 +866,7 @@ describe('autocomplete', () => {

// STATS argument BY assignment (checking field suggestions)
testSuggestions('FROM a | STATS AVG(numberField) BY var0 = /', [
'BUCKET($0, 20, ?start, ?end)',
...getFieldNamesByType('any')
.map((field) => `${field} `)
.map(attachTriggerCommand),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import {
getDateLiterals,
buildFieldsDefinitionsWithMetadata,
TRIGGER_SUGGESTION_COMMAND,
ADD_DATE_HISTOGRAM_SNIPPET,
} from './factories';
import { EDITOR_MARKER, SINGLE_BACKTICK, METADATA_FIELDS } from '../shared/constants';
import { getAstContext, removeMarkerArgFromArgsList } from '../shared/context';
Expand Down Expand Up @@ -1767,7 +1768,7 @@ async function getOptionArgsSuggestions(
defaultMessage: 'Add date histogram',
}
),
text: `BUCKET($0, 20, ?start, ?end)`,
text: ADD_DATE_HISTOGRAM_SNIPPET,
asSnippet: true,
kind: 'Function',
detail: i18n.translate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const allFunctions = statsAggregationFunctionDefinitions
.concat(groupingFunctionDefinitions);

export const TIME_SYSTEM_PARAMS = ['?t_start', '?t_end'];
export const ADD_DATE_HISTOGRAM_SNIPPET = 'BUCKET($0, 20, ?start, ?end)';

export const TRIGGER_SUGGESTION_COMMAND = {
title: 'Trigger Suggestion Dialog',
Expand Down

0 comments on commit cfa7363

Please sign in to comment.