full app done

This commit is contained in:
davmar
2026-09-18 00:01:42 +02:00
parent 8475abeddb
commit 78fd23f69f
74 changed files with 8104 additions and 1963 deletions
+56 -43
View File
@@ -1,66 +1,79 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:myapp/main.dart';
import 'package:myapp/models/item.dart';
import 'package:myapp/services/item_repository.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;
Future<void> pumpApp(WidgetTester tester) async {
testWidgets('splash shows Values Sort then opens welcome', (tester) async {
SharedPreferences.setMockInitialValues({});
final storage = StorageService();
await storage.init();
await tester.pumpWidget(
MyApp(
storage: storage,
repository: ItemRepository(),
),
);
}
testWidgets('splash shows the app name then opens Home', (tester) async {
await pumpApp(tester);
await tester.pumpWidget(MyApp(storage: storage));
expect(find.text(kAppName), findsWidgets);
await tester.pump(kSplashDuration);
await tester.pump(const Duration(milliseconds: 450));
await tester.pump(const Duration(milliseconds: 350));
await tester.pump(const Duration(milliseconds: 500));
await tester.pump(const Duration(milliseconds: 200));
expect(find.text('Home'), findsWidgets);
expect(find.text('Featured items'), findsOneWidget);
expect(find.text('Search'), findsOneWidget);
expect(find.text('Profile'), findsOneWidget);
expect(find.text('Settings'), findsOneWidget);
expect(find.text('Begin Reflection'), findsOneWidget);
expect(find.textContaining('Discover what matters'), findsOneWidget);
});
testWidgets('tapping a list card opens the detail screen', (tester) async {
await pumpApp(tester);
await tester.pump(kSplashDuration);
await tester.pump(const Duration(milliseconds: 450));
await tester.pump(const Duration(milliseconds: 350));
await tester.tap(find.text('Material 3 surfaces'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
expect(find.text('Details'), findsOneWidget);
expect(find.text('Back to list'), findsOneWidget);
});
test('Item.fromJson maps a JSONPlaceholder post', () {
final item = Item.fromJson({
'id': 3,
'title': 'hello world',
'body': 'First sentence. Second sentence.',
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');
});
expect(item.id, 'remote-3');
expect(item.title, 'Hello world');
expect(item.subtitle, 'First sentence.');
expect(item.category, ItemCategory.lifestyle);
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();
});
}