Files
IKAR/test/sliding_pill_nav_unread_test.dart
T

82 lines
2.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:ikar/frontend/widgets/sliding_pill_nav.dart';
void main() {
Future<void> pumpNav(
WidgetTester tester, {
required int unread,
double position = 0,
bool iconsOnly = false,
ValueChanged<int>? onTap,
}) => tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
child: SizedBox(
width: 300,
child: SlidingPillNav(
items: [
PillNavItem(
icon: Icons.chat_bubble,
label: 'Чаты',
unreadCount: unread,
),
const PillNavItem(icon: Icons.call, label: 'Звонки'),
const PillNavItem(icon: Icons.person, label: 'Контакты'),
const PillNavItem(icon: Icons.settings, label: 'Настройки'),
],
position: position,
geometry: PillNavGeometry.fromInnerWidth(296, 4),
iconsOnly: iconsOnly,
onTap: onTap ?? (_) {},
),
),
),
),
),
);
testWidgets('badge updates and disappears after chats are read', (
tester,
) async {
await pumpNav(tester, unread: 3);
expect(find.text('3'), findsOneWidget);
expect(find.byType(Badge), findsOneWidget);
final badgeRight = tester.getRect(find.text('3')).right;
expect(badgeRight, lessThan(tester.getRect(find.text('Чаты')).left));
await pumpNav(tester, unread: 2);
expect(find.text('2'), findsOneWidget);
expect(find.text('3'), findsNothing);
await pumpNav(tester, unread: 0);
expect(find.byType(Badge), findsNothing);
expect(tester.takeException(), isNull);
});
testWidgets(
'badge remains visible on another tab and chat icon is tappable',
(tester) async {
int? tapped;
await pumpNav(tester, unread: 7, position: 1, onTap: (i) => tapped = i);
expect(find.text('7'), findsOneWidget);
await tester.tap(find.byIcon(Icons.chat_bubble));
expect(tapped, 0);
expect(tester.takeException(), isNull);
},
);
testWidgets('large count is compact in icons-only navigation', (
tester,
) async {
await pumpNav(tester, unread: 120, iconsOnly: true);
expect(find.text('99+'), findsOneWidget);
await pumpNav(tester, unread: 120);
final badgeRight = tester.getRect(find.text('99+')).right;
final chatLabel = find.text('Чаты');
expect(badgeRight, lessThan(tester.getRect(chatLabel).left));
expect(tester.takeException(), isNull);
});
}