import 'dart:io'; import 'dart:ui' as ui; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:ads_manager/ui/app_widgets.dart'; import 'package:ads_manager/ui/manager_model.dart'; import 'package:ads_manager/ui/manager_view.dart'; import 'package:ads_manager/data/manager_repository.dart'; void main() { testWidgets( 'Cupertino workbench shows computers without refresh layout shift', (tester) async { tester.view.physicalSize = const Size(1280, 820); tester.view.devicePixelRatio = 1; addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetDevicePixelRatio); final m = ManagerModel(); m.devices = [ const Device('phone-one', false, agentId: 'home', computerName: '家里电脑'), const Device( 'phone-two', false, agentId: 'office', computerName: '办公室电脑', ), ]; final key = GlobalKey(); await tester.pumpWidget( RepaintBoundary( key: key, child: AdsCupertinoApp( home: ManagerView(model: m, onQuit: () async {}), ), ), ); await tester.pumpAndSettle(); expect(find.textContaining('办公室电脑'), findsWidgets); final before = tester.getTopLeft(find.text('phone-one')); await m.action(() async { m.refreshing = true; }); await tester.pump(); expect(tester.getTopLeft(find.text('phone-one')), before); await m.action(() async { m.refreshing = false; }); await tester.pumpAndSettle(); expect(tester.takeException(), isNull); if (const bool.fromEnvironment('ADS_CAPTURE')) { await tester.runAsync(() async { final image = await (key.currentContext!.findRenderObject()! as RenderRepaintBoundary) .toImage(); final bytes = await image.toByteData(format: ui.ImageByteFormat.png); await File('../work/flutter-cupertino.png') .writeAsBytes(bytes!.buffer.asUint8List()); image.dispose(); }); } await tester.pumpWidget(const SizedBox()); m.dispose(); }, ); }