Skip to content

Commit d88de22

Browse files
authored
Form Smart Paste: trim results after getting a value from AI (DevExpress#31033)
1 parent a0b85fe commit d88de22

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

packages/devextreme/js/__internal/core/ai_integration/commands/smartPaste.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,19 @@ describe('SmartPasteCommand', () => {
134134

135135
expect(result).toStrictEqual(expectedResult);
136136
});
137+
138+
it('should trim string and array values in parseResult', () => {
139+
const response = 'Field1::: value1 ;;;Field2::: value2 ::: value3 ';
140+
// @ts-expect-error Access to protected property for a test
141+
const result = command.parseResult(response);
142+
143+
const expectedResult = [
144+
{ name: 'Field1', value: 'value1' },
145+
{ name: 'Field2', value: ['value2', 'value3'] },
146+
];
147+
148+
expect(result).toStrictEqual(expectedResult);
149+
});
137150
});
138151

139152
describe('execute', () => {

packages/devextreme/js/__internal/core/ai_integration/commands/smartPaste.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export class SmartPasteCommand extends BaseCommand<
2828
return;
2929
}
3030

31-
const [name, ...values] = data.split(':::');
31+
const [name, ...rawValues] = data.split(':::');
32+
const values = rawValues.map((value) => value.trim());
3233
const value = values.length <= 1 ? values[0] : values;
3334

3435
if (value) {

packages/devextreme/testing/tests/DevExpress.ui.widgets.form/form.ai.utils.tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ QUnit.module('parseResultForEditorType', () => {
167167
}].forEach(({ editorType, correctValues, incorrectValues, expectedType }) => {
168168
correctValues.forEach(({ value, description }) => {
169169
QUnit.test(`should return correct value for ${description} for ${editorType}`, function(assert) {
170-
assert.strictEqual(parseResultForEditorType('', editorType, value), value, `${JSON.stringify(value)} is correct value for ${editorType}`);
170+
assert.deepEqual(parseResultForEditorType('', editorType, value), value, `${JSON.stringify(value)} is correct value for ${editorType}`);
171171
});
172172
});
173173

@@ -206,7 +206,7 @@ QUnit.module('parseResultForEditorType', () => {
206206

207207
QUnit.test(`should return same array value for ${editorType}`, function(assert) {
208208
const value = ['string'];
209-
assert.strictEqual(parseResultForEditorType('', editorType, value), value, `${JSON.stringify(value)} returned for ${editorType}`);
209+
assert.deepEqual(parseResultForEditorType('', editorType, value), value, `${JSON.stringify(value)} returned for ${editorType}`);
210210
});
211211
});
212212
});

packages/devextreme/testing/tests/DevExpress.ui.widgets.form/form.aiIntegration.tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ QUnit.module('SmartPaste', () => {
12421242
completionCallback();
12431243

12441244
setTimeout(() => {
1245-
assert.strictEqual(form.getEditor(dataField).option('value'), value, 'text value was set');
1245+
assert.deepEqual(form.getEditor(dataField).option('value'), value, 'text value was set');
12461246
done();
12471247
}, 10);
12481248
} catch(error) {

0 commit comments

Comments
 (0)