Skip to content

Commit eeb6097

Browse files
Form Smart Paste: abort previous call on smartPaste triggered (DevExpress#30919)
1 parent 8df0c71 commit eeb6097

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

packages/devextreme/js/__internal/ui/form/form.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1836,13 +1836,16 @@ class Form extends Widget<FormProperties> {
18361836
}
18371837

18381838
async smartPaste(text?: string): Promise<void> {
1839+
if (this._currentAICommand?.command === 'smartPaste') {
1840+
this._processCommandCompletion();
1841+
}
1842+
18391843
const dataItems = this._itemsRunTimeInfo.getItemsForDataExtraction();
18401844
const fields = dataItems.map((item) => ({
18411845
name: item.dataField,
18421846
format: getItemFormatInfo(item),
18431847
instruction: item.aiOptions?.instruction,
18441848
}));
1845-
18461849
const smartPasteParams = {
18471850
text: text ?? await navigator.clipboard.readText(),
18481851
fields,

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ QUnit.module('SmartPaste', () => {
268268
];
269269

270270
assert.strictEqual(smartPaste.calledOnce, true, 'smartPaste command called');
271-
assert.deepEqual(smartPaste.getCall(0).args[0].fields, fields, 'smartPaste command called with passed text');
271+
assert.deepEqual(smartPaste.getCall(0).args[0].fields, fields, 'smartPaste command called with correct fields data');
272272
});
273273

274274
QUnit.test('should call smartPaste command with passed text', function(assert) {
@@ -332,5 +332,22 @@ QUnit.module('SmartPaste', () => {
332332
clipboardReadStub.restore();
333333
}
334334
});
335+
336+
QUnit.test('update aiIntegration cancels active request and calls new one with same params', function(assert) {
337+
const abortSpy = sinon.spy();
338+
const smartPaste = sinon.stub().returns(abortSpy);
339+
const aiIntegration = { smartPaste: smartPaste };
340+
341+
const form = setupFormWithAi({ aiIntegration });
342+
form.smartPaste('test');
343+
344+
assert.strictEqual(smartPaste.calledOnce, true, 'smartPaste called');
345+
346+
form.smartPaste('second test');
347+
348+
assert.strictEqual(abortSpy.calledOnce, true, 'previous request aborted');
349+
assert.strictEqual(smartPaste.getCalls().length, 2, 'smartPaste is called again');
350+
assert.deepEqual(smartPaste.getCall(1).args[0].text, 'second test', 'smartPaste invoked with new text');
351+
});
335352
});
336353
});

0 commit comments

Comments
 (0)