fix(ui): fix various UI issues (#1518)

This commit is contained in:
Levi authored and GitHub committed 2026-09-18 22:40:36 +08:00
1 parent 1ab452ced8
commit 5d8267fa56
25 files changed
+792 -282

No files matched your search

@@ -377,12 +377,14 @@ void main() {
tester.view.physicalSize = const Size(520, 720);
await tester.pumpAndSettle();
final shortcutContent = find.byKey(const ValueKey('create-task-directory-shortcuts-content'));
expect(tester.getTopLeft(shortcutRow).dy, greaterThan(tester.getBottomLeft(rememberDirectoryRow).dy));
expect(tester.getSize(shortcutRow).width, closeTo(tester.getSize(directoryComponent).width, 0.5));
expect(tester.getSize(shortcutContent).width, greaterThan(tester.getSize(shortcutRow).width));
final shortcutScrollable = find.descendant(of: shortcutRow, matching: find.byType(Scrollable));
expect(tester.state<ScrollableState>(shortcutScrollable).position.maxScrollExtent, greaterThan(0));
expect(find.descendant(of: shortcutRow, matching: find.byType(Scrollable)), findsNothing);
for (var index = 0; index < 4; index++) {
final shortcut = tester.getRect(find.byKey(ValueKey('create-task-category-$index')));
expect(shortcut.left, greaterThanOrEqualTo(tester.getRect(shortcutRow).left));
expect(shortcut.right, lessThanOrEqualTo(tester.getRect(shortcutRow).right));
}
tester.view.physicalSize = const Size(719, 720);
await tester.pumpAndSettle();
@@ -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);
});
}
}
+192 -4
View File
@@ -97,6 +97,7 @@ import 'package:gopeed/shared/widgets/app_primary_button.dart';
import 'package:gopeed/shared/widgets/app_text_field.dart';
import 'package:gopeed/shared/widgets/app_tooltip.dart';
import 'package:gopeed/shared/widgets/app_toast.dart';
import 'package:gopeed/shared/widgets/app_swipe_tabs.dart';
import 'package:gopeed/shared/widgets/gopeed_app_mark.dart';
import 'package:gopeed/shared/widgets/responsive_menu_layout.dart';
import 'package:gopeed/shared/widgets/virtual_tree_view.dart';
@@ -541,6 +542,39 @@ void main() {
expect(tester.takeException(), isNull);
expect(find.byKey(const ValueKey('tasks-empty-create-button')), findsOneWidget);
}
tester.view.physicalSize = const Size(390, 760);
await tester.pumpAndSettle();
final content = find.byWidgetPredicate((widget) => widget is AppSwipeTabs);
void expectActive(String label) {
expect(tester.widget<Text>(find.text(label)).style!.fontWeight, FontWeight.w700);
}
expectActive('Downloading 0');
await tester.drag(content, const Offset(160, 0));
await tester.pumpAndSettle();
expectActive('Downloading 0');
await tester.drag(content, const Offset(-160, 0));
await tester.pumpAndSettle();
expectActive('Completed 0');
await tester.drag(content, const Offset(-160, 0));
await tester.pumpAndSettle();
expectActive('Failed 0');
await tester.drag(content, const Offset(-160, 0));
await tester.pumpAndSettle();
expectActive('Failed 0');
await tester.drag(content, const Offset(160, 0));
await tester.pumpAndSettle();
expectActive('Completed 0');
await tester.tap(find.text('Downloading 0'));
await tester.pumpAndSettle();
await tester.drag(content, const Offset(0, -160));
await tester.pumpAndSettle();
expectActive('Downloading 0');
await tester.drag(content, const Offset(-160, 0));
await tester.pumpAndSettle();
expectActive('Completed 0');
expect(tester.takeException(), isNull);
});
testWidgets('extensions grid adds columns from a minimum card width and keeps desktop toolbar aligned', (
@@ -976,6 +1010,28 @@ void main() {
expect(tester.getRect(find.byKey(const ValueKey('extension-search-input'))).top, closeTo(searchRect.top, 0.01));
expect(tester.state<ScrollableState>(scrollable).position.pixels, greaterThan(0));
expect(tester.takeException(), isNull);
final container = ProviderScope.containerOf(tester.element(find.byType(ExtensionsPage)));
ExtensionListFilter filter() => container.read(extensionsControllerProvider).requireValue.listFilter;
expect(filter(), ExtensionListFilter.market);
await tester.drag(list, const Offset(-160, 0));
await tester.pumpAndSettle();
expect(filter(), ExtensionListFilter.installed);
await tester.drag(list, const Offset(-160, 0));
await tester.pumpAndSettle();
expect(filter(), ExtensionListFilter.installed);
await tester.drag(list, const Offset(160, 0));
await tester.pumpAndSettle();
expect(filter(), ExtensionListFilter.market);
await tester.drag(list, const Offset(-20, 0));
await tester.pumpAndSettle();
expect(filter(), ExtensionListFilter.market);
tester.view.physicalSize = const Size(1024, 760);
await tester.pumpAndSettle();
await tester.drag(list, const Offset(-160, 0));
await tester.pumpAndSettle();
expect(filter(), ExtensionListFilter.market);
expect(tester.takeException(), isNull);
});
testWidgets('removing an extension requires explicit confirmation', (WidgetTester tester) async {
@@ -2418,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();
@@ -2761,7 +2823,7 @@ void main() {
});
testWidgets('create task advanced options scroll smoothly into view', (WidgetTester tester) async {
await _setTestSize(tester, const Size(700, 500));
await _setTestSize(tester, const Size(800, 500));
await tester.pumpWidget(const ProviderScope(child: _CreateTaskPageHarness()));
await tester.pumpAndSettle();
final createDirectoryInput = find.byKey(const ValueKey('create-task-directory-input'));
@@ -2891,6 +2953,73 @@ void main() {
await tester.pump(const Duration(seconds: 1));
});
testWidgets('create task stacks narrow forms and preserves header edits across resizing', (tester) async {
await _setTestSize(tester, const Size(390, 844));
await tester.pumpWidget(const ProviderScope(child: _CreateTaskPageHarness()));
await tester.pumpAndSettle();
final rename = find.byKey(const ValueKey('create-task-rename-input'));
final directory = find.byKey(const ValueKey('create-task-directory-input'));
expect(tester.getRect(rename).top, greaterThan(tester.getRect(find.text('Rename')).bottom));
expect(tester.getSize(directory).width, closeTo(342, 0.01));
await tester.ensureVisible(find.text('Advanced'));
await tester.tap(find.text('Advanced'));
await tester.pumpAndSettle();
final proxy = find.byKey(const ValueKey('create-task-proxy-mode'));
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, 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');
FocusManager.instance.primaryFocus?.unfocus();
await tester.pumpAndSettle();
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);
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('create-task-http-header-name-3')), findsOneWidget);
final remove = find.byKey(const ValueKey('create-task-http-header-remove-1'));
await tester.ensureVisible(remove);
await tester.pumpAndSettle();
await tester.tap(remove);
await tester.pumpAndSettle();
expect(editor.controller.toMap()['User-Agent'], 'mobile-agent');
expect(editor.controller.toMap().containsKey('Cookie'), isFalse);
for (final width in [720.0, 1024.0, 390.0]) {
tester.view.physicalSize = Size(width, 844);
await tester.pumpAndSettle();
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);
}
final custom = find.byKey(const ValueKey('create-task-proxy-mode-custom'));
await tester.ensureVisible(custom);
await tester.pumpAndSettle();
await tester.tap(custom);
await tester.pumpAndSettle();
final server = find.byKey(const ValueKey('create-task-proxy-server'));
final port = find.byKey(const ValueKey('create-task-proxy-port'));
final user = find.byKey(const ValueKey('create-task-proxy-username'));
final password = find.byKey(const ValueKey('create-task-proxy-password'));
expect(tester.getRect(port).top, greaterThan(tester.getRect(server).bottom));
expect(tester.getRect(password).top, greaterThan(tester.getRect(user).bottom));
expect(tester.takeException(), isNull);
});
testWidgets('create task labels direct download without a mode field', (WidgetTester tester) async {
await _setTestSize(tester, const Size(700, 500));
await tester.pumpWidget(const ProviderScope(child: _CreateTaskPageHarness()));
@@ -2904,8 +3033,8 @@ void main() {
matching: find.byType(shad.Checkbox),
);
expect(
tester.getRect(directDownloadCheckbox).left,
greaterThan(tester.getRect(find.text('Direct Download')).right),
tester.getRect(directDownloadCheckbox).top,
greaterThan(tester.getRect(find.text('Direct Download')).bottom),
);
await tester.pump(const Duration(seconds: 1));
});
@@ -3051,6 +3180,51 @@ void main() {
expect(hungarianWidth, lessThanOrEqualTo(190));
});
testWidgets('resolved file selector initially expands only first-level directories', (tester) async {
await _setTestSize(tester, const Size(760, 620));
var selected = <int>[];
await tester.pumpWidget(
shad.ShadcnApp(
theme: AppTheme.light(),
materialTheme: AppTheme.materialLight(),
home: ResolveFileTree(
files: [
FileInfo(path: '', name: 'root.txt', size: 1),
FileInfo(path: 'folder', name: 'first.txt', size: 2),
FileInfo(path: 'folder/nested', name: 'second.txt', size: 3),
FileInfo(path: 'folder/nested/deeper', name: 'third.txt', size: 4),
],
initialSelection: const [0, 1, 2, 3],
onSelectionChanged: (values) => selected = values,
),
),
);
await tester.pumpAndSettle();
expect(find.text('root.txt'), findsOneWidget);
expect(find.text('first.txt'), findsOneWidget);
expect(find.text('nested'), findsOneWidget);
expect(find.text('second.txt'), findsNothing);
expect(find.text('third.txt'), findsNothing);
expect(selected, [0, 1, 2, 3]);
await tester.tap(find.byKey(const ValueKey('resolve-tree-node-expand-folder:folder/nested')));
await tester.pumpAndSettle();
expect(find.text('second.txt'), findsOneWidget);
expect(find.text('deeper'), findsOneWidget);
expect(find.text('third.txt'), findsNothing);
expect(selected, [0, 1, 2, 3]);
await tester.tap(find.byKey(const ValueKey('resolve-tree-expand-toggle')));
await tester.pumpAndSettle();
expect(find.text('third.txt'), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('resolve-tree-expand-toggle')));
await tester.pumpAndSettle();
expect(find.text('first.txt'), findsNothing);
expect(find.text('root.txt'), findsOneWidget);
expect(selected, [0, 1, 2, 3]);
expect(tester.takeException(), isNull);
});
testWidgets('resolved file selector uses aligned tree header and sortable columns', (WidgetTester tester) async {
await _setTestSize(tester, const Size(760, 620));
var selected = <int>[];
@@ -3281,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 {