Skip to content

Commit

Permalink
fix final tests
Browse files Browse the repository at this point in the history
  • Loading branch information
drewdaemon committed Aug 6, 2024
1 parent c003581 commit ad77eac
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const triggerCharacters = [',', '(', '=', ' '];
export const fields: Array<{ name: string; type: string; suggestedAs?: string }> = [
...[
'string',
'keyword',
'double',
'date',
'boolean',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ describe('autocomplete', () => {
}
testSuggestions(`from a ${prevCommand}| enrich policy `, ['ON $0', 'WITH $0', '| ']);
testSuggestions(`from a ${prevCommand}| enrich policy on `, [
'keywordField',
'stringField',
'doubleField',
'dateField',
Expand Down Expand Up @@ -704,7 +705,7 @@ describe('autocomplete', () => {
testSuggestions(
'from a | eval a=cidr_match(ipField, textField, ',
[
...getFieldNamesByType('text'),
...getFieldNamesByType('keyword'),
...getFunctionSignaturesByReturnType(
'eval',
['text', 'keyword'],
Expand Down Expand Up @@ -988,48 +989,6 @@ describe('autocomplete', () => {
});
});

describe('auto triggers', () => {
function getSuggestionsFor(statement: string) {
const callbackMocks = createCustomCallbackMocks(undefined, undefined, undefined);
const triggerOffset = statement.lastIndexOf(' ') + 1; // drop <here>
const context = createCompletionContext(statement[triggerOffset]);
return suggest(
statement,
triggerOffset + 1,
context,
async (text) => (text ? getAstAndSyntaxErrors(text) : { ast: [], errors: [] }),
callbackMocks
);
}
it('should trigger further suggestions for functions', async () => {
const suggestions = await getSuggestionsFor('from a | eval ');
const [expectedWithTrigger, expectedWithoutTrigger] = partition(
suggestions,
({ kind, label }) => kind === 'Function' || label === 'var0'
);
// test that all functions will retrigger suggestions
expect(
expectedWithTrigger.every(({ command }) => command === TRIGGER_SUGGESTION_COMMAND)
).toBeTruthy();
// now test that non-function won't retrigger
expect(expectedWithoutTrigger.every(({ command }) => command == null)).toBeTruthy();
});
it('should trigger further suggestions for commands', async () => {
const suggestions = await getSuggestionsFor('from a | ');
// test that all commands will retrigger suggestions
expect(
suggestions.every(({ command }) => command === TRIGGER_SUGGESTION_COMMAND)
).toBeTruthy();
});
it('should trigger further suggestions after enrich mode', async () => {
const suggestions = await getSuggestionsFor('from a | enrich _any:');
// test that all commands will retrigger suggestions
expect(
suggestions.every(({ command }) => command === TRIGGER_SUGGESTION_COMMAND)
).toBeTruthy();
});
});

/**
* Monaco asks for suggestions in at least two different scenarios.
* 1. When the user types a non-whitespace character (e.g. 'FROM k') - this is the Invoke trigger kind
Expand Down Expand Up @@ -1332,10 +1291,10 @@ describe('autocomplete', () => {
// field parameter

const expectedStringSuggestionsWhenMoreArgsAreNeeded = [
...getFieldNamesByType('string')
...getFieldNamesByType('keyword')
.map((field) => `${field}, `)
.map(attachTriggerCommand),
...getFunctionSignaturesByReturnType('eval', 'string', { scalar: true }, undefined, [
...getFunctionSignaturesByReturnType('eval', 'keyword', { scalar: true }, undefined, [
'replace',
]).map((s) => ({
...s,
Expand All @@ -1362,8 +1321,8 @@ describe('autocomplete', () => {
testSuggestions(
'FROM a | EVAL REPLACE(stringField, stringField, )',
[
...getFieldNamesByType('string').map((field) => ({ text: field, command: undefined })),
...getFunctionSignaturesByReturnType('eval', 'string', { scalar: true }, undefined, [
...getFieldNamesByType('keyword').map((field) => ({ text: field, command: undefined })),
...getFunctionSignaturesByReturnType('eval', 'keyword', { scalar: true }, undefined, [
'replace',
]),
],
Expand Down

0 comments on commit ad77eac

Please sign in to comment.