@@ -218,35 +218,69 @@ struct WelcomeWindowSuppressionTests {
218218 #expect( delegate. isHandlingFileOpen == true )
219219 }
220220
221- @Test ( " fileOpenSuppressionCount decrement to zero resets isHandlingFileOpen" )
222- func countZeroResetsFlag ( ) {
221+ @Test ( " endFileOpenSuppression — decrement to zero resets isHandlingFileOpen" )
222+ func endSuppressionResetsFlag ( ) {
223223 let delegate = makeAppDelegate ( )
224224 delegate. isHandlingFileOpen = true
225225 delegate. fileOpenSuppressionCount = 1
226226
227- // Simulate what scheduleWelcomeWindowSuppression does at the end
228- delegate. fileOpenSuppressionCount = max ( 0 , delegate. fileOpenSuppressionCount - 1 )
229- if delegate. fileOpenSuppressionCount == 0 {
230- delegate. isHandlingFileOpen = false
231- }
227+ delegate. endFileOpenSuppression ( )
232228
233229 #expect( delegate. fileOpenSuppressionCount == 0 )
234230 #expect( delegate. isHandlingFileOpen == false )
235231 }
236232
237- @Test ( " fileOpenSuppressionCount decrement keeps flag true while count > 0" )
238- func countPositiveKeepsFlag ( ) {
233+ @Test ( " endFileOpenSuppression — keeps flag true while count > 0" )
234+ func endSuppressionKeepsFlagWhilePositive ( ) {
239235 let delegate = makeAppDelegate ( )
240236 delegate. isHandlingFileOpen = true
241237 delegate. fileOpenSuppressionCount = 2
242238
243- // Simulate one decrement
244- delegate. fileOpenSuppressionCount = max ( 0 , delegate. fileOpenSuppressionCount - 1 )
245- if delegate. fileOpenSuppressionCount == 0 {
246- delegate. isHandlingFileOpen = false
247- }
239+ delegate. endFileOpenSuppression ( )
248240
249241 #expect( delegate. fileOpenSuppressionCount == 1 )
250242 #expect( delegate. isHandlingFileOpen == true )
251243 }
244+
245+ // MARK: - Main Window Becomes Key
246+
247+ @Test ( " windowDidBecomeKey — main window appearing closes welcome during file open " )
248+ func windowDidBecomeKeyMainWindowClosesWelcome( ) {
249+ let delegate = makeAppDelegate ( )
250+ delegate. isHandlingFileOpen = true
251+
252+ let welcome = makeWindow ( identifier: " welcome " )
253+ welcome. orderFront ( nil )
254+ defer { welcome. close ( ) }
255+
256+ let mainWin = makeWindow ( identifier: " main " )
257+ mainWin. orderFront ( nil )
258+ defer { mainWin. close ( ) }
259+
260+ // Simulate main window becoming key — should close welcome
261+ let notification = Notification ( name: NSWindow . didBecomeKeyNotification, object: mainWin)
262+ delegate. windowDidBecomeKey ( notification)
263+
264+ #expect( !welcome. isVisible)
265+ }
266+
267+ @Test ( " windowDidBecomeKey — main window does not close welcome when not handling file open " )
268+ func windowDidBecomeKeyMainWindowNoEffectWhenNotHandling( ) {
269+ let delegate = makeAppDelegate ( )
270+ delegate. isHandlingFileOpen = false
271+
272+ let welcome = makeWindow ( identifier: " welcome " )
273+ welcome. orderFront ( nil )
274+ defer { welcome. close ( ) }
275+
276+ let mainWin = makeWindow ( identifier: " main " )
277+ mainWin. orderFront ( nil )
278+ defer { mainWin. close ( ) }
279+
280+ let notification = Notification ( name: NSWindow . didBecomeKeyNotification, object: mainWin)
281+ delegate. windowDidBecomeKey ( notification)
282+
283+ // Welcome should remain visible — no suppression active
284+ #expect( welcome. isVisible)
285+ }
252286}
0 commit comments