NotificationNavigationBrokerTests.swift (1757B)
1 import Foundation 2 import Testing 3 4 @testable import Crossmate 5 6 @Suite("Notification navigation broker", .serialized) 7 @MainActor 8 struct NotificationNavigationBrokerTests { 9 @Test("Invite-origin is reported exactly once, then cleared") 10 func inviteOriginConsumedOnce() { 11 let broker = NotificationNavigationBroker.shared 12 let gameID = UUID() 13 14 broker.openGame(gameID, fromInvitePing: true) 15 16 // First read sees the invite origin... 17 #expect(broker.consumeInviteOrigin(gameID)) 18 // ...and clears it, so a later re-open from the library list (which 19 // does not pass the flag) behaves like a normal navigation. 20 #expect(!broker.consumeInviteOrigin(gameID)) 21 } 22 23 @Test("A non-invite open carries no invite origin") 24 func defaultOpenHasNoInviteOrigin() { 25 let broker = NotificationNavigationBroker.shared 26 let gameID = UUID() 27 28 broker.openGame(gameID) 29 30 #expect(!broker.consumeInviteOrigin(gameID)) 31 } 32 33 @Test("Consuming an untouched game ID returns false") 34 func consumeWithoutOpenReturnsFalse() { 35 let broker = NotificationNavigationBroker.shared 36 37 #expect(!broker.consumeInviteOrigin(UUID())) 38 } 39 40 @Test("Invite origin is tracked per game ID") 41 func inviteOriginIsPerGame() { 42 let broker = NotificationNavigationBroker.shared 43 let invitedID = UUID() 44 let otherID = UUID() 45 46 broker.openGame(invitedID, fromInvitePing: true) 47 broker.openGame(otherID, fromInvitePing: false) 48 49 // Consuming the unrelated game neither reports nor disturbs the 50 // invited game's flag. 51 #expect(!broker.consumeInviteOrigin(otherID)) 52 #expect(broker.consumeInviteOrigin(invitedID)) 53 } 54 }