@@ -119,4 +119,50 @@ QUnit.module('Async render', () => {
119119 } , asyncTemplateRenderTimeout ) ;
120120 } ) ;
121121 } ) ;
122+
123+ QUnit . test ( 'selectItem triggered in onContentReady works properly for asynchronous templates (T1307114)' , function ( assert ) {
124+ const done = assert . async ( ) ;
125+
126+ let instance = null ;
127+
128+ try {
129+ instance = new TreeView ( $ ( '#treeView' ) , {
130+ dataSource : [ { text : 'item 1' , id : 1 } , { text : 'item 2' , id : 2 } ] ,
131+ selectionMode : 'multiple' ,
132+ showCheckBoxesMode : 'selectAll' ,
133+ itemTemplate : 'custom' ,
134+ onContentReady : ( e ) => {
135+ e . component . selectItem ( 1 ) ;
136+ } ,
137+ templatesRenderAsynchronously : true ,
138+ integrationOptions : {
139+ templates : {
140+ custom : {
141+ render : function ( { container, onRendered, model } ) {
142+ setTimeout ( ( ) => {
143+ $ ( '<div>' ) . text ( model . text ) . appendTo ( container ) ;
144+ onRendered ( ) ;
145+ } ) ;
146+ }
147+ }
148+ }
149+ } ,
150+ } ) ;
151+ assert . ok ( true , 'No error should be thrown' ) ;
152+ } catch ( e ) {
153+ assert . ok ( false , `Error should not be thrown: ${ e } ` ) ;
154+ }
155+
156+ setTimeout ( ( ) => {
157+ const element = instance . itemsContainer ( ) ;
158+ const $firstCheckbox = $ ( element ) . find ( `.${ CHECKBOX_CLASS } ` ) ;
159+ const firstCheckboxInstance = $firstCheckbox . dxCheckBox ( 'instance' ) ;
160+
161+ assert . strictEqual ( $firstCheckbox . eq ( 0 ) . hasClass ( CHECKBOX_CHECKED_CLASS ) , true , 'checkbox has selected class' ) ;
162+ assert . strictEqual ( firstCheckboxInstance . option ( 'value' ) , true , 'checkbox value is correct' ) ;
163+ assert . strictEqual ( instance . getSelectedNodeKeys ( ) [ 0 ] , 1 , 'item is selected' ) ;
164+
165+ done ( ) ;
166+ } , asyncTemplateRenderTimeout ) ;
167+ } ) ;
122168} ) ;
0 commit comments