mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-18 06:13:42 +00:00
feat: new ui (#1455)
This commit is contained in:
742 files changed
+59951
-5934
No files matched your search
@@ -0,0 +1,100 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:gopeed/features/auth/presentation/pages/login_page.dart';
|
||||
import 'package:gopeed/l10n/app_localizations.dart';
|
||||
import 'package:gopeed/shared/theme/app_component_themes.dart';
|
||||
import 'package:gopeed/shared/theme/app_theme.dart';
|
||||
import 'package:gopeed/shared/widgets/app_loading_button.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
|
||||
|
||||
void main() {
|
||||
Widget buildApp() {
|
||||
return ProviderScope(
|
||||
child: shad.ShadcnApp(
|
||||
theme: AppTheme.light(),
|
||||
materialTheme: AppTheme.materialLight(),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: const AppComponentThemes(child: LoginPage()),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> setViewport(WidgetTester tester, Size size) async {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(() {
|
||||
tester.view.resetPhysicalSize();
|
||||
tester.view.resetDevicePixelRatio();
|
||||
});
|
||||
await tester.pumpWidget(buildApp());
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
testWidgets('uses a compact responsive card on mobile', (tester) async {
|
||||
await setViewport(tester, const Size(390, 844));
|
||||
|
||||
expect(find.byKey(const ValueKey('login-compact-card')), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('login-desktop-card')), findsNothing);
|
||||
expect(find.byType(SingleChildScrollView), findsNothing);
|
||||
expect(find.byType(FittedBox), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('uses a split card on desktop', (tester) async {
|
||||
await setViewport(tester, const Size(1200, 800));
|
||||
|
||||
expect(find.byKey(const ValueKey('login-desktop-card')), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('login-compact-card')), findsNothing);
|
||||
expect(find.byType(SingleChildScrollView), findsNothing);
|
||||
expect(find.byType(FittedBox), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('fits a short narrow viewport without overflow or scrolling', (tester) async {
|
||||
await setViewport(tester, const Size(320, 480));
|
||||
|
||||
expect(find.byType(SingleChildScrollView), findsNothing);
|
||||
expect(find.byKey(const ValueKey('login-compact-card')), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('exposes browser-compatible username and password autofill fields', (tester) async {
|
||||
await setViewport(tester, const Size(390, 844));
|
||||
|
||||
final username = tester.widget<shad.TextField>(find.byKey(const ValueKey('login-username-field')));
|
||||
final password = tester.widget<shad.TextField>(find.byKey(const ValueKey('login-password-field')));
|
||||
|
||||
final autofillGroup = tester.widget<AutofillGroup>(find.byType(AutofillGroup));
|
||||
expect(autofillGroup.onDisposeAction, AutofillContextAction.cancel);
|
||||
expect(username.autofillHints, contains(AutofillHints.username));
|
||||
expect(username.autofocus, isTrue);
|
||||
expect(username.textInputAction, TextInputAction.done);
|
||||
expect(password.autofillHints, contains(AutofillHints.password));
|
||||
expect(password.textInputAction, TextInputAction.done);
|
||||
expect(password.obscureText, isTrue);
|
||||
expect(password.features.whereType<shad.InputPasswordToggleFeature>(), hasLength(1));
|
||||
});
|
||||
|
||||
testWidgets('uses a compact centered neutral login action', (tester) async {
|
||||
await setViewport(tester, const Size(1200, 800));
|
||||
|
||||
final buttonContainer = find.byKey(const ValueKey('login-submit-button-container'));
|
||||
final button = tester.widget<AppLoadingButton>(find.byKey(const ValueKey('login-submit-button')));
|
||||
expect(tester.getSize(buttonContainer), const Size(148, 40));
|
||||
expect(button.alignment, Alignment.center);
|
||||
expect(button.variant, AppLoadingButtonVariant.primary);
|
||||
});
|
||||
|
||||
testWidgets('validates required credentials before submitting', (tester) async {
|
||||
await setViewport(tester, const Size(390, 844));
|
||||
|
||||
await tester.tap(find.byKey(const ValueKey('login-submit-button')));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Please enter your username'), findsOneWidget);
|
||||
expect(find.text('Please enter your password'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:gopeed/api/model/extension.dart';
|
||||
import 'package:gopeed/api/model/store_extension.dart';
|
||||
import 'package:gopeed/features/extensions/application/extensions_controller.dart';
|
||||
import 'package:gopeed/features/extensions/presentation/widgets/extension_icon.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
void main() {
|
||||
test('installed extension uses its local icon instead of the store icon', () {
|
||||
final item = ExtensionListItem(installed: _installed(), store: _store());
|
||||
|
||||
final source = resolveExtensionIconSource(item, web: false, storageDirectory: '/app-data');
|
||||
|
||||
expect(source.kind, ExtensionIconSourceKind.file);
|
||||
expect(source.location, path.join('/app-data', 'extensions', 'gopeed@test', 'images', 'icon.png'));
|
||||
});
|
||||
|
||||
test('development extension uses its development directory', () {
|
||||
final item = ExtensionListItem(
|
||||
installed: _installed(devMode: true, devPath: '/extension-source'),
|
||||
store: _store(),
|
||||
);
|
||||
|
||||
final source = resolveExtensionIconSource(item, web: false, storageDirectory: '/app-data');
|
||||
|
||||
expect(source.kind, ExtensionIconSourceKind.file);
|
||||
expect(source.location, path.join('/extension-source', 'images', 'icon.png'));
|
||||
});
|
||||
|
||||
test('web uses the local Gopeed extension file endpoint', () {
|
||||
final item = ExtensionListItem(installed: _installed(), store: _store());
|
||||
|
||||
final source = resolveExtensionIconSource(item, web: true);
|
||||
|
||||
expect(source.kind, ExtensionIconSourceKind.network);
|
||||
expect(source.location, '/fs/extensions/gopeed@test/images/icon.png');
|
||||
});
|
||||
|
||||
test('uninstalled market extension keeps using its remote icon', () {
|
||||
final source = resolveExtensionIconSource(ExtensionListItem(store: _store()), web: false);
|
||||
|
||||
expect(source.kind, ExtensionIconSourceKind.network);
|
||||
expect(source.location, 'https://cdn.example.com/icon.png');
|
||||
});
|
||||
|
||||
test('installed extension without an icon uses the bundled fallback', () {
|
||||
final source = resolveExtensionIconSource(
|
||||
ExtensionListItem(
|
||||
installed: _installed(icon: ''),
|
||||
store: _store(),
|
||||
),
|
||||
web: false,
|
||||
storageDirectory: '/app-data',
|
||||
);
|
||||
|
||||
expect(source.kind, ExtensionIconSourceKind.asset);
|
||||
expect(source.location, 'assets/extension/default_icon.png');
|
||||
});
|
||||
}
|
||||
|
||||
Extension _installed({String icon = 'images/icon.png', bool devMode = false, String devPath = ''}) {
|
||||
return Extension(
|
||||
identity: 'gopeed@test',
|
||||
name: 'test',
|
||||
author: 'gopeed',
|
||||
title: 'Test',
|
||||
description: 'Test extension',
|
||||
icon: icon,
|
||||
version: '1.0.0',
|
||||
homepage: '',
|
||||
repository: Repository(url: 'https://github.com/GopeedLab/test', directory: ''),
|
||||
disabled: false,
|
||||
devMode: devMode,
|
||||
devPath: devPath,
|
||||
);
|
||||
}
|
||||
|
||||
StoreExtension _store() {
|
||||
return StoreExtension(
|
||||
id: 'gopeed@test',
|
||||
repoFullName: 'GopeedLab/test',
|
||||
repoUrl: 'https://github.com/GopeedLab/test',
|
||||
name: 'test',
|
||||
author: 'gopeed',
|
||||
title: 'Test',
|
||||
description: 'Test extension',
|
||||
icon: 'https://cdn.example.com/icon.png',
|
||||
version: '1.0.0',
|
||||
homepage: null,
|
||||
readme: null,
|
||||
installCount: 1,
|
||||
stars: 1,
|
||||
topics: const [],
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:gopeed/api/model/downloader_config.dart';
|
||||
import 'package:gopeed/app/application/app_runtime_controller.dart';
|
||||
import 'package:gopeed/core/capabilities/app_capabilities.dart';
|
||||
import 'package:gopeed/core/capabilities/capability_rpc.dart';
|
||||
import 'package:gopeed/core/capabilities/gopeed_capability.dart';
|
||||
import 'package:gopeed/core/common/start_config.dart';
|
||||
import 'package:gopeed/features/settings/application/settings_controller.dart';
|
||||
|
||||
void main() {
|
||||
test('settings reload backend config after the page releases its provider', () async {
|
||||
var backendDirectory = 'D:/Initial';
|
||||
var getConfigCalls = 0;
|
||||
final registry = CapabilityRegistry(createAppCapabilityCodecs())
|
||||
..bind(GopeedMethods.getConfig, (_) {
|
||||
getConfigCalls++;
|
||||
return DownloaderConfig(downloadDir: backendDirectory);
|
||||
});
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
appCapabilitiesProvider.overrideWithValue(AppCapabilities(LocalCapabilityInvoker(registry))),
|
||||
appRuntimeControllerProvider.overrideWith(_TestRuntimeController.new),
|
||||
],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
|
||||
final firstListener = container.listen(settingsControllerProvider, (_, _) {}, fireImmediately: true);
|
||||
expect((await container.read(settingsControllerProvider.future)).config.downloadDir, 'D:/Initial');
|
||||
firstListener.close();
|
||||
await container.pump();
|
||||
|
||||
backendDirectory = 'E:/Created task';
|
||||
final secondListener = container.listen(settingsControllerProvider, (_, _) {}, fireImmediately: true);
|
||||
addTearDown(secondListener.close);
|
||||
expect((await container.read(settingsControllerProvider.future)).config.downloadDir, 'E:/Created task');
|
||||
expect(getConfigCalls, 2);
|
||||
});
|
||||
}
|
||||
|
||||
class _TestRuntimeController extends AppRuntimeController {
|
||||
@override
|
||||
Future<AppRuntimeState> build() async => AppRuntimeState(
|
||||
startConfig: StartConfig(),
|
||||
runningPort: 0,
|
||||
downloaderConfig: DownloaderConfig(downloadDir: 'C:/Stale runtime snapshot'),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,358 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter/widgets.dart' as flutter show Row;
|
||||
import 'package:flutter/material.dart' show Icons;
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:gopeed/api/model/create_task.dart';
|
||||
import 'package:gopeed/api/model/downloader_config.dart';
|
||||
import 'package:gopeed/api/model/options.dart';
|
||||
import 'package:gopeed/api/model/request.dart';
|
||||
import 'package:gopeed/core/capabilities/app_capabilities.dart';
|
||||
import 'package:gopeed/core/capabilities/capability_rpc.dart';
|
||||
import 'package:gopeed/core/capabilities/gopeed_capability.dart';
|
||||
import 'package:gopeed/core/capabilities/storage_capability.dart';
|
||||
import 'package:gopeed/features/tasks/presentation/pages/create_task_window_page.dart';
|
||||
import 'package:gopeed/shared/services/download_directory_picker.dart';
|
||||
import 'package:gopeed/shared/theme/app_component_themes.dart';
|
||||
import 'package:gopeed/shared/theme/app_design_tokens.dart';
|
||||
import 'package:gopeed/shared/theme/app_theme.dart';
|
||||
import 'package:gopeed/shared/widgets/app_tooltip.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart' as shad;
|
||||
|
||||
void main() {
|
||||
testWidgets('browser extension request parameters populate the form and survive submission', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(1024, 720);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
DownloadDirectoryPicker.debugPlatformOverride = TargetPlatform.android;
|
||||
final androidLocations = <String, String>{'application': 'D:/Downloads', 'downloads': 'G:/Manually selected'};
|
||||
DownloadDirectoryPicker.debugAndroidLocationsLoader = () async => androidLocations;
|
||||
DownloadDirectoryPicker.debugDownloadsPreparer = (path) async => path;
|
||||
addTearDown(() {
|
||||
DownloadDirectoryPicker.debugPlatformOverride = null;
|
||||
DownloadDirectoryPicker.debugAndroidLocationsLoader = null;
|
||||
DownloadDirectoryPicker.debugDownloadsPreparer = null;
|
||||
});
|
||||
|
||||
CreateTask? submitted;
|
||||
final config = DownloaderConfig(downloadDir: 'C:/Downloads')
|
||||
..extra.defaultDirectDownload = true
|
||||
..extra.downloadCategories = [
|
||||
DownloadCategory(name: 'Archives', path: 'E:/Archives/%year%'),
|
||||
DownloadCategory(name: 'Archives', path: 'F:/Archives'),
|
||||
DownloadCategory(name: 'Long video category', path: 'G:/Videos'),
|
||||
DownloadCategory(name: 'Long document category', path: 'H:/Documents'),
|
||||
]
|
||||
..protocolConfig.http.connections = 8;
|
||||
final registry = CapabilityRegistry(createAppCapabilityCodecs())
|
||||
..bind(GopeedMethods.getConfig, (_) => config)
|
||||
..bind(GopeedMethods.createTask, (task) {
|
||||
submitted = task;
|
||||
return 'created-task';
|
||||
})
|
||||
..bind(StorageMethods.saveCreateHistory, (_) => const RpcUnit());
|
||||
final capabilities = AppCapabilities(LocalCapabilityInvoker(registry));
|
||||
|
||||
final initialTask = CreateTask(
|
||||
req: Request(
|
||||
rawUrl: 'https://page.example/download',
|
||||
url: 'https://cdn.example/archive.zip',
|
||||
extra: ReqExtraHttp(
|
||||
method: 'POST',
|
||||
header: const {
|
||||
'User-Agent': 'Browser UA',
|
||||
'Cookie': 'session=abc',
|
||||
'Referer': 'https://page.example/',
|
||||
'Authorization': 'Bearer token',
|
||||
},
|
||||
body: 'request-body',
|
||||
).toJson(),
|
||||
labels: const {'source': 'browser-extension'},
|
||||
proxy: RequestProxy(
|
||||
mode: RequestProxyMode.custom,
|
||||
scheme: 'socks5',
|
||||
host: '127.0.0.1:7890',
|
||||
usr: 'proxy-user',
|
||||
pwd: 'proxy-password',
|
||||
),
|
||||
skipVerifyCert: true,
|
||||
),
|
||||
opts: Options(
|
||||
name: 'archive.zip',
|
||||
path: 'D:/Downloads',
|
||||
extra: OptsExtraHttp(
|
||||
connections: 12,
|
||||
autoTorrent: true,
|
||||
deleteTorrentAfterDownload: true,
|
||||
autoExtract: true,
|
||||
archivePassword: 'archive-password',
|
||||
deleteAfterExtract: true,
|
||||
).toJson(),
|
||||
),
|
||||
);
|
||||
final router = GoRouter(
|
||||
initialLocation: '/create',
|
||||
routes: [
|
||||
GoRoute(path: '/', builder: (_, _) => const SizedBox()),
|
||||
GoRoute(
|
||||
path: '/create',
|
||||
builder: (_, _) => CreateTaskWindowPage(initialTask: initialTask),
|
||||
),
|
||||
],
|
||||
);
|
||||
addTearDown(router.dispose);
|
||||
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [appCapabilitiesProvider.overrideWithValue(capabilities)],
|
||||
child: shad.ShadcnApp.router(
|
||||
theme: AppTheme.light(),
|
||||
materialTheme: AppTheme.materialLight(),
|
||||
builder: (context, child) => AppComponentThemes(child: child ?? const SizedBox.shrink()),
|
||||
routerConfig: router,
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(_fieldText(tester, 'create-task-http-header-name-0'), 'User-Agent');
|
||||
expect(_fieldText(tester, 'create-task-http-header-value-0'), 'Browser UA');
|
||||
expect(_fieldText(tester, 'create-task-http-header-name-3'), 'Authorization');
|
||||
expect(_fieldText(tester, 'create-task-http-header-value-3'), 'Bearer token');
|
||||
expect(_fieldText(tester, 'create-task-proxy-server'), '127.0.0.1');
|
||||
expect(_fieldText(tester, 'create-task-proxy-port'), '7890');
|
||||
expect(_fieldText(tester, 'create-task-proxy-username'), 'proxy-user');
|
||||
expect(_fieldText(tester, 'create-task-proxy-password'), 'proxy-password');
|
||||
expect(_fieldText(tester, 'create-task-archive-password'), 'archive-password');
|
||||
expect(find.byKey(const ValueKey('create-task-skip-verify-cert')), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('create-task-auto-torrent')), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('create-task-delete-torrent')), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('create-task-auto-extract')), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('create-task-delete-after-extract')), findsOneWidget);
|
||||
|
||||
expect(find.text('Archives'), findsNWidgets(2));
|
||||
expect(find.text('Quick folders'), findsNothing);
|
||||
expect(find.byKey(const ValueKey('create-task-category-0')), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('create-task-category-1')), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('create-task-category-2')), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('create-task-category-3')), findsOneWidget);
|
||||
final shortcutRow = find.byKey(const ValueKey('create-task-directory-shortcuts'));
|
||||
expect(tester.getSize(shortcutRow).height, 28);
|
||||
final rememberDirectory = find.byKey(const ValueKey('create-task-remember-download-directory-checkbox'));
|
||||
final directDownloadCheckbox = find.byKey(const ValueKey('create-task-direct-download-checkbox'));
|
||||
final rememberDirectoryRow = find.byKey(const ValueKey('create-task-remember-download-directory'));
|
||||
final directoryComponent = find.byKey(const ValueKey('create-task-directory-component'));
|
||||
final directoryOptionsRow = find.byKey(const ValueKey('create-task-directory-options-row'));
|
||||
final directoryOptionsLayout = find.byKey(const ValueKey('create-task-directory-options-layout'));
|
||||
final directoryPicker = find.byKey(const ValueKey('create-task-directory-picker'));
|
||||
expect(tester.widget<shad.Checkbox>(rememberDirectory).state, shad.CheckboxState.unchecked);
|
||||
expect(tester.widget<shad.Checkbox>(rememberDirectory).size, isNull);
|
||||
expect(tester.getSize(rememberDirectory), const Size.square(AppDesignTokens.checkboxSize));
|
||||
expect(tester.getCenter(rememberDirectory).dx, closeTo(tester.getCenter(directDownloadCheckbox).dx, 0.5));
|
||||
final rememberDirectoryLabel = tester.widget<Text>(
|
||||
find.byKey(const ValueKey('create-task-remember-download-directory-label')),
|
||||
);
|
||||
final directDownloadLabel = tester.widget<Text>(find.byKey(const ValueKey('create-task-direct-download-label')));
|
||||
expect(rememberDirectoryLabel.style, directDownloadLabel.style);
|
||||
expect(rememberDirectoryLabel.maxLines, directDownloadLabel.maxLines);
|
||||
expect(rememberDirectoryLabel.overflow, directDownloadLabel.overflow);
|
||||
expect(tester.widget<shad.IconButton>(directoryPicker).variance, same(shad.ButtonVariance.outline));
|
||||
expect(tester.widget<flutter.Row>(directoryOptionsLayout).mainAxisAlignment, MainAxisAlignment.spaceBetween);
|
||||
expect(tester.getCenter(rememberDirectoryRow).dy, closeTo(tester.getCenter(shortcutRow).dy, 0.5));
|
||||
expect(tester.getTopRight(directoryOptionsRow).dx, closeTo(tester.getTopRight(directoryComponent).dx, 0.5));
|
||||
expect(
|
||||
tester.getTopRight(find.byKey(const ValueKey('create-task-category-3'))).dx,
|
||||
closeTo(tester.getTopRight(directoryComponent).dx, 0.5),
|
||||
);
|
||||
|
||||
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));
|
||||
|
||||
tester.view.physicalSize = const Size(719, 720);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.widget<shad.Column>(find.byKey(const ValueKey('create-task-directory-options-layout'))),
|
||||
isA<shad.Column>(),
|
||||
);
|
||||
|
||||
tester.view.physicalSize = const Size(720, 720);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.widget<flutter.Row>(find.byKey(const ValueKey('create-task-directory-options-layout'))).mainAxisAlignment,
|
||||
MainAxisAlignment.spaceBetween,
|
||||
);
|
||||
|
||||
tester.view.physicalSize = const Size(1024, 720);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(directoryPicker);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const ValueKey('android-app-directory-option')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.widget<shad.Checkbox>(rememberDirectory).state, shad.CheckboxState.unchecked);
|
||||
|
||||
await tester.tap(directoryPicker);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const ValueKey('android-downloads-directory-option')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.widget<shad.Checkbox>(rememberDirectory).state, shad.CheckboxState.checked);
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.tap(find.byKey(const ValueKey('create-task-category-3')));
|
||||
await tester.pump();
|
||||
expect(tester.widget<shad.Checkbox>(rememberDirectory).state, shad.CheckboxState.unchecked);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const ValueKey('create-task-category-3')),
|
||||
matching: find.byIcon(Icons.folder_outlined),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
androidLocations['downloads'] = 'C:/Downloads';
|
||||
await tester.tap(directoryPicker);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const ValueKey('android-downloads-directory-option')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.widget<shad.Checkbox>(rememberDirectory).state, shad.CheckboxState.unchecked);
|
||||
|
||||
androidLocations['downloads'] = 'G:/Manually selected';
|
||||
await tester.tap(directoryPicker);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const ValueKey('android-downloads-directory-option')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.widget<shad.Checkbox>(rememberDirectory).state, shad.CheckboxState.checked);
|
||||
|
||||
await tester.tap(find.text('Confirm'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final request = submitted?.req;
|
||||
expect(request, isNotNull);
|
||||
expect(request?.rawUrl, initialTask.req?.rawUrl);
|
||||
expect(request?.labels, initialTask.req?.labels);
|
||||
expect(request?.proxy?.mode, RequestProxyMode.custom);
|
||||
expect(request?.proxy?.scheme, 'socks5');
|
||||
expect(request?.proxy?.host, '127.0.0.1:7890');
|
||||
expect(request?.proxy?.usr, 'proxy-user');
|
||||
expect(request?.proxy?.pwd, 'proxy-password');
|
||||
expect(request?.skipVerifyCert, isTrue);
|
||||
expect(ReqExtraHttp.fromJson(request?.extra! as Map<String, dynamic>).toJson(), initialTask.req?.extra);
|
||||
expect(submitted?.opts?.path, 'G:/Manually selected');
|
||||
final options = OptsExtraHttp.fromJson(submitted?.opts?.extra! as Map<String, dynamic>);
|
||||
expect(options.connections, 12);
|
||||
expect(options.autoTorrent, isTrue);
|
||||
expect(options.deleteTorrentAfterDownload, isTrue);
|
||||
expect(options.autoExtract, isTrue);
|
||||
expect(options.archivePassword, 'archive-password');
|
||||
expect(options.deleteAfterExtract, isTrue);
|
||||
expect(submitted?.opts?.asDefaultPath, isTrue);
|
||||
});
|
||||
|
||||
testWidgets('create history supports filtering, deleting one entry, and clearing all entries', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(1024, 720);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
final histories = <String>[
|
||||
'https://example.com/alpha.zip',
|
||||
'https://example.com/beta.iso',
|
||||
'magnet:?xt=urn:btih:gamma',
|
||||
];
|
||||
String? removedHistory;
|
||||
var cleared = false;
|
||||
final registry = CapabilityRegistry(createAppCapabilityCodecs())
|
||||
..bind(GopeedMethods.getConfig, (_) => DownloaderConfig(downloadDir: '/downloads'))
|
||||
..bind(StorageMethods.getCreateHistory, (_) => List<String>.unmodifiable(histories))
|
||||
..bind(StorageMethods.removeCreateHistory, (value) {
|
||||
removedHistory = value;
|
||||
histories.remove(value);
|
||||
return const RpcUnit();
|
||||
})
|
||||
..bind(StorageMethods.clearCreateHistory, (_) {
|
||||
cleared = true;
|
||||
histories.clear();
|
||||
return const RpcUnit();
|
||||
});
|
||||
final capabilities = AppCapabilities(LocalCapabilityInvoker(registry));
|
||||
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [appCapabilitiesProvider.overrideWithValue(capabilities)],
|
||||
child: shad.ShadcnApp(
|
||||
theme: AppTheme.light(),
|
||||
materialTheme: AppTheme.materialLight(),
|
||||
home: AppComponentThemes(child: const CreateTaskWindowPage()),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byIcon(Icons.history));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.getSize(find.byKey(const ValueKey('create-history-title-bar'))).width,
|
||||
tester.getSize(find.byKey(const ValueKey('create-history-content'))).width,
|
||||
);
|
||||
final alphaItem = find.byKey(const ValueKey('create-history-item-https://example.com/alpha.zip'));
|
||||
final betaItem = find.byKey(const ValueKey('create-history-item-https://example.com/beta.iso'));
|
||||
final gammaItem = find.byKey(const ValueKey('create-history-item-magnet:?xt=urn:btih:gamma'));
|
||||
expect(alphaItem, findsOneWidget);
|
||||
expect(betaItem, findsOneWidget);
|
||||
expect(gammaItem, findsOneWidget);
|
||||
final clearAction = find.byKey(const ValueKey('create-history-clear'));
|
||||
final closeAction = find.byKey(const ValueKey('create-history-close'));
|
||||
expect(
|
||||
tester.widget<AppTooltip>(find.ancestor(of: clearAction, matching: find.byType(AppTooltip))).message,
|
||||
'Clear History',
|
||||
);
|
||||
expect(
|
||||
tester.widget<AppTooltip>(find.ancestor(of: closeAction, matching: find.byType(AppTooltip))).message,
|
||||
'Close',
|
||||
);
|
||||
final historyText = tester.widget<Text>(find.descendant(of: alphaItem, matching: find.byType(Text)));
|
||||
expect(historyText.data, contains('\u200B'));
|
||||
expect(historyText.semanticsLabel, 'https://example.com/alpha.zip');
|
||||
|
||||
final filter = find.byKey(const ValueKey('create-history-filter'));
|
||||
await tester.enterText(filter, 'beta');
|
||||
await tester.pump();
|
||||
expect(alphaItem, findsNothing);
|
||||
expect(betaItem, findsOneWidget);
|
||||
expect(gammaItem, findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(const ValueKey('create-history-delete-https://example.com/beta.iso')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(removedHistory, 'https://example.com/beta.iso');
|
||||
expect(find.text('No History Found'), findsOneWidget);
|
||||
|
||||
await tester.enterText(filter, '');
|
||||
await tester.pump();
|
||||
expect(alphaItem, findsOneWidget);
|
||||
expect(gammaItem, findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const ValueKey('create-history-clear')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(cleared, isTrue);
|
||||
expect(find.text('No history'), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('create-history-clear')), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('create-history-close')), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
String _fieldText(WidgetTester tester, String key) {
|
||||
final editable = find.descendant(of: find.byKey(ValueKey(key)), matching: find.byType(EditableText));
|
||||
return tester.widget<EditableText>(editable).controller.text;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:gopeed/features/tasks/domain/task_record.dart';
|
||||
import 'package:gopeed/features/tasks/presentation/task_record_localizations.dart';
|
||||
import 'package:gopeed/l10n/app_localizations_en.dart';
|
||||
|
||||
void main() {
|
||||
test('remaining time and download duration share unit thresholds and rounding', () {
|
||||
final l10n = AppLocalizationsEn();
|
||||
final cases = <(int, String, String)>[
|
||||
(59, '59 seconds remaining', '59 seconds'),
|
||||
(60, '1 minute remaining', '1 minute'),
|
||||
(61, '2 minutes remaining', '2 minutes'),
|
||||
(3599, '60 minutes remaining', '60 minutes'),
|
||||
(3600, '1 hour remaining', '1 hour'),
|
||||
(3723, '2 hours remaining', '2 hours'),
|
||||
];
|
||||
|
||||
for (final (seconds, remaining, duration) in cases) {
|
||||
final runningTask = TaskRecord(
|
||||
id: 'running-$seconds',
|
||||
name: 'archive.zip',
|
||||
status: TaskStatus.downloading,
|
||||
downloaded: '1 MB',
|
||||
url: 'https://example.com/archive.zip',
|
||||
storagePath: '/downloads/archive.zip',
|
||||
files: const [],
|
||||
uploading: false,
|
||||
remainingSeconds: seconds,
|
||||
);
|
||||
final completedTask = TaskRecord(
|
||||
id: 'completed-$seconds',
|
||||
name: 'archive.zip',
|
||||
status: TaskStatus.completed,
|
||||
downloaded: '1 MB',
|
||||
url: 'https://example.com/archive.zip',
|
||||
storagePath: '/downloads/archive.zip',
|
||||
files: const [],
|
||||
uploading: false,
|
||||
downloadDuration: Duration(seconds: seconds),
|
||||
);
|
||||
|
||||
expect(runningTask.localizedRemaining(l10n), remaining);
|
||||
expect(completedTask.localizedDownloadDuration(l10n), duration);
|
||||
expect(formatTaskDuration(l10n, Duration(seconds: seconds)), duration);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user