@@ -25,6 +25,18 @@ struct CommandSourceTests {
2525 CommandSource ( ) . emptyItems ( context: ctx) ? . first { $0. title == title }
2626 }
2727
28+ /// The rename actions defer setting `renaming…ID` to the next main-queue
29+ /// tick (so the sidebar row's TextField exists before it takes first
30+ /// responder — see `AppCommand.action(in:)`). Spin the run loop so that
31+ /// deferred work lands before asserting.
32+ private func flushMainQueue( ) async {
33+ // Enqueue behind any pending DispatchQueue.main.async work; main-queue
34+ // FIFO ordering guarantees the deferred set has run once this resumes.
35+ await withCheckedContinuation { continuation in
36+ DispatchQueue . main. async { continuation. resume ( ) }
37+ }
38+ }
39+
2840 // MARK: - renameTab command availability
2941
3042 @Test
@@ -50,20 +62,21 @@ struct CommandSourceTests {
5062 }
5163
5264 @Test
53- func renameTab_postPaletteAction_sets_sidebarVisible_and_renamingTabID( ) throws {
65+ func renameTab_postPaletteAction_sets_sidebarVisible_and_renamingTabID( ) async throws {
5466 let ( ctx, state) = makeContext ( )
5567 let activeTabID = try #require(
5668 state. activeProjectID. flatMap { state. workspaces [ $0] ? . activeTabID }
5769 )
5870 let item = try #require( findItem ( title: AppCommand . renameTab. title, in: ctx) )
5971 item. action ( )
6072 state. postPaletteAction ? ( )
73+ await flushMainQueue ( )
6174 #expect( state. sidebarVisible)
6275 #expect( state. renamingTabID == activeTabID)
6376 }
6477
6578 @Test
66- func renameTab_postPaletteAction_targets_active_tab_at_time_of_action( ) throws {
79+ func renameTab_postPaletteAction_targets_active_tab_at_time_of_action( ) async throws {
6780 let ( ctx, state) = makeContext ( )
6881 let projectID = try #require( state. activeProjectID)
6982 let ws = try #require( state. workspaces [ projectID] )
@@ -81,6 +94,7 @@ struct CommandSourceTests {
8194 ws. selectTab ( firstTabID)
8295 item. action ( )
8396 state. postPaletteAction ? ( )
97+ await flushMainQueue ( )
8498
8599 // renamingTabID should be the tab that was active when the item was built.
86100 #expect( state. renamingTabID == secondTab. id)
@@ -112,31 +126,34 @@ struct CommandSourceTests {
112126 }
113127
114128 @Test
115- func renameProject_postPaletteAction_sets_sidebarVisible_and_renamingProjectID( ) throws {
129+ func renameProject_postPaletteAction_sets_sidebarVisible_and_renamingProjectID( ) async throws {
116130 let ( ctx, state) = makeContext ( )
117131 let projectID = try #require( state. activeProjectID)
118132 let item = try #require( findItem ( title: AppCommand . renameProject. title, in: ctx) )
119133 item. action ( )
120134 state. postPaletteAction ? ( )
135+ await flushMainQueue ( )
121136 #expect( state. sidebarVisible)
122137 #expect( state. renamingProjectID == projectID)
123138 }
124139
125140 @Test
126- func renameProject_does_not_set_renamingTabID( ) throws {
141+ func renameProject_does_not_set_renamingTabID( ) async throws {
127142 let ( ctx, state) = makeContext ( )
128143 let item = try #require( findItem ( title: AppCommand . renameProject. title, in: ctx) )
129144 item. action ( )
130145 state. postPaletteAction ? ( )
146+ await flushMainQueue ( )
131147 #expect( state. renamingTabID == nil )
132148 }
133149
134150 @Test
135- func renameTab_does_not_set_renamingProjectID( ) throws {
151+ func renameTab_does_not_set_renamingProjectID( ) async throws {
136152 let ( ctx, state) = makeContext ( )
137153 let item = try #require( findItem ( title: AppCommand . renameTab. title, in: ctx) )
138154 item. action ( )
139155 state. postPaletteAction ? ( )
156+ await flushMainQueue ( )
140157 #expect( state. renamingProjectID == nil )
141158 }
142159}
0 commit comments