From 99695e8861a4bf3bd70f910f9e200b070fb5c2c2 Mon Sep 17 00:00:00 2001 From: wangjia <809946525@qq.com> Date: Mon, 22 Jun 2026 20:51:34 +0800 Subject: [PATCH] =?UTF-8?q?test(client):=20=E9=94=81=E5=AE=9A=20form=5Ffac?= =?UTF-8?q?tor=20=E6=96=AD=E7=82=B9(iPad=E2=86=92tablet,=20iPhone=E2=86=92?= =?UTF-8?q?mobile)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/test/responsive/form_factor_test.dart | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 client/test/responsive/form_factor_test.dart diff --git a/client/test/responsive/form_factor_test.dart b/client/test/responsive/form_factor_test.dart new file mode 100644 index 0000000..987a3e3 --- /dev/null +++ b/client/test/responsive/form_factor_test.dart @@ -0,0 +1,27 @@ +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pangolin_vpn/core/responsive/form_factor.dart'; + +Future _ffAt(WidgetTester tester, Size size) async { + late FormFactor ff; + tester.view.physicalSize = size; + tester.view.devicePixelRatio = 1.0; + addTearDown(tester.view.reset); + await tester.pumpWidget(MediaQuery( + data: MediaQueryData.fromView(tester.view), + child: Builder(builder: (c) { ff = c.formFactor; return const SizedBox(); }), + )); + return ff; +} + +void main() { + testWidgets('iPad 竖屏(768) → tablet', (t) async { + expect(await _ffAt(t, const Size(768, 1024)), FormFactor.tablet); + }); + testWidgets('iPad 横屏(1024) → tablet', (t) async { + expect(await _ffAt(t, const Size(1024, 768)), FormFactor.tablet); + }); + testWidgets('iPhone(390) → mobile', (t) async { + expect(await _ffAt(t, const Size(390, 844)), FormFactor.mobile); + }); +}