feat(flutter): 增加关键操作震动反馈
This commit is contained in:
1 parent
e609e3ad8d
commit
8a481d5c62
20 files changed
+308
-72
No files matched your search
@@ -10,6 +10,7 @@ import 'package:fruitshorts/core/data/repositories/download_repository.dart';
|
||||
import 'package:fruitshorts/core/data/services/auth_controller.dart';
|
||||
import 'package:fruitshorts/core/data/services/auth_session_store.dart';
|
||||
import 'package:fruitshorts/core/data/services/download_controller.dart';
|
||||
import 'package:fruitshorts/core/platform/haptics.dart';
|
||||
import 'package:fruitshorts/l10n/app_localizations.dart';
|
||||
import 'package:fruitshorts/pages/downloads/downloads_page.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@@ -17,20 +18,19 @@ import 'package:shared_preferences_platform_interface/in_memory_shared_preferenc
|
||||
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart';
|
||||
|
||||
import '../support/fake_http_adapter.dart';
|
||||
import '../support/fake_haptics.dart';
|
||||
|
||||
DownloadPolicy _policy({
|
||||
bool wifiOnly = true,
|
||||
String maxQuality = 'AUTO',
|
||||
}) => DownloadPolicy(
|
||||
maxPerDevice: 20,
|
||||
licenseDays: 30,
|
||||
wifiOnly: wifiOnly,
|
||||
maxQuality: maxQuality,
|
||||
maxStorageBytes: 0,
|
||||
used: 1,
|
||||
remaining: 19,
|
||||
expirePolicyText: 'Licenses last 30 days',
|
||||
);
|
||||
DownloadPolicy _policy({bool wifiOnly = true, String maxQuality = 'AUTO'}) =>
|
||||
DownloadPolicy(
|
||||
maxPerDevice: 20,
|
||||
licenseDays: 30,
|
||||
wifiOnly: wifiOnly,
|
||||
maxQuality: maxQuality,
|
||||
maxStorageBytes: 0,
|
||||
used: 1,
|
||||
remaining: 19,
|
||||
expirePolicyText: 'Licenses last 30 days',
|
||||
);
|
||||
|
||||
DownloadLicense _license(String episodeId) => DownloadLicense(
|
||||
licenseId: 'license-$episodeId',
|
||||
@@ -145,8 +145,14 @@ void main() {
|
||||
licenses: [_license('1')],
|
||||
);
|
||||
final controller = DownloadController(repository);
|
||||
final haptics = FakeHaptics();
|
||||
|
||||
await _pumpPage(tester, auth: auth, controller: controller);
|
||||
await _pumpPage(
|
||||
tester,
|
||||
auth: auth,
|
||||
controller: controller,
|
||||
haptics: haptics,
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('download-clear')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(repository.clearCalls, 0);
|
||||
@@ -155,23 +161,25 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(repository.clearCalls, 1);
|
||||
expect(haptics.mediumImpacts, 1);
|
||||
expect(find.byKey(const Key('downloads-empty')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('should_render_unique_quality_options_when_policy_uses_a_preset', (
|
||||
tester,
|
||||
) async {
|
||||
final auth = await _auth(signedIn: true);
|
||||
final repository = FakeDownloadRepository(
|
||||
policy: _policy(maxQuality: '720P'),
|
||||
);
|
||||
final controller = DownloadController(repository);
|
||||
testWidgets(
|
||||
'should_render_unique_quality_options_when_policy_uses_a_preset',
|
||||
(tester) async {
|
||||
final auth = await _auth(signedIn: true);
|
||||
final repository = FakeDownloadRepository(
|
||||
policy: _policy(maxQuality: '720P'),
|
||||
);
|
||||
final controller = DownloadController(repository);
|
||||
|
||||
await _pumpPage(tester, auth: auth, controller: controller);
|
||||
await _pumpPage(tester, auth: auth, controller: controller);
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.byKey(const Key('download-quality')), findsOneWidget);
|
||||
});
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.byKey(const Key('download-quality')), findsOneWidget);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<AuthController> _auth({required bool signedIn}) async {
|
||||
@@ -198,12 +206,14 @@ Future<void> _pumpPage(
|
||||
WidgetTester tester, {
|
||||
required AuthController auth,
|
||||
required DownloadController controller,
|
||||
FakeHaptics? haptics,
|
||||
}) async {
|
||||
await tester.pumpWidget(
|
||||
MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider<AuthController>.value(value: auth),
|
||||
ChangeNotifierProvider<DownloadController>.value(value: controller),
|
||||
Provider<Haptics>.value(value: haptics ?? FakeHaptics()),
|
||||
],
|
||||
child: MaterialApp(
|
||||
locale: const Locale('en'),
|
||||
|
||||
Reference in new issue
Block a user