-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(editor): Fix completion on $input.item. in Code node (#10800)
- Loading branch information
Showing
3 changed files
with
80 additions
and
9 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
...itor-ui/src/components/CodeNodeEditor/completions/__tests__/itemField.completions.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { CompletionContext } from '@codemirror/autocomplete'; | ||
import { EditorSelection, EditorState } from '@codemirror/state'; | ||
import { useItemFieldCompletions } from '../itemField.completions'; | ||
|
||
describe('inputMethodCompletions', () => { | ||
test('should return completions for $input.item.|', () => { | ||
const { inputMethodCompletions } = useItemFieldCompletions('javaScript'); | ||
expect(inputMethodCompletions(createContext('$input.item.|'))).toEqual({ | ||
from: 0, | ||
options: [ | ||
{ | ||
info: expect.any(Function), | ||
label: '$input.item.json', | ||
type: 'variable', | ||
}, | ||
|
||
{ | ||
info: expect.any(Function), | ||
label: '$input.item.binary', | ||
type: 'variable', | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test('should return completions for $input.first().|', () => { | ||
const { inputMethodCompletions } = useItemFieldCompletions('javaScript'); | ||
expect(inputMethodCompletions(createContext('$input.first().|'))).toEqual({ | ||
from: 0, | ||
options: [ | ||
{ | ||
info: expect.any(Function), | ||
label: '$input.first().json', | ||
type: 'variable', | ||
}, | ||
|
||
{ | ||
info: expect.any(Function), | ||
label: '$input.first().binary', | ||
type: 'variable', | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test('should return completions for $input.all()[1].|', () => { | ||
const { inputMethodCompletions } = useItemFieldCompletions('javaScript'); | ||
expect(inputMethodCompletions(createContext('$input.all()[1].|'))).toEqual({ | ||
from: 0, | ||
options: [ | ||
{ | ||
info: expect.any(Function), | ||
label: '$input.all()[1].json', | ||
type: 'variable', | ||
}, | ||
|
||
{ | ||
info: expect.any(Function), | ||
label: '$input.all()[1].binary', | ||
type: 'variable', | ||
}, | ||
], | ||
}); | ||
}); | ||
}); | ||
|
||
export function createContext(docWithCursor: string) { | ||
const cursorPosition = docWithCursor.indexOf('|'); | ||
|
||
const doc = docWithCursor.slice(0, cursorPosition) + docWithCursor.slice(cursorPosition + 1); | ||
|
||
return new CompletionContext( | ||
EditorState.create({ doc, selection: EditorSelection.single(cursorPosition) }), | ||
cursorPosition, | ||
false, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
packages/editor-ui/src/components/CodeNodeEditor/completions/package.json
This file was deleted.
Oops, something went wrong.