Files
doormile_milderapp/test/sheet_layout_test.dart
2026-08-28 15:07:30 +05:30

193 lines
6.0 KiB
Dart

import 'dart:async' show unawaited;
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:miler/Models/stop_status.dart';
import 'package:miler/data/order_manifest.dart';
import 'package:miler/data/service_profile.dart';
import 'package:miler/views/Dashboard/home/duty_sheet.dart';
import 'package:miler/views/Dashboard/home/pickup_preview_sheet.dart';
import 'package:miler/views/Dashboard/home/stop_action_sheet.dart';
import 'package:miler/views/Dashboard/home/stop_detail_sheet.dart';
/// ─────────────────────────────────────────────────────────────────────────
/// THE SHEETS, ACROSS THE PHONES THIS SHIPS TO
///
/// Same shape as `activity_layout_test`: every rider-path sheet, opened
/// through its real `show` entry point (so the route, fabric and insets are
/// the ones production uses), at the four widths the brief names against the
/// text scales Android exposes. One assertion — **nothing throws** — because
/// a `RenderFlex` overflow is an exception under the test binding and that is
/// the cheapest honest "does it fit?".
/// ─────────────────────────────────────────────────────────────────────────
void main() {
setUpAll(() {
// The detail sheet's map caches tiles through path_provider, which has no
// host under the test binding.
TestWidgetsFlutterBinding.ensureInitialized();
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
const MethodChannel('plugins.flutter.io/path_provider'),
(call) async => Directory.systemTemp
.createTemp('sheet_layout')
.then((d) => d.path),
);
});
tearDown(() {
Get.reset();
ServiceProfile.setActive(ServiceProfile.parcel);
});
const widths = [320.0, 375.0, 390.0, 412.0];
const textScales = [1.0, 1.3, 2.0];
const lines = [
ManifestLine(
stop: {},
orderId: 'D1',
customer: 'Venkataraman Subramanian',
label: 'Bag 1',
),
ManifestLine(stop: {}, orderId: 'D2', customer: 'Arun Prakash', label: 'Bag 2'),
ManifestLine(stop: {}, orderId: 'D3', customer: 'Priya Nair', label: 'Bag 3'),
];
Map<String, dynamic> stop() => {
'orderid': 'D1',
'type': 'delivery',
'pickupcustomer': 'Venkataraman Subramanian',
'sourcename': 'DailyGrubs RS Puram Central Kitchen',
'pickupaddress': '4 Cross, RS Puram, Coimbatore 641002',
'dropaddress': '12, SNS Colony, Peelamedu, Coimbatore 641004',
'orderstatus': 'accepted',
'pickupcontactno': '9787698259',
'baglabel': 'Bag 1',
'Quantity': 1,
'collectionamt': '123456',
'notes': 'Gate code 4411, leave with security if unreachable.',
'pickuplat': 11.0168,
'pickuplon': 76.9558,
'droplat': 11.0208,
'droplon': 76.9598,
};
Future<void> sweep(
WidgetTester tester,
double width,
double scale,
Future<void> Function(BuildContext) open,
) async {
ServiceProfile.setActive(ServiceProfile.milkMan);
SharedPreferences.setMockInitialValues({'userid': 1});
tester.view.physicalSize = Size(width * 3, 844 * 3);
tester.view.devicePixelRatio = 3.0;
addTearDown(tester.view.reset);
late BuildContext ctx;
await tester.pumpWidget(
ScreenUtilInit(
designSize: const Size(390, 844),
builder: (_, _) => MaterialApp(
builder: (context, child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: TextScaler.linear(scale)),
child: child!,
),
home: Builder(
builder: (c) {
ctx = c;
return const Scaffold(body: SizedBox.expand());
},
),
),
),
);
unawaited(open(ctx));
await tester.pumpAndSettle(const Duration(seconds: 1));
expect(
tester.takeException(),
isNull,
reason: 'the sheet overflowed at ${width}pt / ${scale}x',
);
}
for (final width in widths) {
for (final scale in textScales) {
final tag = '${width.toInt()}pt / ${scale}x';
testWidgets('duty fits $tag', (tester) async {
await sweep(
tester,
width,
scale,
(c) => DutySheet.show(
c,
goingOnline: true,
onConfirm: () async => false,
),
);
});
testWidgets('the rung confirmation fits $tag', (tester) async {
await sweep(
tester,
width,
scale,
(c) => StopActionSheet.show(
c,
stage: StopStatus.arrived,
placeName: 'DailyGrubs RS Puram Central Kitchen',
count: 3,
lines: lines,
onConfirm: (_) async => null,
),
);
});
testWidgets('the pickup preview fits $tag', (tester) async {
await sweep(
tester,
width,
scale,
(c) => PickupPreviewSheet.show(
c,
placeName: 'DailyGrubs RS Puram Central Kitchen',
lines: lines,
meters: 3100,
ride: const Duration(minutes: 9),
onNavigate: () {},
onCall: () {},
),
);
});
testWidgets('the stop detail fits $tag', (tester) async {
await sweep(
tester,
width,
scale,
(c) => StopDetailSheet.show(
c,
stop: stop(),
stopNumber: 7,
label: 'Bag 1',
riderLat: 11.0168,
riderLng: 76.9558,
),
);
});
}
}
}