import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:material_symbols_icons/symbols.dart'; import 'package:ikar/frontend/screens/chats/chat/view/scroll_down_button.dart'; void main() { Future pumpButton( WidgetTester tester, ValueNotifier unread, { VoidCallback? onTap, bool material = false, double visibility = 1, }) async { final height = ValueNotifier(64); addTearDown(height.dispose); await tester.pumpWidget( MaterialApp( home: Scaffold( body: Stack( children: [ ScrollDownButton( composerHeight: height, materialComposer: material, composerUnderlap: true, frosted: false, liquidChrome: false, pillBackdrop: null, scrollDownCurved: AlwaysStoppedAnimation(visibility), unreadCount: unread, onTap: onTap ?? () {}, ), ], ), ), ), ); } for (final material in [false, true]) { testWidgets('existing unread count updates while the arrow is visible ' '(material=$material)', (tester) async { final unread = ValueNotifier(12); addTearDown(unread.dispose); await pumpButton(tester, unread, material: material); expect(find.text('12'), findsOneWidget); unread.value = 5; await tester.pumpAndSettle(); expect(find.text('5'), findsOneWidget); expect(find.text('12'), findsNothing); unread.value = 0; await tester.pumpAndSettle(); expect(find.text('5'), findsNothing); expect(find.byIcon(Symbols.keyboard_arrow_down), findsOneWidget); expect(tester.takeException(), isNull); }); } testWidgets('large counts are capped and tapping waits for actual reading', ( tester, ) async { final unread = ValueNotifier(150); addTearDown(unread.dispose); var taps = 0; await pumpButton(tester, unread, onTap: () => taps++); expect(find.text('99+'), findsOneWidget); await tester.tap(find.byIcon(Symbols.keyboard_arrow_down)); await tester.pumpAndSettle(); expect(taps, 1); expect(find.text('99+'), findsOneWidget); unread.value = 0; await tester.pumpAndSettle(); expect(find.text('99+'), findsNothing); }); testWidgets('hidden arrow also hides its badge', (tester) async { final unread = ValueNotifier(8); addTearDown(unread.dispose); await pumpButton(tester, unread, visibility: 0); expect(find.text('8'), findsNothing); expect(find.byIcon(Symbols.keyboard_arrow_down), findsNothing); }); }