Files
minstrel/flutter_client/test/settings/storage_section_test.dart
T
bvandeusen a3db6c9453 fix(flutter/test): testWidgets skip takes bool, not String
CI analyze flagged storage_section_test.dart's `skip: _skipDrift` calls.
testWidgets has signature `skip: bool?`; only test() takes `String?` as
the skip-reason. Changed _skipDrift in this file to `const bool = true`
and moved the rationale into a comment. The other two drift-cohort
files (sync_controller_test, audio_cache_manager_test) use test() so
their String const is fine.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 10:41:48 -04:00

85 lines
3.1 KiB
Dart

@Tags(['drift'])
library;
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:minstrel/auth/auth_provider.dart';
import 'package:minstrel/settings/storage_section.dart';
import 'package:minstrel/theme/theme_data.dart';
class _MockStorage extends Mock implements FlutterSecureStorage {}
// StorageSection.initState calls audioCacheManagerProvider.usageBytes()
// which opens the AppDb via NativeDatabase. CI's flutter-ci runner
// lacks libsqlite3.so so this silently emits a warning today and would
// break under stricter analyze. Skipped with the drift cohort.
//
// testWidgets only accepts a bool for skip (unlike test() which takes
// a String reason). Reason: 'libsqlite3 missing on flutter-ci runner;
// on-device covers'. See Fable #399.
const _skipDrift = true;
void main() {
setUpAll(() {
registerFallbackValue('');
});
testWidgets('renders Storage heading + all controls', skip: _skipDrift, (t) async {
final storage = _MockStorage();
when(() => storage.read(key: any(named: 'key')))
.thenAnswer((_) async => null);
when(() => storage.write(
key: any(named: 'key'), value: any(named: 'value')))
.thenAnswer((_) async {});
await t.pumpWidget(ProviderScope(
overrides: [secureStorageProvider.overrideWithValue(storage)],
child: MaterialApp(
theme: buildDarkTheme(),
home: const Scaffold(body: StorageSection()),
),
));
await t.pumpAndSettle();
expect(find.text('Storage'), findsOneWidget);
expect(find.text('Cache size limit'), findsOneWidget);
expect(find.text('Pre-fetch ahead'), findsOneWidget);
expect(find.byKey(const Key('clear_cache_button')), findsOneWidget);
expect(find.byKey(const Key('sync_now_button')), findsOneWidget);
expect(find.byKey(const Key('cache_liked_toggle')), findsOneWidget);
expect(find.byKey(const Key('cap_selector')), findsOneWidget);
expect(find.byKey(const Key('prefetch_selector')), findsOneWidget);
});
testWidgets('Clear cache button shows confirm dialog', skip: _skipDrift, (t) async {
final storage = _MockStorage();
when(() => storage.read(key: any(named: 'key')))
.thenAnswer((_) async => null);
when(() => storage.write(
key: any(named: 'key'), value: any(named: 'value')))
.thenAnswer((_) async {});
await t.pumpWidget(ProviderScope(
overrides: [secureStorageProvider.overrideWithValue(storage)],
child: MaterialApp(
theme: buildDarkTheme(),
home: const Scaffold(body: StorageSection()),
),
));
await t.pumpAndSettle();
await t.tap(find.byKey(const Key('clear_cache_button')));
await t.pumpAndSettle();
expect(find.text('Clear cache?'), findsOneWidget);
// Cancel returns to the original state.
await t.tap(find.text('Cancel'));
await t.pumpAndSettle();
expect(find.text('Clear cache?'), findsNothing);
});
}