Files
MeshPort/apps/meshport_lab/test/responsive_layout_test.dart

72 lines
2.8 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshport_client_core/meshport_client_core.dart';
import 'package:meshport_lab/app.dart';
import 'package:meshport_lab/features/configuration_pages.dart';
import 'package:meshport_lab/features/lab_screen.dart';
import 'package:meshport_lab/features/proxy_node_editor.dart';
void main() {
for (final width in [360.0, 800.0]) {
testWidgets('main tabs fit ${width}px with larger text', (tester) async {
tester.view.physicalSize = Size(width, 850);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
MaterialApp(
theme: meshPortTheme(),
builder: (context, child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: const TextScaler.linear(1.4)),
child: child!,
),
home: const LabScreen(initializeNative: false),
),
);
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
for (final label in ['代理', '组网', '设置', '概览']) {
await tester.tap(find.text(label).last);
await tester.pumpAndSettle();
expect(tester.takeException(), isNull, reason: label);
if (label == '代理') {
await tester.ensureVisible(find.text('高级设置'));
await tester.tap(find.text('高级设置'));
await tester.pumpAndSettle();
await tester.ensureVisible(find.text('DNS 设置'));
expect(
tester.takeException(),
isNull,
reason: 'expanded advanced settings',
);
expect(find.textContaining('代理 DNS:'), findsOneWidget);
}
}
});
}
testWidgets('forms keep fields apart at phone width', (tester) async {
tester.view.physicalSize = const Size(360, 850);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
for (final page in <Widget>[
DnsPage(profile: ProxyProfile(), changed: () {}),
const ProxyNodeEditor(),
const RuleEditor(),
NetworkConfigPage(section: '基础配置', initial: const {}, save: (_) async {}),
]) {
await tester.pumpWidget(MaterialApp(theme: meshPortTheme(), home: page));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
final fields = find.byType(TextField).evaluate().toList();
for (var i = 1; i < fields.length; i++) {
final previous = tester.getRect(find.byWidget(fields[i - 1].widget));
final current = tester.getRect(find.byWidget(fields[i].widget));
expect(current.top - previous.bottom, greaterThanOrEqualTo(12));
}
}
});
}