mirror of
https://github.com/block/buzz.git
synced 2026-11-24 18:21:59 +00:00
Duo keeps conversations and Settings details open across closed, book and flat postures. Book mode splits at the fold; flattening restores the sidebar. Native rail controls, full-width navigation backdrops and sheet-local safe areas keep content aligned. Ordinary iPhones remain single-pane in portrait and landscape; tablet and Duo split layouts remain enabled. Includes the recovered preview's matching pane widths, Buzz empty-pane mark, stable Settings chevrons, Bestie pane routing and Duo-only upward New menu attachment. Current main's Activity redesign, Search content fade and unread-navigation button are retained. Menu selection checks sit beside their labels. Shared mobile changes remain in scope: the native iOS status editor, Appearance preview layout, avatar crop preservation, onboarding footer layout, profile/invite sheet geometry and nested conversation navigation. This PR is not exclusively Duo-gated. Nested navigator observers preserve recording cancellation and navigation callbacks; crop resizing preserves the selected image region. iOS 27.1 APIs remain compile-time and runtime gated. Validation on the reconciled source: Flutter analysis, Activity/Home journeys, the full mobile test suite, file-size checks and Swift package tests. The iPhone single-pane fix was also exercised on an iPhone 18 Pro simulator before reconciliation. Fresh hosted CI and physical-device confirmation of the reconciled build are separate and remain pending. --------- Signed-off-by: kenny lopez <klopez4212@gmail.com> Signed-off-by: Tom Brow <tomb@squareup.com> Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Tom Brow <tomb@block.xyz> Co-authored-by: Tom Brow <tomb@squareup.com>
885 lines
30 KiB
Dart
885 lines
30 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:buzz/features/pairing/pairing_provider.dart';
|
|
|
|
import '../../helpers/controllable_pairing_socket.dart';
|
|
|
|
import 'dart:async';
|
|
|
|
import 'package:buzz/features/pairing/pairing_qr_scanner.dart';
|
|
import 'package:duo_kit/testing.dart';
|
|
import 'package:buzz/features/pairing/pairing_page.dart';
|
|
|
|
import '../../helpers/widget_helpers.dart';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:mobile_scanner/mobile_scanner.dart';
|
|
|
|
const _qrScannerPlatformChannel = MethodChannel('buzz/qr_scanner');
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
final defaultScannerPlatform = MobileScannerPlatform.instance;
|
|
late _FakeMobileScannerPlatform fakeScannerPlatform;
|
|
|
|
setUp(() {
|
|
fakeScannerPlatform = _FakeMobileScannerPlatform();
|
|
MobileScannerPlatform.instance = fakeScannerPlatform;
|
|
});
|
|
|
|
tearDown(() async {
|
|
debugDefaultTargetPlatformOverride = null;
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(_qrScannerPlatformChannel, null);
|
|
await fakeScannerPlatform.dispose();
|
|
MobileScannerPlatform.instance = defaultScannerPlatform;
|
|
});
|
|
|
|
for (final (paste, cancel) in [
|
|
(false, false),
|
|
(true, false),
|
|
(false, true),
|
|
(true, true),
|
|
]) {
|
|
testWidgets('pairing entry paste=$paste cancel=$cancel permits retry', (
|
|
tester,
|
|
) async {
|
|
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(
|
|
_qrScannerPlatformChannel,
|
|
(call) async =>
|
|
call.method == 'usesDynamicIslandQrScannerPortal' ? true : null,
|
|
);
|
|
final readiness = Completer<void>();
|
|
final notifier = PairingNotifier(
|
|
socketFactory:
|
|
({
|
|
required wsUrl,
|
|
required ephemeralPrivkey,
|
|
required onMessage,
|
|
required onDisconnected,
|
|
}) => _PendingPairingSocket(
|
|
readiness.future,
|
|
ephemeralPrivkey: ephemeralPrivkey,
|
|
onMessage: onMessage,
|
|
onDisconnected: onDisconnected,
|
|
),
|
|
);
|
|
await tester.pumpWidget(
|
|
WidgetHelpers.testable(
|
|
disableAnimations: true,
|
|
overrides: [pairingProvider.overrideWith(() => notifier)],
|
|
child: PairingPage(
|
|
addingCommunity: paste,
|
|
existingUser: paste,
|
|
connectionLanding: true,
|
|
showConnectionOptions: false,
|
|
),
|
|
),
|
|
);
|
|
const code =
|
|
'nostrpair://79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'
|
|
'?secret=abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789'
|
|
'&relay=wss%3A%2F%2Fpairing.example&v=1';
|
|
if (paste) {
|
|
await tester.enterText(
|
|
find.byKey(const Key('community-pairing-input')),
|
|
code,
|
|
);
|
|
await tester.tap(find.text('Connect'));
|
|
} else {
|
|
await tester.tap(find.text('Scan a QR code'));
|
|
await tester.pump();
|
|
await tester.pump();
|
|
fakeScannerPlatform._barcodes.add(
|
|
BarcodeCapture(barcodes: [Barcode(rawValue: code)]),
|
|
);
|
|
}
|
|
await tester.pump();
|
|
await tester.pump();
|
|
await tester.pump();
|
|
expect(
|
|
find.byKey(const Key('pairing-community-loading')),
|
|
findsOneWidget,
|
|
);
|
|
expect(find.text('Scan a QR code'), findsNothing);
|
|
if (cancel) {
|
|
await tester.tap(find.text('Cancel'));
|
|
await tester.pump();
|
|
expect(
|
|
find.byKey(const Key('pairing-community-loading')),
|
|
findsNothing,
|
|
);
|
|
}
|
|
readiness.completeError(const SocketException('Network is unreachable'));
|
|
await tester.pump();
|
|
await tester.pump();
|
|
expect(
|
|
find.textContaining('Could not reach the pairing relay'),
|
|
cancel ? findsNothing : findsOneWidget,
|
|
);
|
|
if (paste) {
|
|
expect(
|
|
tester
|
|
.widget<TextField>(
|
|
find.byKey(const Key('community-pairing-input')),
|
|
)
|
|
.controller!
|
|
.text,
|
|
code,
|
|
);
|
|
expect(
|
|
tester
|
|
.widget<FilledButton>(
|
|
find.widgetWithText(FilledButton, 'Connect'),
|
|
)
|
|
.onPressed,
|
|
isNotNull,
|
|
);
|
|
} else {
|
|
expect(find.text('Scan a QR code'), findsOneWidget);
|
|
}
|
|
debugDefaultTargetPlatformOverride = null;
|
|
});
|
|
}
|
|
|
|
group('DynamicIslandQrScannerGeometry', () {
|
|
const viewport = Size(393, 852);
|
|
const geometry = DynamicIslandQrScannerGeometry(
|
|
viewport: viewport,
|
|
safeAreaTop: 59,
|
|
);
|
|
|
|
test('starts at the physical Dynamic Island frame', () {
|
|
expect(geometry.collapsedFrame, const Rect.fromLTWH(136.5, 11, 120, 36));
|
|
});
|
|
|
|
test('keeps the top edge fixed while the camera grows down', () {
|
|
final start = geometry.frameAt(0);
|
|
final middle = geometry.frameAt(0.5);
|
|
final end = geometry.frameAt(1);
|
|
|
|
expect(middle.top, start.top);
|
|
expect(end.top, start.top);
|
|
expect(middle.bottom, greaterThan(start.bottom));
|
|
expect(end.bottom, greaterThan(middle.bottom));
|
|
expect(end, const Rect.fromLTWH(15, 11, 363, 363));
|
|
});
|
|
|
|
test('delays the camera until the portal has left the island', () {
|
|
expect(geometry.scannerOpacityAt(0.18), 0);
|
|
expect(geometry.scannerOpacityAt(0.5), greaterThan(0));
|
|
expect(geometry.scannerOpacityAt(1), 1);
|
|
});
|
|
});
|
|
|
|
for (final pose in [
|
|
FoldTestPose.duoCover,
|
|
FoldTestPose.duoCoverWithOcclusions,
|
|
FoldTestPose.duoCoverLandscapeLeft,
|
|
FoldTestPose.duoCoverLandscapeRight,
|
|
FoldTestPose.duoInnerLandscape,
|
|
FoldTestPose.duoHalfOpenedLandscape,
|
|
]) {
|
|
for (final reducedMotion in [false, true]) {
|
|
testWidgets(
|
|
'Duo camera portal ${pose.name}, reduced motion $reducedMotion',
|
|
(tester) async {
|
|
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(_qrScannerPlatformChannel, (
|
|
call,
|
|
) async {
|
|
if (call.method == 'cameraCutoutFrame') {
|
|
final media = FoldTestPose.duoCoverWithOcclusions.data;
|
|
final rect = media.displayFeatures.first.bounds;
|
|
return [
|
|
rect.left,
|
|
rect.top,
|
|
rect.width,
|
|
rect.height,
|
|
media.size.width,
|
|
media.size.height,
|
|
];
|
|
}
|
|
return call.method == 'previewRotationQuarterTurns' ? -1 : null;
|
|
});
|
|
final media = pose.data;
|
|
await tester.binding.setSurfaceSize(media.size);
|
|
addTearDown(() => tester.binding.setSurfaceSize(null));
|
|
final camera =
|
|
(media.displayFeatures.isEmpty
|
|
? FoldTestPose.duoCoverWithOcclusions.data
|
|
: media)
|
|
.displayFeatures
|
|
.first
|
|
.bounds;
|
|
Rect? detectedCamera;
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
builder: (_, child) => MediaQuery(
|
|
data: media.copyWith(disableAnimations: reducedMotion),
|
|
child: child!,
|
|
),
|
|
home: Builder(
|
|
builder: (context) => TextButton(
|
|
onPressed: () async {
|
|
detectedCamera = await resolveDuoQrScannerCameraFrame(
|
|
context,
|
|
);
|
|
if (!context.mounted || detectedCamera == null) return;
|
|
showDynamicIslandPairingQrScanner(
|
|
context,
|
|
cameraFrame: detectedCamera,
|
|
);
|
|
},
|
|
child: const Text('Open scanner'),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.tap(find.text('Open scanner'));
|
|
await tester.pump();
|
|
if (pose == FoldTestPose.duoInnerLandscape ||
|
|
pose == FoldTestPose.duoHalfOpenedLandscape) {
|
|
expect(detectedCamera, isNull);
|
|
expect(
|
|
find.byKey(const ValueKey('dynamic-island-qr-scanner-portal')),
|
|
findsNothing,
|
|
);
|
|
debugDefaultTargetPlatformOverride = null;
|
|
return;
|
|
}
|
|
expect(detectedCamera, camera);
|
|
final portal = find.byKey(
|
|
const ValueKey('dynamic-island-qr-scanner-portal'),
|
|
);
|
|
if (!reducedMotion) {
|
|
final onBottom = camera.center.dy > media.size.height / 2;
|
|
final pill = Rect.fromLTRB(
|
|
camera.left,
|
|
camera.top - (onBottom ? 22 : 4),
|
|
camera.right,
|
|
camera.bottom + (onBottom ? 4 : 22),
|
|
);
|
|
expect(tester.getRect(portal), pill);
|
|
expect(
|
|
tester.widget<ClipRSuperellipse>(portal).borderRadius,
|
|
BorderRadius.circular(camera.shortestSide / 2),
|
|
);
|
|
}
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester
|
|
.widget<RotatedBox>(
|
|
find.byKey(const ValueKey('qr-camera-orientation')),
|
|
)
|
|
.quarterTurns,
|
|
-1,
|
|
);
|
|
final expanded = tester.getRect(portal);
|
|
if (camera.top == 0 && camera.right == media.size.width) {
|
|
expect(expanded.right, lessThan(camera.left));
|
|
} else {
|
|
expect(expanded.contains(camera.center), isTrue);
|
|
final right = camera.center.dx > media.size.width / 2;
|
|
final bottom = camera.center.dy > media.size.height / 2;
|
|
expect(
|
|
right ? expanded.right : expanded.left,
|
|
right ? camera.right : camera.left,
|
|
);
|
|
expect(
|
|
bottom ? expanded.bottom : expanded.top,
|
|
bottom ? camera.bottom + 4 : camera.top - 4,
|
|
);
|
|
final radii = tester
|
|
.widget<ClipRSuperellipse>(portal)
|
|
.borderRadius
|
|
.resolve(TextDirection.ltr);
|
|
final corner = bottom
|
|
? (right ? radii.bottomRight : radii.bottomLeft)
|
|
: (right ? radii.topRight : radii.topLeft);
|
|
expect(corner, Radius.circular(camera.shortestSide / 2));
|
|
}
|
|
expect((Offset.zero & media.size).contains(expanded.topLeft), isTrue);
|
|
expect(
|
|
(Offset.zero & media.size).contains(expanded.bottomRight),
|
|
isTrue,
|
|
);
|
|
expect(expanded.width, expanded.height);
|
|
await tester.tapAt(expanded.center);
|
|
await tester.pump();
|
|
if (!reducedMotion) {
|
|
await tester.pump(const Duration(milliseconds: 300));
|
|
final closing = tester.getRect(portal);
|
|
expect(
|
|
(closing.center - camera.center).distance,
|
|
lessThan((expanded.center - camera.center).distance),
|
|
);
|
|
expect(closing.width, lessThan(expanded.width));
|
|
}
|
|
await tester.pumpAndSettle();
|
|
expect(portal, findsNothing);
|
|
expect(fakeScannerPlatform._isDisposed, isTrue);
|
|
expect(tester.takeException(), isNull);
|
|
debugDefaultTargetPlatformOverride = null;
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
group('usesDynamicIslandQrScannerPortal', () {
|
|
test('asks the native bridge on iOS', () async {
|
|
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(_qrScannerPlatformChannel, (call) async {
|
|
expect(call.method, 'usesDynamicIslandQrScannerPortal');
|
|
return true;
|
|
});
|
|
|
|
expect(await usesDynamicIslandQrScannerPortal(), isTrue);
|
|
});
|
|
|
|
test('uses the fallback without asking native code on Android', () async {
|
|
debugDefaultTargetPlatformOverride = TargetPlatform.android;
|
|
var nativeCalls = 0;
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(_qrScannerPlatformChannel, (call) async {
|
|
nativeCalls += 1;
|
|
return true;
|
|
});
|
|
|
|
expect(await usesDynamicIslandQrScannerPortal(), isFalse);
|
|
expect(nativeCalls, 0);
|
|
});
|
|
});
|
|
|
|
testWidgets('fallback reveals the camera behind the current app surface', (
|
|
tester,
|
|
) async {
|
|
await tester.binding.setSurfaceSize(const Size(375, 667));
|
|
addTearDown(() => tester.binding.setSurfaceSize(null));
|
|
|
|
var scannerClosed = false;
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: FallbackPairingQrScanner(
|
|
appSurface: const ColoredBox(
|
|
color: Colors.white,
|
|
child: Center(child: Text('Current app surface')),
|
|
),
|
|
onClosed: (_) {
|
|
scannerClosed = true;
|
|
},
|
|
),
|
|
),
|
|
);
|
|
|
|
final sheet = find.byKey(const ValueKey('fallback-qr-scanner-app-sheet'));
|
|
expect(tester.getRect(sheet).top, 0);
|
|
expect(find.text('Current app surface'), findsOneWidget);
|
|
|
|
await tester.pump(const Duration(milliseconds: 420));
|
|
expect(tester.getRect(sheet).top, closeTo(555, 0.1));
|
|
|
|
await tester.binding.setSurfaceSize(const Size(951, 669));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester.getRect(find.text('Scan a QR code')).bottom,
|
|
lessThan(tester.getRect(sheet).top),
|
|
);
|
|
|
|
expect(
|
|
tester.getRect(find.byKey(const ValueKey('fallback-qr-scanner-mask'))),
|
|
const Rect.fromLTWH(0, 0, 951, 669),
|
|
);
|
|
|
|
await tester.tapAt(const Offset(187.5, 100));
|
|
await tester.pump();
|
|
expect(scannerClosed, isFalse);
|
|
|
|
await tester.pump(const Duration(milliseconds: 320));
|
|
await tester.pumpAndSettle();
|
|
expect(scannerClosed, isTrue);
|
|
expect(tester.getRect(sheet).top, 0);
|
|
});
|
|
|
|
testWidgets(
|
|
'portal route opens from the island and an outside tap reverses it closed',
|
|
(tester) async {
|
|
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(_qrScannerPlatformChannel, (call) async {
|
|
return switch (call.method) {
|
|
'usesDynamicIslandQrScannerPortal' => true,
|
|
'setDynamicIslandScannerStatusBarHidden' => null,
|
|
_ => null,
|
|
};
|
|
});
|
|
await tester.binding.setSurfaceSize(const Size(393, 852));
|
|
addTearDown(() => tester.binding.setSurfaceSize(null));
|
|
|
|
final cameraStart = Completer<void>();
|
|
fakeScannerPlatform.startGate = cameraStart.future;
|
|
var scannerClosed = false;
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: MediaQuery(
|
|
data: const MediaQueryData(
|
|
size: Size(393, 852),
|
|
viewPadding: EdgeInsets.only(top: 59),
|
|
),
|
|
child: Builder(
|
|
builder: (context) => TextButton(
|
|
onPressed: () async {
|
|
await showDynamicIslandPairingQrScanner(context);
|
|
scannerClosed = true;
|
|
},
|
|
child: const Text('Open scanner'),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.tap(find.text('Open scanner'));
|
|
await tester.pump();
|
|
|
|
final portal = find.byKey(
|
|
const ValueKey('dynamic-island-qr-scanner-portal'),
|
|
);
|
|
expect(tester.getRect(portal), const Rect.fromLTWH(136.5, 11, 120, 36));
|
|
final prompt = find
|
|
.ancestor(
|
|
of: find.text('Scan a QR code'),
|
|
matching: find.byType(Opacity),
|
|
)
|
|
.first;
|
|
final camera = find
|
|
.ancestor(
|
|
of: find.byType(MobileScanner),
|
|
matching: find.byType(Opacity),
|
|
)
|
|
.first;
|
|
expect(tester.widget<Opacity>(prompt).opacity, 0);
|
|
expect(find.byType(MobileScanner), findsOneWidget);
|
|
await tester.pump();
|
|
expect(fakeScannerPlatform.startCalls, 1);
|
|
expect(
|
|
tester.widget<ClipRSuperellipse>(portal).borderRadius,
|
|
BorderRadius.circular(18),
|
|
);
|
|
expect(
|
|
tester.widget<ClipRSuperellipse>(portal).clipBehavior,
|
|
Clip.antiAlias,
|
|
);
|
|
|
|
await tester.pump(const Duration(milliseconds: 12));
|
|
final firstOpeningFrame = tester.getRect(portal);
|
|
expect(firstOpeningFrame.height, inExclusiveRange(36, 363));
|
|
await tester.pump(const Duration(milliseconds: 218));
|
|
expect(
|
|
tester.widget<Opacity>(prompt).opacity,
|
|
tester.widget<Opacity>(camera).opacity,
|
|
);
|
|
expect(tester.widget<Opacity>(prompt).opacity, inExclusiveRange(0, 1));
|
|
expect(
|
|
tester.getRect(portal).height,
|
|
greaterThan(firstOpeningFrame.height),
|
|
);
|
|
final openingRadius =
|
|
(tester.widget<ClipRSuperellipse>(portal).borderRadius
|
|
as BorderRadius)
|
|
.topLeft
|
|
.x;
|
|
expect(openingRadius, inExclusiveRange(18, 40));
|
|
|
|
await tester.pumpAndSettle();
|
|
final readyFade = find.byKey(const ValueKey('qr-camera-ready-fade'));
|
|
final previewFade = find
|
|
.descendant(of: readyFade, matching: find.byType(FadeTransition))
|
|
.first;
|
|
expect(tester.widget<FadeTransition>(previewFade).opacity.value, 0);
|
|
cameraStart.complete();
|
|
await tester.pump();
|
|
await tester.pump();
|
|
await tester.pump(const Duration(milliseconds: 60));
|
|
expect(
|
|
tester.widget<FadeTransition>(previewFade).opacity.value,
|
|
inExclusiveRange(0, 1),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(tester.widget<FadeTransition>(previewFade).opacity.value, 1);
|
|
expect(
|
|
tester.widget<ClipRSuperellipse>(portal).borderRadius,
|
|
BorderRadius.circular(40),
|
|
);
|
|
expect(tester.getRect(portal).top, 11);
|
|
expect(
|
|
find.byKey(const ValueKey('dynamic-island-qr-scanner-close')),
|
|
findsNothing,
|
|
);
|
|
|
|
await tester.tapAt(const Offset(196.5, 700));
|
|
await tester.pump();
|
|
expect(scannerClosed, isFalse);
|
|
expect(find.byType(MobileScanner), findsOneWidget);
|
|
|
|
await tester.pump(const Duration(milliseconds: 100));
|
|
final earlyClosingHeight = tester.getRect(portal).height;
|
|
expect(earlyClosingHeight, lessThan(280));
|
|
expect(find.byType(MobileScanner), findsOneWidget);
|
|
await tester.pump(const Duration(milliseconds: 100));
|
|
final lateClosingHeight = tester.getRect(portal).height;
|
|
// Keep native camera teardown outside the closing animation.
|
|
expect(find.byType(MobileScanner), findsOneWidget);
|
|
expect(
|
|
tester
|
|
.widget<Opacity>(
|
|
find
|
|
.ancestor(
|
|
of: find.byType(MobileScanner),
|
|
matching: find.byType(Opacity),
|
|
)
|
|
.first,
|
|
)
|
|
.opacity,
|
|
0,
|
|
);
|
|
expect(fakeScannerPlatform.stopCalls, 0);
|
|
expect(fakeScannerPlatform._isDisposed, isFalse);
|
|
expect(lateClosingHeight, lessThan(earlyClosingHeight));
|
|
expect(lateClosingHeight, greaterThan(36));
|
|
// The final approach is slower than the initial collapse, not an impact.
|
|
expect(lateClosingHeight - 36, lessThan((363 - earlyClosingHeight) / 4));
|
|
final closingRadius =
|
|
(tester.widget<ClipRSuperellipse>(portal).borderRadius
|
|
as BorderRadius)
|
|
.topLeft
|
|
.x;
|
|
expect(closingRadius, inExclusiveRange(18, 40));
|
|
await tester.pump(const Duration(milliseconds: 170));
|
|
await tester.pumpAndSettle();
|
|
expect(scannerClosed, isTrue);
|
|
expect(portal, findsNothing);
|
|
expect(fakeScannerPlatform._isDisposed, isTrue);
|
|
debugDefaultTargetPlatformOverride = null;
|
|
},
|
|
);
|
|
|
|
testWidgets('welcome and Add follow the scanner spring and return on close', (
|
|
tester,
|
|
) async {
|
|
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(_qrScannerPlatformChannel, (call) async {
|
|
return call.method == 'usesDynamicIslandQrScannerPortal'
|
|
? true
|
|
: null;
|
|
});
|
|
await tester.binding.setSurfaceSize(const Size(393, 852));
|
|
addTearDown(() => tester.binding.setSurfaceSize(null));
|
|
for (final (reduced, adding) in [
|
|
(false, false),
|
|
(true, false),
|
|
(false, true),
|
|
(true, true),
|
|
]) {
|
|
await tester.pumpWidget(
|
|
WidgetHelpers.testable(
|
|
disableAnimations: reduced,
|
|
child: PairingPage(
|
|
addingCommunity: adding,
|
|
connectionLanding: true,
|
|
showConnectionOptions: false,
|
|
),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
final opacity = find.byKey(const Key('scanner-welcome-opacity'));
|
|
final scale = find.byKey(const Key('scanner-welcome-scale'));
|
|
void expectBeesMatchWelcome() {
|
|
if (adding) return;
|
|
expect(
|
|
tester
|
|
.widget<Opacity>(find.byKey(const Key('scanner-bees-opacity')))
|
|
.opacity,
|
|
tester.widget<Opacity>(opacity).opacity,
|
|
);
|
|
expect(
|
|
tester
|
|
.widget<Transform>(find.byKey(const Key('scanner-bees-scale')))
|
|
.transform
|
|
.storage[0],
|
|
tester.widget<Transform>(scale).transform.storage[0],
|
|
);
|
|
}
|
|
|
|
// The welcome swarm animates continuously. Wait for the scanner's
|
|
// observable transition endpoint rather than global frame idleness.
|
|
Future<void> waitForOpacity(double target) async {
|
|
for (
|
|
var frame = 0;
|
|
frame < 120 &&
|
|
(tester.widget<Opacity>(opacity).opacity != target ||
|
|
(target == 1 &&
|
|
find
|
|
.byKey(
|
|
const ValueKey('dynamic-island-qr-scanner-portal'),
|
|
)
|
|
.evaluate()
|
|
.isNotEmpty));
|
|
frame++
|
|
) {
|
|
await tester.pump(const Duration(milliseconds: 16));
|
|
}
|
|
expect(tester.widget<Opacity>(opacity).opacity, target);
|
|
}
|
|
|
|
expect(tester.widget<Opacity>(opacity).opacity, 1);
|
|
if (adding) {
|
|
// Only foreground controls transition; the opaque page stays fixed.
|
|
expect(
|
|
find.descendant(of: opacity, matching: find.byType(Scaffold)),
|
|
findsNothing,
|
|
);
|
|
expect(
|
|
find.ancestor(of: opacity, matching: find.byType(Scaffold)),
|
|
findsWidgets,
|
|
);
|
|
}
|
|
await tester.tap(find.text('Scan a QR code').hitTestable());
|
|
await tester.pump();
|
|
// Opening must begin without waiting for the welcome double-tap timeout.
|
|
expect(
|
|
find.byKey(const ValueKey('dynamic-island-qr-scanner-portal')),
|
|
findsOneWidget,
|
|
);
|
|
await tester.pump(const Duration(milliseconds: 100));
|
|
if (!reduced) {
|
|
final portal = find.byKey(
|
|
const ValueKey('dynamic-island-qr-scanner-portal'),
|
|
);
|
|
final progress = (tester.getSize(portal).height - 36) / (363 - 36);
|
|
expect(
|
|
tester.widget<Opacity>(opacity).opacity,
|
|
closeTo(1 - progress, 0.001),
|
|
);
|
|
expect(
|
|
tester.widget<Transform>(scale).transform.storage[0],
|
|
closeTo(1 - 0.04 * progress, 0.001),
|
|
);
|
|
}
|
|
expectBeesMatchWelcome();
|
|
await waitForOpacity(0);
|
|
expectBeesMatchWelcome();
|
|
expect(tester.widget<Opacity>(opacity).opacity, 0);
|
|
expect(
|
|
tester.widget<Transform>(scale).transform.storage[0],
|
|
closeTo(reduced ? 1 : 0.96, 0.001),
|
|
);
|
|
expect(
|
|
find
|
|
.ancestor(
|
|
of: find.text('Scan a QR code'),
|
|
matching: find.byType(FilledButton),
|
|
)
|
|
.hitTestable(),
|
|
findsNothing,
|
|
);
|
|
await tester.tapAt(const Offset(196.5, 700));
|
|
await tester.pump();
|
|
await waitForOpacity(1);
|
|
expectBeesMatchWelcome();
|
|
expect(tester.widget<Opacity>(opacity).opacity, 1);
|
|
expect(tester.widget<Transform>(scale).transform.storage[0], 1);
|
|
expect(
|
|
find
|
|
.ancestor(
|
|
of: find.text('Scan a QR code'),
|
|
matching: find.byType(FilledButton),
|
|
)
|
|
.hitTestable(),
|
|
findsOneWidget,
|
|
);
|
|
expect(tester.takeException(), isNull);
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
await tester.pumpAndSettle();
|
|
}
|
|
debugDefaultTargetPlatformOverride = null;
|
|
});
|
|
|
|
testWidgets(
|
|
'an early dismissal keeps its frame and settles back into the island',
|
|
(tester) async {
|
|
await tester.binding.setSurfaceSize(const Size(393, 852));
|
|
addTearDown(() => tester.binding.setSurfaceSize(null));
|
|
var closeCount = 0;
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Builder(
|
|
builder: (context) => TextButton(
|
|
onPressed: () async {
|
|
await showDynamicIslandPairingQrScanner(context);
|
|
closeCount++;
|
|
},
|
|
child: const Text('Open scanner'),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.tap(find.text('Open scanner'));
|
|
await tester.pump();
|
|
await tester.pump(const Duration(milliseconds: 72));
|
|
final portal = find.byKey(
|
|
const ValueKey('dynamic-island-qr-scanner-portal'),
|
|
);
|
|
final beforeLastOpeningFrame = tester.getRect(portal);
|
|
await tester.pump(const Duration(milliseconds: 8));
|
|
final beforeDismissal = tester.getRect(portal);
|
|
await tester.tapAt(const Offset(196.5, 700));
|
|
await tester.pump();
|
|
expect(
|
|
tester.getRect(portal),
|
|
rectMoreOrLessEquals(beforeDismissal, epsilon: 0.00001),
|
|
);
|
|
// Preserve the outgoing velocity briefly instead of abruptly flipping it.
|
|
await tester.pump(const Duration(milliseconds: 8));
|
|
final afterDismissal = tester.getRect(portal);
|
|
expect(afterDismissal.height, greaterThan(beforeDismissal.height));
|
|
// Reversing decelerates the outgoing motion over an equal frame interval.
|
|
expect(
|
|
afterDismissal.height - beforeDismissal.height,
|
|
lessThan(beforeDismissal.height - beforeLastOpeningFrame.height),
|
|
);
|
|
await tester.tapAt(const Offset(196.5, 700));
|
|
await tester.pumpAndSettle();
|
|
expect(closeCount, 1);
|
|
expect(portal, findsNothing);
|
|
expect(find.text('Open scanner'), findsOneWidget);
|
|
expect(tester.takeException(), isNull);
|
|
},
|
|
);
|
|
|
|
testWidgets('tapping the scanner closes it without a separate control', (
|
|
tester,
|
|
) async {
|
|
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(_qrScannerPlatformChannel, (call) async {
|
|
return switch (call.method) {
|
|
'usesDynamicIslandQrScannerPortal' => true,
|
|
'setDynamicIslandScannerStatusBarHidden' => null,
|
|
_ => null,
|
|
};
|
|
});
|
|
await tester.binding.setSurfaceSize(const Size(393, 852));
|
|
addTearDown(() => tester.binding.setSurfaceSize(null));
|
|
|
|
var scannerClosed = false;
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
builder: (context, child) => MediaQuery(
|
|
data: MediaQuery.of(context).copyWith(disableAnimations: true),
|
|
child: child!,
|
|
),
|
|
home: Builder(
|
|
builder: (context) => TextButton(
|
|
onPressed: () async {
|
|
await showDynamicIslandPairingQrScanner(context);
|
|
scannerClosed = true;
|
|
},
|
|
child: const Text('Open scanner'),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.tap(find.text('Open scanner'));
|
|
await tester.pump();
|
|
|
|
final portal = find.byKey(
|
|
const ValueKey('dynamic-island-qr-scanner-portal'),
|
|
);
|
|
expect(tester.getRect(portal), const Rect.fromLTWH(15, 11, 363, 363));
|
|
expect(
|
|
tester.widget<ClipRSuperellipse>(portal).borderRadius,
|
|
BorderRadius.circular(40),
|
|
);
|
|
|
|
await tester.tapAt(tester.getCenter(portal));
|
|
await tester.pump();
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(scannerClosed, isTrue);
|
|
expect(portal, findsNothing);
|
|
debugDefaultTargetPlatformOverride = null;
|
|
});
|
|
}
|
|
|
|
class _FakeMobileScannerPlatform extends MobileScannerPlatform {
|
|
final _barcodes = StreamController<BarcodeCapture?>.broadcast();
|
|
var _isDisposed = false;
|
|
var stopCalls = 0;
|
|
var startCalls = 0;
|
|
Future<void>? startGate;
|
|
|
|
@override
|
|
Stream<BarcodeCapture?> get barcodesStream => _barcodes.stream;
|
|
|
|
@override
|
|
Stream<TorchState> get torchStateStream =>
|
|
Stream.value(TorchState.unavailable);
|
|
|
|
@override
|
|
Stream<double> get zoomScaleStateStream => Stream.value(1);
|
|
|
|
@override
|
|
Future<MobileScannerViewAttributes> start(StartOptions startOptions) async {
|
|
startCalls++;
|
|
await startGate;
|
|
return const MobileScannerViewAttributes(
|
|
cameraDirection: CameraFacing.back,
|
|
currentTorchMode: TorchState.unavailable,
|
|
size: Size(200, 200),
|
|
numberOfCameras: 1,
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget buildCameraView() => const SizedBox.expand();
|
|
|
|
@override
|
|
Future<void> stop() async {
|
|
stopCalls++;
|
|
}
|
|
|
|
@override
|
|
Future<void> dispose() async {
|
|
if (_isDisposed) {
|
|
return;
|
|
}
|
|
_isDisposed = true;
|
|
await _barcodes.close();
|
|
}
|
|
}
|
|
|
|
class _PendingPairingSocket extends ControllablePairingSocket {
|
|
_PendingPairingSocket(
|
|
this.readiness, {
|
|
required super.ephemeralPrivkey,
|
|
required super.onMessage,
|
|
required super.onDisconnected,
|
|
});
|
|
final Future<void> readiness;
|
|
@override
|
|
Future<void> connect() async {
|
|
await readiness;
|
|
await super.connect();
|
|
}
|
|
}
|