@@ -8,6 +8,106 @@ import XCTest
88
99class RunnerTests : XCTestCase {
1010
11+ @ MainActor
12+ func testNativeRemovalConfirmationUsesDestructiveAlertAndCancelsOnce ( ) async throws {
13+ let messenger = NavigationTestMessenger ( )
14+ let parent = UIViewController ( )
15+ let window = UIWindow ( frame : UIScreen . main . bounds )
16+ window . windowScene = UIApplication . shared . connectedScenes . compactMap { $0 as? UIWindowScene } . first
17+ window . rootViewController = parent
18+ parent . view . backgroundColor = . systemBackground
19+ window . makeKeyAndVisible ( )
20+ defer { window . isHidden = true }
21+ let coordinator = NativeConfirmationDialogCoordinator ( messenger : messenger , parentViewController : parent )
22+ let arguments : [ String : Any ] = [ " title " : " Remove community? " ,
23+ " message " : " Are you sure you want to remove “Alpha”? You can pair with it again later. " ,
24+ " confirmLabel " : " Remove " , " cancelLabel " : " Cancel " , " dark " : false ]
25+ var replies : [ Bool ] = [ ]
26+ let completed = expectation ( description : " Native confirmation dismissed " )
27+ messenger . invoke ( " present " , arguments : arguments ) {
28+ if let value = $0 as? Bool { replies . append ( value ) ; completed . fulfill ( ) }
29+ }
30+ let alert = try XCTUnwrap ( parent . presentedViewController as? UIAlertController )
31+ if let transition = alert . transitionCoordinator {
32+ await withCheckedContinuation { continuation in
33+ transition . animate ( alongsideTransition : nil ) { _ in continuation . resume ( ) }
34+ }
35+ }
36+ XCTAssertEqual ( alert . preferredStyle , . alert )
37+ XCTAssertEqual ( alert . title , " Remove community? " )
38+ XCTAssertEqual ( alert . message , arguments [ " message " ] as? String )
39+ XCTAssertEqual ( alert . actions . map ( \. title ) , [ " Cancel " , " Remove " ] )
40+ XCTAssertEqual ( alert . actions . map ( \. style ) , [ . cancel , . destructive ] )
41+ XCTAssertEqual ( alert . overrideUserInterfaceStyle , . light )
42+ XCTAssertTrue ( replies . isEmpty )
43+ var duplicate : Bool ?
44+ messenger . invoke ( " present " , arguments : arguments ) { duplicate = $0 as? Bool }
45+ XCTAssertEqual ( duplicate , false )
46+ XCTAssertTrue ( parent . presentedViewController === alert )
47+ let capture = UIGraphicsImageRenderer ( bounds : window . bounds ) . image { _ in
48+ window . drawHierarchy ( in : window . bounds , afterScreenUpdates : true )
49+ }
50+ let attachment = XCTAttachment ( image : capture )
51+ attachment . name = " Native remove community alert "
52+ attachment . lifetime = . keepAlways
53+ add ( attachment )
54+ coordinator . cancel ( )
55+ coordinator . cancel ( )
56+ await fulfillment ( of : [ completed ] , timeout : 3 )
57+ XCTAssertNil ( parent . presentedViewController )
58+ XCTAssertEqual ( replies , [ false ] )
59+ }
60+
61+ @ MainActor
62+ func testCommunityAvatarReportsItsVisibleFrameAndHidesWithoutMoving ( ) async throws {
63+ let messenger = NavigationTestMessenger ( )
64+ let parent = UIViewController ( )
65+ let window = UIWindow ( frame : CGRect ( x : 0 , y : 0 , width : 393 , height : 852 ) )
66+ window . windowScene = UIApplication . shared . connectedScenes . compactMap { $0 as? UIWindowScene } . first
67+ parent . view . backgroundColor = . systemBackground
68+ window . rootViewController = parent
69+ window . makeKeyAndVisible ( )
70+ defer { window . isHidden = true }
71+ let factory = IosNavigationBarFactory ( messenger : messenger , parent : parent )
72+ var leading : [ String : Any ] = [ " id " : " leading " , " label " : " Community settings " ,
73+ " avatarInitial " : " A " , " enabled " : true , " tracksAvatarBounds " : true ]
74+ let bar = factory . create ( withFrame : CGRect ( x : 0 , y : 0 , width : 393 , height : 160 ) ,
75+ viewIdentifier : 999991 , arguments : [ " title " : " Alpha " , " largeTitle " : true , " leading " : leading ,
76+ " actions " : [ [ " id " : " profile " , " label " : " Profile " , " avatarInitial " : " P " , " enabled " : true ] ] ] )
77+ parent . view . addSubview ( bar . view ( ) )
78+ parent . view . layoutIfNeeded ( )
79+ try await Task . sleep ( nanoseconds : 200_000_000 )
80+ let navigation = try XCTUnwrap ( parent . children . first as? UINavigationController )
81+ func avatar ( ) throws -> UIButton {
82+ try XCTUnwrap ( navigation . topViewController ? . navigationItem . leftBarButtonItems ? . first ? . customView as? UIButton )
83+ }
84+ // A rectangular custom view makes UIKit's surrounding glass a pill.
85+ let buttonBounds = try avatar ( ) . bounds
86+ XCTAssertEqual ( buttonBounds . width , buttonBounds . height )
87+ XCTAssertEqual ( buttonBounds . width , 36 )
88+ let visibleFrame = try XCTUnwrap ( messenger . avatarBounds )
89+ XCTAssertEqual ( ( visibleFrame [ " width " ] as? NSNumber ) ? . doubleValue , 36 )
90+ XCTAssertEqual ( ( visibleFrame [ " height " ] as? NSNumber ) ? . doubleValue , 36 )
91+ let image = try XCTUnwrap ( avatar ( ) . imageView )
92+ let imageFrame = image . convert ( image . bounds , to : bar . view ( ) )
93+ XCTAssertEqual ( ( visibleFrame [ " x " ] as? NSNumber ) ? . doubleValue , imageFrame . minX )
94+ XCTAssertEqual ( ( visibleFrame [ " y " ] as? NSNumber ) ? . doubleValue , imageFrame . minY )
95+ try avatar ( ) . sendActions ( for : . touchUpInside )
96+ XCTAssertEqual ( messenger . actions , [ " leading " ] )
97+ leading [ " avatarHidden " ] = true
98+ messenger . configure ( [ " title " : " Bravo " , " largeTitle " : true , " leading " : leading ] )
99+ var landingPrepared = false
100+ messenger . invoke ( " prepareForReveal " , arguments : [ : ] ) { _ in landingPrepared = true }
101+ XCTAssertTrue ( landingPrepared )
102+ XCTAssertFalse ( bar . view ( ) . layer . needsLayout ( ) )
103+ XCTAssertEqual ( try avatar ( ) . alpha , 0 )
104+ XCTAssertEqual ( ( messenger . avatarBounds ? [ " x " ] as? NSNumber ) ? . doubleValue , imageFrame . minX )
105+ XCTAssertEqual ( ( messenger . avatarBounds ? [ " y " ] as? NSNumber ) ? . doubleValue , imageFrame . minY )
106+ leading [ " avatarHidden " ] = false
107+ messenger . configure ( [ " title " : " Bravo " , " largeTitle " : true , " leading " : leading ] )
108+ XCTAssertEqual ( try avatar ( ) . alpha , 1 )
109+ }
110+
11111 @ MainActor
12112 func testConversationTitleHasWidthBeforePlatformViewLayout ( ) throws {
13113 let parent = UIViewController ( )
@@ -244,7 +344,7 @@ class RunnerTests: XCTestCase {
244344 }
245345
246346 @ MainActor
247- func testCompactMaterialOnlyAppearsAfterScrolling ( ) async throws {
347+ func testCompactNavigationMaterialFollowsScrollDepth ( ) async throws {
248348 let messenger = NavigationTestMessenger ( )
249349 let parent = UIViewController ( )
250350 let window = UIWindow ( frame : UIScreen . main . bounds )
@@ -260,8 +360,9 @@ class RunnerTests: XCTestCase {
260360 parent . view . addSubview ( bar . view ( ) )
261361 parent . view . layoutIfNeeded ( )
262362 let material = try XCTUnwrap ( bar . view ( ) . subviews . first as? UIVisualEffectView )
263- // At rest and during top-edge overscroll the bar is clear; positive
264- // scroll gradually introduces the backdrop.
363+ XCTAssertEqual ( material . alpha , 0 , " Compact titles must not frost an unscrolled page " )
364+ // Scrolling, returning to rest, and pull-to-refresh all share the same
365+ // treatment as large titles; reconfiguration must preserve that depth.
265366 for offset in [ 0.0 , 6.0 , 52.0 , 12.0 , 0.0 , - 20.0 , 0.0 ] {
266367 messenger . scroll ( to : offset )
267368 bar . view ( ) . setNeedsLayout ( )
@@ -273,7 +374,10 @@ class RunnerTests: XCTestCase {
273374 XCTAssertEqual ( locations . first ? . doubleValue , 0 )
274375 XCTAssertEqual ( locations . last ? . doubleValue , 1 )
275376 XCTAssertLessThan ( locations [ 1 ] . doubleValue , 1 , " Compact material needs a soft lower edge " )
276- XCTAssertEqual ( material . alpha , min ( 1 , max ( 0 , offset ) / 12 ) , accuracy : 0.01 )
377+ XCTAssertEqual ( material . alpha , min ( 1 , max ( 0 , offset ) / 12 ) , accuracy : 0.001 )
378+ messenger . configure ( [ " title " : " general " , " subtitle " : " 37 members " ] )
379+ XCTAssertEqual ( material . alpha , min ( 1 , max ( 0 , offset ) / 12 ) , accuracy : 0.001 ,
380+ " Updating a compact title must not restore blur at rest " )
277381 XCTAssertEqual ( material . frame , bar . view ( ) . bounds )
278382 if #available( iOS 26 . 0 , * ) {
279383 let navigation = try XCTUnwrap ( parent . children . first as? UINavigationController )
@@ -1637,11 +1741,13 @@ private actor NativeEmojiDownloadProbe {
16371741
16381742private final class NavigationTestMessenger : NSObject , FlutterBinaryMessenger {
16391743 var metrics : [ String : Any ] ?
1744+ var avatarBounds : [ String : Any ] ?
16401745 var actions : [ String ] = [ ]
16411746 func send ( onChannel channel : String , message : Data ? ) {
16421747 guard let message else { return }
16431748 let call = FlutterStandardMethodCodec . sharedInstance ( ) . decodeMethodCall ( message )
16441749 if call . method == " metrics " { metrics = call . arguments as? [ String : Any ] }
1750+ if call . method == " avatarBounds " { avatarBounds = call . arguments as? [ String : Any ] }
16451751 if call . method == " action " , let action = call . arguments as? String { actions . append ( action ) }
16461752 }
16471753 func send ( onChannel channel : String , message : Data ? , binaryReply callback : FlutterBinaryReply ? ) {
@@ -1662,6 +1768,12 @@ private final class NavigationTestMessenger: NSObject, FlutterBinaryMessenger {
16621768 handler = nil
16631769 }
16641770
1771+ func invoke ( _ method : String , arguments : [ String : Any ] , reply : @escaping ( Any ? ) -> Void ) {
1772+ let codec = FlutterStandardMethodCodec . sharedInstance ( )
1773+ let message = codec . encode ( FlutterMethodCall ( methodName : method , arguments : arguments ) )
1774+ handler ? ( message ) { data in reply ( data . flatMap { codec . decodeEnvelope ( $0 ) } ) }
1775+ }
1776+
16651777 func configure ( _ arguments : [ String : Any ] ) {
16661778 let message = FlutterStandardMethodCodec . sharedInstance ( ) . encode (
16671779 FlutterMethodCall ( methodName : " configure " , arguments : arguments )
0 commit comments