@@ -21,9 +21,12 @@ public override void OneTimeSetUp()
2121    { 
2222        base . OneTimeSetUp ( ) ; 
2323        m_Asset  =  AssetDatabaseUtils . CreateAsset < InputActionAsset > ( ) ; 
24-         m_Asset . AddActionMap ( "First Name" ) ; 
24+         var   actionMap   =   m_Asset . AddActionMap ( "First Name" ) ; 
2525        m_Asset . AddActionMap ( "Second Name" ) ; 
2626        m_Asset . AddActionMap ( "Third Name" ) ; 
27+ 
28+         actionMap . AddAction ( "Action One" ) ; 
29+         actionMap . AddAction ( "Action Two" ) ; 
2730    } 
2831
2932    public  override  void  OneTimeTearDown ( ) 
@@ -55,6 +58,19 @@ IEnumerator WaitForActionMapRename(int index, bool isActive, double timeoutSecs
5558        } ,  $ "WaitForActionMapRename { index }  { isActive } ",  timeoutSecs ) ; 
5659    } 
5760
61+     IEnumerator  WaitForActionRename ( int  index ,  bool  isActive ,  double  timeoutSecs  =  5.0 ) 
62+     { 
63+         return  WaitUntil ( ( )  => 
64+         { 
65+             var  actionItems  =  m_Window . rootVisualElement . Q ( "actions-container" ) . Query < InputActionsTreeViewItem > ( ) . ToList ( ) ; 
66+             if  ( actionItems . Count  >  index  &&  actionItems [ index ] . IsFocused  ==  isActive ) 
67+             { 
68+                 return  true ; 
69+             } 
70+             return  false ; 
71+         } ,  $ "WaitForActionRename { index }  { isActive } ",  timeoutSecs ) ; 
72+     } 
73+ 
5874    #endregion
5975
6076    [ Test ] 
@@ -173,5 +189,51 @@ public IEnumerator CanDeleteActionMap()
173189        Assert . That ( m_Window . currentAssetInEditor . actionMaps [ 0 ] . name ,  Is . EqualTo ( "First Name" ) ) ; 
174190        Assert . That ( m_Window . currentAssetInEditor . actionMaps [ 1 ] . name ,  Is . EqualTo ( "Third Name" ) ) ; 
175191    } 
192+ 
193+     [ UnityTest ] 
194+     public  IEnumerator  CanRenameAction ( ) 
195+     { 
196+         var  actionContainer  =  m_Window . rootVisualElement . Q ( "actions-container" ) ; 
197+         var  actionItem  =  actionContainer . Query < InputActionsTreeViewItem > ( ) . ToList ( ) ; 
198+         Assume . That ( actionItem [ 1 ] . Q < Label > ( "name" ) . text ,  Is . EqualTo ( "Action Two" ) ) ; 
199+ 
200+         m_Window . rootVisualElement . Q < TreeView > ( "actions-tree-view" ) . Focus ( ) ; 
201+         m_Window . rootVisualElement . Q < TreeView > ( "actions-tree-view" ) . selectedIndex  =  1 ; 
202+ 
203+         // Selection change triggers a state change, wait for the scheduler to process the frame 
204+         yield  return  WaitForSchedulerLoop ( ) ; 
205+         yield  return  WaitForNotDirty ( ) ; 
206+         yield  return  WaitForFocus ( m_Window . rootVisualElement . Q < TreeView > ( "actions-tree-view" ) ) ; 
207+ 
208+         // Re-fetch the actions since the UI may have refreshed. 
209+         actionItem  =  actionContainer . Query < InputActionsTreeViewItem > ( ) . ToList ( ) ; 
210+ 
211+         // Click twice to start the rename 
212+         SimulateClickOn ( actionItem [ 1 ] ) ; 
213+         // If the item is already focused, don't click again 
214+         if  ( ! actionItem [ 1 ] . IsFocused ) 
215+         { 
216+             SimulateClickOn ( actionItem [ 1 ] ) ; 
217+         } 
218+ 
219+         yield  return  WaitForActionRename ( 1 ,  isActive :  true ) ; 
220+ 
221+         // Rename the action 
222+         SimulateTypingText ( "New Name" ) ; 
223+ 
224+         // Wait for rename to end 
225+         yield  return  WaitForActionRename ( 1 ,  isActive :  false ) ; 
226+ 
227+         // Check on the UI side 
228+         actionContainer  =  m_Window . rootVisualElement . Q ( "actions-container" ) ; 
229+         Assume . That ( actionContainer ,  Is . Not . Null ) ; 
230+         actionItem  =  actionContainer . Query < InputActionsTreeViewItem > ( ) . ToList ( ) ; 
231+         Assert . That ( actionItem ,  Is . Not . Null ) ; 
232+         Assert . That ( actionItem . Count ,  Is . EqualTo ( 2 ) ) ; 
233+         Assert . That ( actionItem [ 1 ] . Q < Label > ( "name" ) . text ,  Is . EqualTo ( "New Name" ) ) ; 
234+ 
235+         // Check on the asset side 
236+         Assert . That ( m_Window . currentAssetInEditor . actionMaps [ 0 ] . actions [ 1 ] . name ,  Is . EqualTo ( "New Name" ) ) ; 
237+     } 
176238} 
177239#endif
0 commit comments