mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-15 04:43:41 +00:00
Merge latest PR #1518 into 2.0.0-beta.2
This commit is contained in:
commit
c6dd58848d
8 files changed
+257
-186
No files matched your search
@@ -0,0 +1,49 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
|
||||
import 'package:gopeed/shared/theme/app_theme.dart';
|
||||
import 'package:gopeed/shared/widgets/app_path_placeholder_button.dart';
|
||||
|
||||
void main() {
|
||||
for (final width in [390.0, 1024.0]) {
|
||||
testWidgets('path placeholders explain and insert variables at width $width', (tester) async {
|
||||
tester.view.physicalSize = Size(width, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final controller = TextEditingController(text: '/downloads/replace');
|
||||
addTearDown(controller.dispose);
|
||||
controller.selection = const TextSelection(baseOffset: 11, extentOffset: 18);
|
||||
await tester.pumpWidget(
|
||||
shad.ShadcnApp(
|
||||
theme: AppTheme.light(),
|
||||
materialTheme: AppTheme.materialLight(),
|
||||
home: Center(child: AppPathPlaceholderButton(controller: controller)),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('Insert Placeholder'));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 300));
|
||||
expect(find.text('%year% — Current year'), findsOneWidget);
|
||||
expect(find.text('%month% — Current month (01-12)'), findsOneWidget);
|
||||
expect(find.text('%day% — Current day (01-31)'), findsOneWidget);
|
||||
expect(find.text('%date% — Full date (YYYY-MM-DD)'), findsOneWidget);
|
||||
expect(find.text('e.g. ${DateTime.now().year}'), findsOneWidget);
|
||||
await tester.tap(find.byKey(const ValueKey('path-placeholder-%year%')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.text, '/downloads/%year%');
|
||||
expect(controller.selection.baseOffset, controller.text.length);
|
||||
expect(find.text('%year% — Current year'), findsNothing);
|
||||
for (final variable in ['%month%', '%day%', '%date%']) {
|
||||
controller.text = '/downloads/';
|
||||
await tester.tap(find.text('Insert Placeholder'));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 300));
|
||||
await tester.tap(find.byKey(ValueKey('path-placeholder-$variable')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.text, '/downloads/$variable');
|
||||
}
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2474,11 +2474,17 @@ void main() {
|
||||
expect(find.byType(DownloadCategoriesControl), findsOneWidget);
|
||||
await tester.enterText(find.byKey(const ValueKey('download-category-name')), '归档');
|
||||
await tester.enterText(find.byKey(const ValueKey('download-category-path')), '/tmp/archive');
|
||||
await tester.tap(find.text('Insert Placeholder'));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 300));
|
||||
expect(find.text('%date% — Full date (YYYY-MM-DD)'), findsOneWidget);
|
||||
await tester.tap(find.byKey(const ValueKey('path-placeholder-%date%')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Confirm'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('归档'), findsOneWidget);
|
||||
expect(find.text('/tmp/archive'), findsOneWidget);
|
||||
expect(find.text('/tmp/archive%date%'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const ValueKey('edit-download-category-资料')));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -2963,8 +2969,9 @@ void main() {
|
||||
expect(tester.getRect(proxy).top, greaterThan(tester.getRect(find.text('Proxy')).bottom));
|
||||
final name = find.byKey(const ValueKey('create-task-http-header-name-0'));
|
||||
final value = find.byKey(const ValueKey('create-task-http-header-value-0'));
|
||||
expect(tester.getRect(value).top, greaterThan(tester.getRect(name).bottom));
|
||||
expect(tester.getSize(value).width, tester.getSize(name).width);
|
||||
expect(tester.getRect(value).top, closeTo(tester.getRect(name).top, 0.01));
|
||||
expect(tester.getRect(value).left, greaterThan(tester.getRect(name).right));
|
||||
expect(tester.getSize(value).width / tester.getSize(name).width, closeTo(1.618, 0.01));
|
||||
await tester.ensureVisible(value);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(find.descendant(of: value, matching: find.byType(EditableText)), 'mobile-agent');
|
||||
@@ -2974,6 +2981,9 @@ void main() {
|
||||
final editor = tester.widget<AppHttpHeadersEditor>(find.byType(AppHttpHeadersEditor));
|
||||
expect(editor.controller.toMap()['User-Agent'], 'mobile-agent');
|
||||
final add = find.byKey(const ValueKey('create-task-http-header-add'));
|
||||
final lastRemove = find.byKey(const ValueKey('create-task-http-header-remove-2'));
|
||||
expect(tester.getCenter(add).dy, closeTo(tester.getCenter(lastRemove).dy, 0.01));
|
||||
expect(tester.getRect(add).left, greaterThan(tester.getRect(lastRemove).right));
|
||||
await tester.ensureVisible(add);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(add);
|
||||
@@ -2990,12 +3000,8 @@ void main() {
|
||||
for (final width in [720.0, 1024.0, 390.0]) {
|
||||
tester.view.physicalSize = Size(width, 844);
|
||||
await tester.pumpAndSettle();
|
||||
if (width >= 720) {
|
||||
expect(tester.getRect(name).top, closeTo(tester.getRect(value).top, 0.01));
|
||||
expect(tester.getRect(value).left, greaterThan(tester.getRect(name).right));
|
||||
} else {
|
||||
expect(tester.getRect(value).top, greaterThan(tester.getRect(name).bottom));
|
||||
}
|
||||
expect(tester.getRect(name).top, closeTo(tester.getRect(value).top, 0.01));
|
||||
expect(tester.getRect(value).left, greaterThan(tester.getRect(name).right));
|
||||
expect(editor.controller.toMap()['User-Agent'], 'mobile-agent');
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
@@ -3449,6 +3455,20 @@ void main() {
|
||||
expect(position.pixels, greaterThan(0));
|
||||
expect(tester.getRect(find.text(longName)).left, lessThan(nameLeftBefore));
|
||||
expect(tester.getRect(trailing).left, closeTo(trailingLeftBefore, 0.01));
|
||||
|
||||
position.jumpTo(0);
|
||||
await tester.pumpAndSettle();
|
||||
final nameArea = find.byKey(const ValueKey('resolve-tree-name-scroll-file:0'));
|
||||
await tester.drag(nameArea, const Offset(-100, 0));
|
||||
await tester.pumpAndSettle();
|
||||
expect(position.pixels, greaterThan(0));
|
||||
expect(tester.getRect(find.text(longName)).left, lessThan(nameLeftBefore));
|
||||
expect(tester.getRect(trailing).left, closeTo(trailingLeftBefore, 0.01));
|
||||
final previousOffset = position.pixels;
|
||||
await tester.drag(nameArea, const Offset(80, 0));
|
||||
await tester.pumpAndSettle();
|
||||
expect(position.pixels, lessThan(previousOffset));
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('file name scrollbar stays hidden when measured labels fit', (WidgetTester tester) async {
|
||||
|
||||
Reference in new issue
Block a user