Files
buzz/mobile/test/features/profile/set_status_sheet_test.dart
klopez4212 cb69ad9e4f Adapt iPhone Duo layouts, rail navigation, and native sheets (#8568)
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>
2026-11-12 19:00:58 +00:00

423 lines
14 KiB
Dart

import 'package:buzz/features/profile/set_status_sheet.dart';
import 'package:buzz/features/profile/user_status.dart';
import 'package:buzz/features/profile/user_status_provider.dart';
import 'package:buzz/shared/custom_emoji/custom_emoji_provider.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:buzz/shared/theme/buzz_icons.dart';
import '../../helpers/widget_helpers.dart';
void main() {
testWidgets(
'iOS status uses native form, retains failed draft, saves and clears',
(tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
addTearDown(() => debugDefaultTargetPlatformOverride = null);
const channel = MethodChannel('buzz/profile_text_editor');
final calls = <Map<dynamic, dynamic>>[];
final notifier = _RecordingUserStatusNotifier()..failNext = true;
final expiration = DateTime.now().add(const Duration(days: 3));
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (call) async {
expect(call.method, 'presentStatus');
calls.add(call.arguments as Map<dynamic, dynamic>);
if (calls.length == 3) return {'clear': true};
if (calls.length == 4) return null;
return {
'text': 'Focused',
'emoji': ':buzz:',
'duration': 0,
'expiresAt': expiration.millisecondsSinceEpoch / 1000,
'clear': false,
};
});
addTearDown(
() => TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, null),
);
await tester.pumpWidget(
WidgetHelpers.testable(
overrides: [
customEmojiListProvider.overrideWithValue(const []),
userStatusProvider.overrideWith(() => notifier),
],
child: Builder(
builder: (context) => FilledButton(
onPressed: () => showSetStatusSheet(
context,
currentStatus: const UserStatus(
text: 'Old',
emoji: '🎯',
updatedAt: 1,
),
),
child: const Text('Open'),
),
),
),
);
await tester.tap(find.text('Open'));
await tester.pumpAndSettle();
expect(calls, hasLength(2));
expect(calls.first['text'], 'Old');
expect(calls[1]['text'], 'Focused');
expect(calls[1]['emoji'], ':buzz:');
expect(calls[1]['saveError'], true);
expect(notifier.savedText, 'Focused');
expect(
notifier.savedExpiresAt?.millisecondsSinceEpoch,
expiration.millisecondsSinceEpoch,
);
expect(find.byType(BottomSheet), findsNothing);
await tester.tap(find.text('Open'));
await tester.pumpAndSettle();
expect(notifier.savedText, '');
expect(notifier.savedEmoji, '');
await tester.tap(find.text('Open'));
await tester.pumpAndSettle();
expect(calls, hasLength(4));
expect(notifier.savedText, '');
debugDefaultTargetPlatformOverride = null;
},
);
for (final invalidExpiration in <Object?>[
9_000_000_000_000,
-9_000_000_000_000,
double.nan,
double.infinity,
'tomorrow',
null,
]) {
testWidgets('iOS recovers from invalid expiration $invalidExpiration', (
tester,
) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
addTearDown(() => debugDefaultTargetPlatformOverride = null);
const channel = MethodChannel('buzz/profile_text_editor');
final calls = <Map<dynamic, dynamic>>[];
final notifier = _RecordingUserStatusNotifier();
final expiration = DateTime.now().add(const Duration(days: 1));
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (call) async {
expect(call.method, 'presentStatus');
final draft = call.arguments as Map<dynamic, dynamic>;
calls.add(draft);
// Bound the mock so a regression reports a failure, not a hang.
if (calls.length > 2) return null;
expect(draft['duration'], 86400);
expect(draft['expiresAt'], isNull);
if (calls.length == 2) {
expect(draft['text'], 'Edited');
expect(draft['emoji'], '🎯');
expect(draft['saveError'], true);
expect(notifier.savedText, isNull);
}
return {
'text': 'Edited',
'emoji': '🎯',
'duration': calls.length == 1 ? 0 : draft['duration'],
'expiresAt': calls.length == 1
? invalidExpiration
: expiration.millisecondsSinceEpoch / 1000,
};
});
addTearDown(
() => TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, null),
);
await tester.pumpWidget(
WidgetHelpers.testable(
overrides: [userStatusProvider.overrideWith(() => notifier)],
child: Builder(
builder: (context) => FilledButton(
onPressed: () => showSetStatusSheet(
context,
currentStatus: const UserStatus(
text: 'Old',
emoji: '',
updatedAt: 1,
expiresAt: 9_000_000_000_000,
),
),
child: const Text('Open'),
),
),
),
);
await tester.tap(find.text('Open'));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
expect(calls, hasLength(2));
expect(notifier.savedText, 'Edited');
expect(notifier.savedEmoji, '🎯');
expect(
notifier.savedExpiresAt?.millisecondsSinceEpoch,
expiration.millisecondsSinceEpoch,
);
debugDefaultTargetPlatformOverride = null;
});
}
testWidgets('keeps its resting top edge when the keyboard appears', (
tester,
) async {
addTearDown(tester.view.reset);
await tester.pumpWidget(
WidgetHelpers.testable(
overrides: [
customEmojiListProvider.overrideWithValue(const []),
userStatusProvider.overrideWith(() => _RecordingUserStatusNotifier()),
],
child: Builder(
builder: (context) => FilledButton(
onPressed: () => showSetStatusSheet(context),
child: const Text('Open status editor'),
),
),
),
);
await tester.tap(find.text('Open status editor'));
await tester.pumpAndSettle();
final restingTop = tester.getTopLeft(find.byType(BottomSheet)).dy;
tester.view.viewInsets = const FakeViewPadding(bottom: 300);
await tester.pumpAndSettle();
expect(
tester.getTopLeft(find.byType(BottomSheet)).dy,
closeTo(restingTop, 0.01),
);
});
testWidgets('uses Buzz rows, desktop presets, and a real duration', (
tester,
) async {
final statusNotifier = _RecordingUserStatusNotifier();
await tester.pumpWidget(
WidgetHelpers.testable(
overrides: [
customEmojiListProvider.overrideWithValue(const []),
userStatusProvider.overrideWith(() => statusNotifier),
],
child: Builder(
builder: (context) => FilledButton(
onPressed: () => showSetStatusSheet(
context,
currentStatus: const UserStatus(
text: 'Focusing',
emoji: '\u{1F3AF}',
updatedAt: 1,
),
),
child: const Text('Open status editor'),
),
),
),
);
await tester.tap(find.text('Open status editor'));
await tester.pumpAndSettle();
expect(find.text('\u{1F3AF}'), findsOneWidget);
expect(find.byTooltip('Remove status emoji'), findsOneWidget);
expect(find.byKey(const ValueKey('status-input-outline')), findsOneWidget);
expect(find.text('Visible in chats to everyone'), findsNothing);
expect(find.text('Let others know what you\u2019re up to.'), findsNothing);
expect(find.text('1 day'), findsOneWidget);
expect(find.text('In a meeting'), findsOneWidget);
expect(find.text('Commuting'), findsOneWidget);
expect(find.text('Out sick'), findsOneWidget);
expect(find.text('Vacationing'), findsOneWidget);
expect(find.text('Working remotely'), findsOneWidget);
await tester.tap(find.text('1 day'));
await tester.pumpAndSettle();
expect(find.text('1 hour'), findsOneWidget);
expect(find.text('8 hours'), findsOneWidget);
expect(find.text('1 week'), findsOneWidget);
expect(find.text('Custom'), findsOneWidget);
await tester.tap(find.text('8 hours'));
await tester.pumpAndSettle();
expect(find.text('8 hours'), findsOneWidget);
await tester.tap(find.byTooltip('Remove status emoji'));
await tester.pump();
expect(find.text('\u{1F3AF}'), findsNothing);
expect(find.byIcon(BuzzIcons.smilePlus), findsOneWidget);
expect(
tester.widget<TextField>(find.byType(TextField)).controller?.text,
'Focusing',
);
final beforeSave = DateTime.now();
await tester.tap(find.byTooltip('Save status'));
await tester.pumpAndSettle();
expect(statusNotifier.savedText, 'Focusing');
expect(statusNotifier.savedEmoji, isEmpty);
expect(statusNotifier.savedExpiresAt, isNotNull);
expect(
statusNotifier.savedExpiresAt!.difference(beforeSave).inSeconds,
inInclusiveRange(
const Duration(hours: 8).inSeconds - 2,
const Duration(hours: 8).inSeconds + 2,
),
);
});
testWidgets('opens with an out-of-range remote expiration', (tester) async {
await tester.pumpWidget(
WidgetHelpers.testable(
overrides: [
customEmojiListProvider.overrideWithValue(const []),
userStatusProvider.overrideWith(() => _RecordingUserStatusNotifier()),
],
child: Builder(
builder: (context) => FilledButton(
onPressed: () => showSetStatusSheet(
context,
currentStatus: const UserStatus(
text: 'Focusing',
emoji: '',
updatedAt: 1,
expiresAt: 9_000_000_000_000,
),
),
child: const Text('Open status editor'),
),
),
),
);
await tester.tap(find.text('Open status editor'));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
expect(find.text('Focusing'), findsOneWidget);
expect(find.text('1 day'), findsOneWidget);
});
testWidgets('clamps an existing custom date to the Android picker range', (
tester,
) async {
debugDefaultTargetPlatformOverride = TargetPlatform.android;
addTearDown(() => debugDefaultTargetPlatformOverride = null);
final expiresAt = DateTime.now().add(const Duration(days: 730));
await tester.pumpWidget(
WidgetHelpers.testable(
overrides: [
customEmojiListProvider.overrideWithValue(const []),
userStatusProvider.overrideWith(() => _RecordingUserStatusNotifier()),
],
child: Builder(
builder: (context) => FilledButton(
onPressed: () => showSetStatusSheet(
context,
currentStatus: UserStatus(
text: 'Sabbatical',
emoji: '\u{1F3DD}\u{FE0F}',
updatedAt: 1,
expiresAt: expiresAt.millisecondsSinceEpoch ~/ 1000,
),
),
child: const Text('Open status editor'),
),
),
),
);
await tester.tap(find.text('Open status editor'));
await tester.pumpAndSettle();
await tester.tap(find.text('Until'));
await tester.pumpAndSettle();
final picker = tester.widget<DatePickerDialog>(
find.byType(DatePickerDialog),
);
expect(picker.initialDate, picker.lastDate);
debugDefaultTargetPlatformOverride = null;
});
testWidgets('custom duration reveals the native until picker', (
tester,
) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
addTearDown(() => debugDefaultTargetPlatformOverride = null);
const channel = MethodChannel('buzz/profile_text_editor');
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
channel,
(_) async => throw MissingPluginException(),
);
addTearDown(
() => TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, null),
);
final statusNotifier = _RecordingUserStatusNotifier();
await tester.pumpWidget(
WidgetHelpers.testable(
overrides: [
customEmojiListProvider.overrideWithValue(const []),
userStatusProvider.overrideWith(() => statusNotifier),
],
child: Builder(
builder: (context) => FilledButton(
onPressed: () => showSetStatusSheet(context),
child: const Text('Open status editor'),
),
),
),
);
await tester.tap(find.text('Open status editor'));
await tester.pumpAndSettle();
await tester.tap(find.text('1 day'));
await tester.pumpAndSettle();
await tester.ensureVisible(find.text('Custom'));
await tester.pumpAndSettle();
await tester.tap(find.text('Custom'));
await tester.pumpAndSettle();
expect(find.byType(CupertinoDatePicker), findsOneWidget);
await tester.tap(find.text('Done'));
await tester.pumpAndSettle();
expect(find.text('Custom'), findsOneWidget);
expect(find.text('Until'), findsOneWidget);
debugDefaultTargetPlatformOverride = null;
});
}
class _RecordingUserStatusNotifier extends UserStatusNotifier {
bool failNext = false;
String? savedText;
String? savedEmoji;
DateTime? savedExpiresAt;
@override
Future<UserStatus?> build() async => null;
@override
Future<void> setStatus(
String text,
String emoji, {
DateTime? expiresAt,
}) async {
if (failNext) {
failNext = false;
throw StateError('publish failed');
}
savedText = text;
savedEmoji = emoji;
savedExpiresAt = expiresAt;
}
}