mirror of
https://github.com/block/buzz.git
synced 2026-11-25 18:52:52 +00:00
## Summary Adds Buzzies and refreshes the agent avatar picker with larger previews, rounded option strips, and clearer category choices. Also moves Agents above Appearance in the home menu and adds a custom agent icon. ### Related issue None found. ### Testing Analysis, 4,138 app tests, package tests, and 121 configured-auth tests pass. Earlier visual build exercised on Pixel and iOS simulator, with iPhone review; snapshots below show that build. | Android · Pixel | iOS · simulator preview | | --- | --- | |  |  | --------- Signed-off-by: kenny lopez <klopez4212@gmail.com> Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
268 lines
9.3 KiB
Dart
268 lines
9.3 KiB
Dart
import 'package:buzz/shared/widgets/preset_agent_avatar.dart';
|
|
import 'package:buzz/shared/widgets/avatar_image.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:video_player_platform_interface/video_player_platform_interface.dart';
|
|
|
|
class _Player extends VideoPlayerPlatform {
|
|
bool playing = false;
|
|
double volume = 1;
|
|
Duration position = Duration.zero;
|
|
@override
|
|
Future<void> init() async {}
|
|
@override
|
|
Future<int?> createWithOptions(VideoCreationOptions options) async => 1;
|
|
@override
|
|
Stream<VideoEvent> videoEventsFor(int id) {
|
|
return Stream.value(
|
|
VideoEvent(
|
|
eventType: VideoEventType.initialized,
|
|
duration: const Duration(seconds: 2),
|
|
size: const Size(100, 100),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget buildView(int id) => const SizedBox(key: Key('video'));
|
|
@override
|
|
Future<void> play(int id) async {
|
|
playing = true;
|
|
}
|
|
|
|
@override
|
|
Future<void> pause(int id) async {
|
|
playing = false;
|
|
}
|
|
|
|
@override
|
|
Future<void> setLooping(int id, bool looping) async {}
|
|
@override
|
|
Future<void> setVolume(int id, double value) async {
|
|
volume = value;
|
|
}
|
|
|
|
@override
|
|
Future<void> setPlaybackSpeed(int id, double speed) async {}
|
|
@override
|
|
Future<void> setMixWithOthers(bool value) async {}
|
|
@override
|
|
Future<Duration> getPosition(int id) async => position;
|
|
@override
|
|
Future<void> dispose(int id) async {}
|
|
}
|
|
|
|
void main() {
|
|
testWidgets(
|
|
'preset plays silently, pauses when hidden, and respects reduced motion',
|
|
(tester) async {
|
|
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
|
addTearDown(() => debugDefaultTargetPlatformOverride = null);
|
|
final original = VideoPlayerPlatform.instance;
|
|
final player = _Player();
|
|
VideoPlayerPlatform.instance = player;
|
|
addTearDown(() => VideoPlayerPlatform.instance = original);
|
|
Widget surface({
|
|
bool visible = true,
|
|
bool reduced = false,
|
|
bool preparedPoster = false,
|
|
}) => ProviderScope(
|
|
child: MaterialApp(
|
|
home: MediaQuery(
|
|
data: MediaQueryData(disableAnimations: reduced),
|
|
child: TickerMode(
|
|
enabled: visible,
|
|
child: PresetAgentAvatar(
|
|
posterPlaceholder: preparedPoster
|
|
? const SizedBox(key: Key('prepared-poster'))
|
|
: null,
|
|
imageUrl:
|
|
'https://dwwgwmfqqjotj.cloudfront.net/avatars/20260925T154625166Z/poster/gloopies/gloopies-13.png',
|
|
size: 50.4,
|
|
fallback: Text('Swiss'),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpWidget(surface());
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(const Key('video')), findsOneWidget);
|
|
expect(player.playing, isTrue);
|
|
expect(player.volume, 0);
|
|
await tester.pumpWidget(surface(visible: false));
|
|
await tester.pump();
|
|
expect(player.playing, isFalse);
|
|
await tester.pumpWidget(surface());
|
|
await tester.pump();
|
|
expect(player.playing, isTrue);
|
|
await tester.pumpWidget(surface(preparedPoster: true));
|
|
await tester.pump();
|
|
expect(
|
|
tester.widget<AnimatedOpacity>(find.byType(AnimatedOpacity)).opacity,
|
|
1,
|
|
);
|
|
player.position = const Duration(milliseconds: 100);
|
|
await tester.pump(const Duration(milliseconds: 600));
|
|
await tester.pump();
|
|
expect(
|
|
tester.widget<AnimatedOpacity>(find.byType(AnimatedOpacity)).opacity,
|
|
0,
|
|
);
|
|
// Looping back to zero must not flash the poster again.
|
|
player.position = Duration.zero;
|
|
await tester.pump(const Duration(milliseconds: 600));
|
|
await tester.pump();
|
|
expect(
|
|
tester.widget<AnimatedOpacity>(find.byType(AnimatedOpacity)).opacity,
|
|
0,
|
|
);
|
|
final navigator = tester.state<NavigatorState>(find.byType(Navigator));
|
|
navigator.push<void>(
|
|
PageRouteBuilder<void>(
|
|
opaque: false,
|
|
transitionDuration: const Duration(milliseconds: 240),
|
|
reverseTransitionDuration: const Duration(milliseconds: 240),
|
|
pageBuilder: (_, _, _) => const SizedBox.shrink(),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
await tester.pump(const Duration(milliseconds: 60));
|
|
expect(find.byKey(const Key('video')), findsNothing);
|
|
expect(find.byKey(const Key('prepared-poster')), findsOneWidget);
|
|
await tester.pumpAndSettle();
|
|
navigator.pop();
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(const Key('video')), findsOneWidget);
|
|
expect(player.playing, isTrue);
|
|
await tester.pumpWidget(surface(reduced: true));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(const Key('video')), findsNothing);
|
|
expect(tester.takeException(), isNull);
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
debugDefaultTargetPlatformOverride = null;
|
|
},
|
|
);
|
|
testWidgets('Android uses transparent renderer and pauses offscreen', (
|
|
tester,
|
|
) async {
|
|
debugDefaultTargetPlatformOverride = TargetPlatform.android;
|
|
addTearDown(() => debugDefaultTargetPlatformOverride = null);
|
|
final messenger = tester.binding.defaultBinaryMessenger;
|
|
final playback = <bool>[];
|
|
var rejectPlayback = false;
|
|
var frameReady = false;
|
|
var frameFailed = false;
|
|
var readinessCalls = 0;
|
|
final channels = <MethodChannel>[];
|
|
messenger.setMockMethodCallHandler(SystemChannels.platform_views, (
|
|
call,
|
|
) async {
|
|
if (call.method == 'create') {
|
|
final args = call.arguments as Map;
|
|
expect(args['viewType'], 'buzz/transparent-avatar');
|
|
final channel = MethodChannel('buzz/transparent-avatar/${args['id']}');
|
|
channels.add(channel);
|
|
messenger.setMockMethodCallHandler(channel, (call) async {
|
|
if (call.method == 'isReady') {
|
|
readinessCalls++;
|
|
return frameFailed
|
|
? 'failed'
|
|
: frameReady
|
|
? 'ready'
|
|
: 'loading';
|
|
}
|
|
if (call.method == 'setPlaying') {
|
|
if (rejectPlayback) throw PlatformException(code: 'unavailable');
|
|
playback.add(call.arguments as bool);
|
|
}
|
|
return null;
|
|
});
|
|
return 1;
|
|
}
|
|
if (call.method == 'resize') {
|
|
final args = call.arguments as Map;
|
|
return {'width': args['width'], 'height': args['height']};
|
|
}
|
|
return null;
|
|
});
|
|
addTearDown(() {
|
|
messenger.setMockMethodCallHandler(SystemChannels.platform_views, null);
|
|
for (final channel in channels) {
|
|
messenger.setMockMethodCallHandler(channel, null);
|
|
}
|
|
});
|
|
Widget surface({
|
|
bool visible = true,
|
|
bool reduced = false,
|
|
}) => ProviderScope(
|
|
child: MaterialApp(
|
|
home: MediaQuery(
|
|
data: MediaQueryData(disableAnimations: reduced),
|
|
child: TickerMode(
|
|
enabled: visible,
|
|
child: const PresetAgentAvatar(
|
|
imageUrl:
|
|
'https://dwwgwmfqqjotj.cloudfront.net/avatars/20260925T154625166Z/poster/gloopies/gloopies-13.png',
|
|
size: 50.4,
|
|
fallback: Text('Swiss'),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpWidget(surface());
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(AndroidView), findsOneWidget);
|
|
// The poster stays until Chromium has actually presented a video frame.
|
|
expect(find.byType(AvatarImageContent), findsOneWidget);
|
|
// A slow download must still become visible after the old ten-second cap.
|
|
for (var i = 0; i < 220; i++) {
|
|
await tester.pump(const Duration(milliseconds: 50));
|
|
}
|
|
frameReady = true;
|
|
await tester.pump(const Duration(milliseconds: 50));
|
|
await tester.pump();
|
|
expect(
|
|
tester.widget<AnimatedOpacity>(find.byType(AnimatedOpacity)).opacity,
|
|
0,
|
|
);
|
|
expect(playback.last, true);
|
|
await tester.pumpWidget(surface(visible: false));
|
|
await tester.pumpAndSettle();
|
|
expect(playback.last, false);
|
|
await tester.pumpWidget(surface());
|
|
await tester.pumpAndSettle();
|
|
expect(playback.last, true);
|
|
await tester.pumpWidget(surface(reduced: true));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(AndroidView), findsNothing);
|
|
frameReady = false;
|
|
frameFailed = true;
|
|
await tester.pumpWidget(surface());
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(AndroidView), findsNothing);
|
|
expect(find.byType(AvatarImageContent), findsOneWidget);
|
|
final stoppedAt = readinessCalls;
|
|
await tester.pump(const Duration(seconds: 15));
|
|
await tester.pumpWidget(surface(visible: false));
|
|
await tester.pumpWidget(surface());
|
|
await tester.pump(const Duration(seconds: 15));
|
|
expect(readinessCalls, stoppedAt);
|
|
await tester.pumpWidget(surface(reduced: true));
|
|
await tester.pumpAndSettle();
|
|
frameFailed = false;
|
|
rejectPlayback = true;
|
|
await tester.pumpWidget(surface());
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(AndroidView), findsNothing);
|
|
expect(find.byType(AvatarImageContent), findsOneWidget);
|
|
expect(tester.takeException(), isNull);
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
debugDefaultTargetPlatformOverride = null;
|
|
});
|
|
}
|