mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 21:07:28 -08:00
fix(editor): Render empty string instead of [empty] (#12448)
This commit is contained in:
parent
803960e092
commit
2c72047d0b
|
@ -132,6 +132,109 @@ describe('useExpressionEditor', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('render [empty] when expression evaluates to an empty string', async () => {
|
||||||
|
mockResolveExpression().mockReturnValueOnce('');
|
||||||
|
|
||||||
|
const {
|
||||||
|
expressionEditor: { segments },
|
||||||
|
} = await renderExpressionEditor({
|
||||||
|
editorValue: "{{ '' }}",
|
||||||
|
extensions: [n8nLang()],
|
||||||
|
});
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(toValue(segments.all)).toEqual([
|
||||||
|
{
|
||||||
|
error: null,
|
||||||
|
from: 0,
|
||||||
|
kind: 'resolvable',
|
||||||
|
resolvable: "{{ '' }}",
|
||||||
|
resolved: '[empty]',
|
||||||
|
state: 'valid',
|
||||||
|
to: 8,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(toValue(segments.resolvable)).toEqual([
|
||||||
|
{
|
||||||
|
error: null,
|
||||||
|
from: 0,
|
||||||
|
kind: 'resolvable',
|
||||||
|
resolvable: "{{ '' }}",
|
||||||
|
resolved: '[empty]',
|
||||||
|
state: 'valid',
|
||||||
|
to: 8,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(toValue(segments.plaintext)).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('does not render [empty] when expression evaluates to an empty string within a string', async () => {
|
||||||
|
mockResolveExpression().mockReturnValueOnce('');
|
||||||
|
|
||||||
|
const {
|
||||||
|
expressionEditor: { segments },
|
||||||
|
} = await renderExpressionEditor({
|
||||||
|
editorValue: "before {{ '' }} after",
|
||||||
|
extensions: [n8nLang()],
|
||||||
|
});
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(toValue(segments.all)).toEqual([
|
||||||
|
{
|
||||||
|
from: 0,
|
||||||
|
kind: 'plaintext',
|
||||||
|
plaintext: 'before ',
|
||||||
|
to: 7,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
error: null,
|
||||||
|
from: 7,
|
||||||
|
kind: 'resolvable',
|
||||||
|
resolvable: "{{ '' }}",
|
||||||
|
resolved: '',
|
||||||
|
state: 'valid',
|
||||||
|
to: 15,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
from: 15,
|
||||||
|
kind: 'plaintext',
|
||||||
|
plaintext: ' after',
|
||||||
|
to: 21,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(toValue(segments.resolvable)).toEqual([
|
||||||
|
{
|
||||||
|
error: null,
|
||||||
|
from: 7,
|
||||||
|
kind: 'resolvable',
|
||||||
|
resolvable: "{{ '' }}",
|
||||||
|
resolved: '',
|
||||||
|
state: 'valid',
|
||||||
|
to: 15,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(toValue(segments.plaintext)).toEqual([
|
||||||
|
{
|
||||||
|
from: 0,
|
||||||
|
kind: 'plaintext',
|
||||||
|
plaintext: 'before ',
|
||||||
|
to: 7,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
from: 15,
|
||||||
|
kind: 'plaintext',
|
||||||
|
plaintext: ' after',
|
||||||
|
to: 21,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('readEditorValue()', () => {
|
describe('readEditorValue()', () => {
|
||||||
test('should return the full editor value (unresolved)', async () => {
|
test('should return the full editor value (unresolved)', async () => {
|
||||||
mockResolveExpression().mockReturnValueOnce(15);
|
mockResolveExpression().mockReturnValueOnce(15);
|
||||||
|
|
|
@ -22,11 +22,7 @@ import { useWorkflowHelpers } from '@/composables/useWorkflowHelpers';
|
||||||
import { highlighter } from '@/plugins/codemirror/resolvableHighlighter';
|
import { highlighter } from '@/plugins/codemirror/resolvableHighlighter';
|
||||||
import { closeCursorInfoBox } from '@/plugins/codemirror/tooltips/InfoBoxTooltip';
|
import { closeCursorInfoBox } from '@/plugins/codemirror/tooltips/InfoBoxTooltip';
|
||||||
import type { Html, Plaintext, RawSegment, Resolvable, Segment } from '@/types/expressions';
|
import type { Html, Plaintext, RawSegment, Resolvable, Segment } from '@/types/expressions';
|
||||||
import {
|
import { getExpressionErrorMessage, getResolvableState } from '@/utils/expressions';
|
||||||
getExpressionErrorMessage,
|
|
||||||
getResolvableState,
|
|
||||||
isEmptyExpression,
|
|
||||||
} from '@/utils/expressions';
|
|
||||||
import { closeCompletion, completionStatus } from '@codemirror/autocomplete';
|
import { closeCompletion, completionStatus } from '@codemirror/autocomplete';
|
||||||
import {
|
import {
|
||||||
Compartment,
|
Compartment,
|
||||||
|
@ -129,6 +125,12 @@ export const useExpressionEditor = ({
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
|
if (
|
||||||
|
segments.value.length === 1 &&
|
||||||
|
segments.value[0]?.kind === 'resolvable' &&
|
||||||
|
segments.value[0]?.resolved === ''
|
||||||
|
)
|
||||||
|
segments.value[0].resolved = i18n.baseText('expressionModalInput.empty');
|
||||||
};
|
};
|
||||||
|
|
||||||
function readEditorValue(): string {
|
function readEditorValue(): string {
|
||||||
|
@ -314,14 +316,6 @@ export const useExpressionEditor = ({
|
||||||
result.fullError = error;
|
result.fullError = error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.resolved === '') {
|
|
||||||
result.resolved = i18n.baseText('expressionModalInput.empty');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.resolved === undefined && isEmptyExpression(resolvable)) {
|
|
||||||
result.resolved = i18n.baseText('expressionModalInput.empty');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.resolved === undefined) {
|
if (result.resolved === undefined) {
|
||||||
result.resolved = isUncalledExpressionExtension(resolvable)
|
result.resolved = isUncalledExpressionExtension(resolvable)
|
||||||
? i18n.baseText('expressionEditor.uncalledFunction')
|
? i18n.baseText('expressionEditor.uncalledFunction')
|
||||||
|
|
Loading…
Reference in a new issue