@@ -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 ( )
@@ -54,6 +57,19 @@ IEnumerator WaitForActionMapRename(int index, bool isActive, double timeoutSecs
5457 return false ;
5558 } , $ "WaitForActionMapRename { index } { isActive } ", timeoutSecs ) ;
5659 }
60+
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+ }
5773
5874 #endregion
5975
@@ -173,5 +189,55 @@ 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+ // Get the element that has focus before rename
220+ var focusedElement = m_Window . rootVisualElement . Q < TreeView > ( "actions-tree-view" ) . focusController . focusedElement ;
221+
222+ yield return WaitForActionRename ( 1 , isActive : true ) ;
223+
224+ // Rename the action
225+ SimulateTypingText ( "New Name" ) ;
226+
227+ // Wait for rename to end
228+ yield return WaitForActionRename ( 1 , isActive : false ) ;
229+
230+ // Check on the UI side
231+ actionContainer = m_Window . rootVisualElement . Q ( "actions-container" ) ;
232+ Assume . That ( actionContainer , Is . Not . Null ) ;
233+ actionItem = actionContainer . Query < InputActionsTreeViewItem > ( ) . ToList ( ) ;
234+ Assert . That ( actionItem , Is . Not . Null ) ;
235+ Assert . That ( actionItem . Count , Is . EqualTo ( 2 ) ) ;
236+ Assert . That ( actionItem [ 1 ] . Q < Label > ( "name" ) . text , Is . EqualTo ( "New Name" ) ) ;
237+ Assert . That ( m_Window . rootVisualElement . Q < TreeView > ( "actions-tree-view" ) . focusController . focusedElement , Is . EqualTo ( focusedElement ) ) ;
238+
239+ // Check on the asset side
240+ Assert . That ( m_Window . currentAssetInEditor . actionMaps [ 0 ] . actions [ 1 ] . name , Is . EqualTo ( "New Name" ) ) ;
241+ }
176242}
177243#endif
0 commit comments