@@ -464,7 +464,7 @@ QUnit.module('SmartPaste', () => {
464464 } ) ;
465465 } ) ;
466466
467- QUnit . test ( 'LoadPanel is hidden when smartPaste operation is aborted ' , function ( assert ) {
467+ QUnit . test ( 'LoadPanel not hidden on aiIntegration update during command execution ' , function ( assert ) {
468468 const done = assert . async ( ) ;
469469 let abortCallback ;
470470
@@ -485,6 +485,38 @@ QUnit.module('SmartPaste', () => {
485485
486486 form . option ( 'aiIntegration' , { smartPaste : sinon . stub ( ) . callsFake ( ( ) => ( ) => { } ) } ) ;
487487
488+ setTimeout ( ( ) => {
489+ assert . strictEqual ( abortCallback . calledOnce , true , 'Previous operation was aborted' ) ;
490+ assert . strictEqual ( form . _loadPanel . option ( 'visible' ) , true , 'LoadPanel is hidden after abort' ) ;
491+ assert . strictEqual ( form . option ( 'disabled' ) , true , 'Form is not disabled after abort' ) ;
492+
493+ done ( ) ;
494+ } , 10 ) ;
495+ } , 10 ) ;
496+ } ) ;
497+ } ) ;
498+
499+ QUnit . test ( 'LoadPanel is hidden on aiIntegration remove during command execution' , function ( assert ) {
500+ const done = assert . async ( ) ;
501+ let abortCallback ;
502+
503+ const smartPaste = sinon . stub ( ) . callsFake ( ( params , callbacks ) => {
504+ abortCallback = sinon . spy ( ) ;
505+ return abortCallback ;
506+ } ) ;
507+ const aiIntegration = { smartPaste : smartPaste } ;
508+ const form = setupFormWithAi ( { aiIntegration } ) ;
509+
510+ this . clipboardStub = this . createClipboardStub ( 'test text' ) ;
511+
512+ form . smartPaste ( ) . then ( ( ) => {
513+ setTimeout ( ( ) => {
514+ assert . strictEqual ( form . $element ( ) . find ( `.${ FORM_LOAD_PANEL_CLASS } ` ) . length , 1 , 'LoadPanel is shown during operation' ) ;
515+ assert . strictEqual ( form . option ( 'disabled' ) , true , 'Form is disabled during operation' ) ;
516+ assert . ok ( abortCallback , 'Abort callback was created' ) ;
517+
518+ form . option ( 'aiIntegration' , undefined ) ;
519+
488520 setTimeout ( ( ) => {
489521 assert . strictEqual ( abortCallback . calledOnce , true , 'Previous operation was aborted' ) ;
490522 assert . strictEqual ( form . $element ( ) . find ( `.${ FORM_LOAD_PANEL_CLASS } ` ) . length , 1 , 'LoadPanel is still present but hidden' ) ;
@@ -765,6 +797,30 @@ QUnit.module('SmartPaste', () => {
765797 assert . strictEqual ( onSmartPasted . calledOnce , true , 'onSmartPasted event has been invoked after its change at runtime' ) ;
766798 } ) ;
767799 } ) ;
800+
801+ QUnit . test ( 'should invoke onDataFieldChanged for each updated field after smartPaste' , function ( assert ) {
802+ const aiResult = [
803+ { name : 'field1' , value : 'value1' } ,
804+ { name : 'field2' , value : 'value2' } ,
805+ ] ;
806+ const smartPaste = ( _ , callbacks ) => {
807+ callbacks . onComplete ( aiResult ) ;
808+ } ;
809+ const onFieldDataChanged = sinon . spy ( ) ;
810+
811+ const form = setupFormWithAi ( {
812+ aiIntegration : { smartPaste } ,
813+ onFieldDataChanged
814+ } ) ;
815+
816+ form . smartPaste ( 'text' ) ;
817+
818+ const onFieldDataChangedCalls = onFieldDataChanged . getCalls ( ) ;
819+
820+ assert . strictEqual ( onFieldDataChangedCalls . length , 2 , 'onFieldDataChanged called twice' ) ;
821+ assert . propContains ( onFieldDataChangedCalls [ 0 ] . args [ 0 ] , { dataField : 'field1' , value : 'value1' } , 'onFieldDataChanged called for 1st field with correct args' ) ;
822+ assert . propContains ( onFieldDataChangedCalls [ 1 ] . args [ 0 ] , { dataField : 'field2' , value : 'value2' } , 'onFieldDataChanged called for 2nd field with correct args' ) ;
823+ } ) ;
768824 } ) ;
769825
770826 QUnit . module ( 'aiOptions' , {
0 commit comments