fix(editor): Support renaming node in HTML parameters (#16315)

This commit is contained in:
Charlie Kolb
2025-06-13 15:44:21 +02:00
committed by GitHub
parent aa273745ec
commit 88e3c90e71
6 changed files with 539 additions and 1 deletions

View File

@@ -0,0 +1,54 @@
import { mockFn } from 'jest-mock-extended';
import type { INode } from '@/index';
import { renameFormFields } from '@/node-parameters/rename-node-utils';
const makeNode = (formFieldValues: Array<Record<string, unknown>>) =>
({
parameters: {
formFields: {
values: formFieldValues,
},
},
}) as unknown as INode;
const mockMapping = mockFn();
describe('renameFormFields', () => {
beforeEach(() => {
mockMapping.mockReset();
});
it.each([
{ parameters: {} },
{ parameters: { otherField: null } },
{ parameters: { formFields: 'a' } },
{ parameters: { formFields: { values: 3 } } },
{ parameters: { formFields: { values: { newKey: true } } } },
{ parameters: { formFields: { values: [] } } },
{ parameters: { formFields: { values: [{ fieldType: 'json' }] } } },
{ parameters: { formFields: { values: [{ fieldType: 'html' }] } } },
] as unknown as INode[])('should not modify %s without formFields.values parameters', (node) => {
renameFormFields(node, mockMapping);
expect(mockMapping).not.toBeCalled();
});
it('should rename fields based on the provided mapping', () => {
const node = makeNode([{ fieldType: 'html', html: 'some text' }]);
renameFormFields(node, mockMapping);
expect(mockMapping).toBeCalledWith('some text');
});
it('should rename multiple fields', () => {
const node = makeNode([
{ fieldType: 'html', html: 'some text' },
{ fieldType: 'html', html: 'some text' },
{ fieldType: 'html', html: 'some text' },
{ fieldType: 'html', html: 'some text' },
{ fieldType: 'html', html: 'some text' },
]);
renameFormFields(node, mockMapping);
expect(mockMapping).toBeCalledTimes(5);
});
});