Files
doormile_milderapp/test/accepted_pill_test.dart
2026-08-11 13:16:33 +05:30

66 lines
2.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:miler/views/Dashboard/home/accepted_pill.dart';
import 'package:miler/views/helpers/constants/design_constants.dart';
/// The way from Home to the work used to be a "Continue trip" button under the
/// last hub row of a trip — so it only existed once that trip had nothing left
/// to decide, and it was below the fold on any route longer than about four
/// stops. The pill replaces it: same fixed place every time, and it says how
/// many bookings the rider is holding.
void main() {
Future<void> pump(WidgetTester tester, int count, {VoidCallback? onTap}) async {
tester.view.physicalSize = const Size(1170, 2532);
tester.view.devicePixelRatio = 3.0;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
ScreenUtilInit(
designSize: const Size(390, 844),
builder: (_, _) => MaterialApp(
home: Scaffold(
body: AcceptedPill(count: count, onTap: onTap ?? () {}),
),
),
),
);
await tester.pumpAndSettle();
}
testWidgets('says nothing when nothing is accepted', (tester) async {
await pump(tester, 0);
expect(find.textContaining('accepted'), findsNothing);
});
testWidgets('carries the count and the singular wording', (tester) async {
await pump(tester, 1);
expect(find.text('1'), findsOneWidget);
expect(find.text('booking accepted'), findsOneWidget);
});
testWidgets('pluralises', (tester) async {
await pump(tester, 4);
expect(find.text('4'), findsOneWidget);
expect(find.text('bookings accepted'), findsOneWidget);
});
testWidgets('is a tap target that leads somewhere', (tester) async {
var taps = 0;
await pump(tester, 3, onTap: () => taps++);
await tester.tap(find.text('bookings accepted'));
await tester.pumpAndSettle();
expect(taps, 1);
// Material's touch-target floor. The pill is small on purpose — it is a way
// through, not the action Home exists for — so this is the guard that keeps
// "small" from becoming "hard to hit at arm's length".
final height = tester.getSize(find.byType(InkWell)).height;
expect(height, greaterThanOrEqualTo(48.0));
expect(ButtonSizes.minTapTarget, lessThanOrEqualTo(height));
});
}