80 lines
2.5 KiB
Dart
80 lines
2.5 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:google_fonts/google_fonts.dart';
|
|
import 'package:myapp/main.dart';
|
|
import 'package:myapp/models/value_card.dart';
|
|
import 'package:myapp/models/value_pile.dart';
|
|
import 'package:myapp/providers/values_sort_provider.dart';
|
|
import 'package:myapp/services/storage_service.dart';
|
|
import 'package:myapp/utils/constants.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
GoogleFonts.config.allowRuntimeFetching = false;
|
|
|
|
testWidgets('splash shows Values Sort then opens welcome', (tester) async {
|
|
SharedPreferences.setMockInitialValues({});
|
|
final storage = StorageService();
|
|
await storage.init();
|
|
await tester.pumpWidget(MyApp(storage: storage));
|
|
|
|
expect(find.text(kAppName), findsWidgets);
|
|
|
|
await tester.pump(kSplashDuration);
|
|
await tester.pump(const Duration(milliseconds: 500));
|
|
await tester.pump(const Duration(milliseconds: 200));
|
|
|
|
expect(find.text('Begin Reflection'), findsOneWidget);
|
|
expect(find.textContaining('Discover what matters'), findsOneWidget);
|
|
});
|
|
|
|
test('ValueCard and ValuePile helpers', () {
|
|
final card = ValueCard.fromJson({
|
|
'id': 'v1',
|
|
'title': 'Courage',
|
|
'description': 'Acting despite fear.',
|
|
'domain': 'Agency',
|
|
});
|
|
expect(card.title, 'Courage');
|
|
expect(ValuePile.mostImportant.rank, 5);
|
|
expect(ValuePile.notImportant.shortLabel, 'Not');
|
|
});
|
|
|
|
testWidgets('sort progress persists across controller reloads', (tester) async {
|
|
SharedPreferences.setMockInitialValues({});
|
|
final storage = StorageService();
|
|
await storage.init();
|
|
|
|
const seed = [
|
|
ValueCard(
|
|
id: 'v001',
|
|
title: 'Acceptance',
|
|
description: 'To be accepted as I am',
|
|
),
|
|
ValueCard(
|
|
id: 'v002',
|
|
title: 'Accuracy',
|
|
description: 'To be accurate in my opinions and beliefs',
|
|
),
|
|
];
|
|
|
|
final first = ValuesSortController(storage: storage);
|
|
await first.load(seedDeck: seed);
|
|
first.beginPractice();
|
|
final cardId = first.currentCard!.id;
|
|
first.assignCurrent(ValuePile.mostImportant);
|
|
await tester.pump();
|
|
|
|
expect(storage.sortSessionJson, isNotNull);
|
|
|
|
first.dispose();
|
|
|
|
final second = ValuesSortController(storage: storage);
|
|
await second.load(seedDeck: seed);
|
|
expect(second.stage, SortStage.sorting);
|
|
expect(second.assignments[cardId], ValuePile.mostImportant);
|
|
expect(second.sortedCount, 1);
|
|
second.dispose();
|
|
});
|
|
}
|