Remade frontend dashboard as flutter dashboard, still WIP

This commit is contained in:
Nate Anderson
2025-06-13 09:20:42 -06:00
parent 8ea06b12f7
commit b373a93f0e
207 changed files with 9869 additions and 46 deletions
@@ -0,0 +1,124 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:xp_dashboard/src/widgets/progress_card.dart';
import 'package:xp_models/xp_models.dart';
void main() {
group('ProgressCard Widget Tests', () {
testWidgets('displays progress correctly', (WidgetTester tester) async {
// Create test data
final stats = DashboardStats(
today: TodayStats(
level: 5,
xp: 1250,
focusTime: 14400, // 4 hours
meetingTime: 7200, // 2 hours
focusSessions: 4,
),
streaks: StreakStats(
currentStreak: 7,
longestStreak: 15,
),
recentActivity: [],
timestamp: DateTime.now().millisecondsSinceEpoch,
);
// Build the widget
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ProgressCard(stats: stats),
),
),
);
// Verify the progress items are displayed
expect(find.text('Today\'s Progress'), findsOneWidget);
expect(find.text('Focus Time'), findsOneWidget);
expect(find.text('Meeting Time'), findsOneWidget);
expect(find.text('Focus Sessions'), findsOneWidget);
// Check formatted durations
expect(find.text('4h 0m'), findsOneWidget); // Focus time
expect(find.text('2h 0m'), findsOneWidget); // Meeting time
expect(find.text('4'), findsOneWidget); // Focus sessions
// Check progress percentages
expect(find.text('50% of target'), findsOneWidget); // Focus time (4/8 hours)
expect(find.text('50% of target'), findsAtLeastNWidgets(2)); // Meeting time (2/4 hours) and focus sessions (4/8)
});
testWidgets('handles null stats gracefully', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: ProgressCard(stats: null),
),
),
);
// Should show loading indicator
expect(find.byType(CircularProgressIndicator), findsOneWidget);
expect(find.text('Today\'s Progress'), findsOneWidget);
});
testWidgets('formats duration correctly', (WidgetTester tester) async {
final stats = DashboardStats(
today: TodayStats(
level: 1,
xp: 100,
focusTime: 3665, // 1 hour, 1 minute, 5 seconds
meetingTime: 90, // 1 minute, 30 seconds
focusSessions: 1,
),
streaks: StreakStats(
currentStreak: 1,
longestStreak: 1,
),
recentActivity: [],
timestamp: DateTime.now().millisecondsSinceEpoch,
);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ProgressCard(stats: stats),
),
),
);
// Check formatted durations (should truncate seconds)
expect(find.text('1h 1m'), findsOneWidget); // Focus time
expect(find.text('0h 1m'), findsOneWidget); // Meeting time
});
testWidgets('calculates progress percentages correctly', (WidgetTester tester) async {
final stats = DashboardStats(
today: TodayStats(
level: 1,
xp: 100,
focusTime: 28800, // 8 hours (100% of target)
meetingTime: 14400, // 4 hours (100% of target)
focusSessions: 8, // 8 sessions (100% of target)
),
streaks: StreakStats(
currentStreak: 1,
longestStreak: 1,
),
recentActivity: [],
timestamp: DateTime.now().millisecondsSinceEpoch,
);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ProgressCard(stats: stats),
),
),
);
// All should show 100% of target
expect(find.text('100% of target'), findsNWidgets(3));
});
});
}
@@ -0,0 +1,87 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:xp_dashboard/src/widgets/stats_header.dart';
import 'package:xp_models/xp_models.dart';
void main() {
group('StatsHeader Widget Tests', () {
testWidgets('displays stats correctly', (WidgetTester tester) async {
// Create test data
final stats = DashboardStats(
today: TodayStats(
level: 5,
xp: 1250,
focusTime: 7200, // 2 hours
meetingTime: 3600, // 1 hour
focusSessions: 3,
),
streaks: StreakStats(
currentStreak: 7,
longestStreak: 15,
),
recentActivity: [],
timestamp: DateTime.now().millisecondsSinceEpoch,
);
// Build the widget
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: StatsHeader(stats: stats),
),
),
);
// Verify the stats are displayed
expect(find.text('5'), findsOneWidget); // Level
expect(find.text('1.3K'), findsOneWidget); // XP formatted
expect(find.text('7'), findsOneWidget); // Streak
expect(find.text('Level'), findsOneWidget);
expect(find.text('XP'), findsOneWidget);
expect(find.text('Streak'), findsOneWidget);
});
testWidgets('handles null stats gracefully', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: StatsHeader(stats: null),
),
),
);
// Should render empty container
expect(find.byType(SizedBox), findsOneWidget);
});
testWidgets('formats large numbers correctly', (WidgetTester tester) async {
final stats = DashboardStats(
today: TodayStats(
level: 50,
xp: 1500000, // 1.5M
focusTime: 0,
meetingTime: 0,
focusSessions: 0,
),
streaks: StreakStats(
currentStreak: 100,
longestStreak: 200,
),
recentActivity: [],
timestamp: DateTime.now().millisecondsSinceEpoch,
);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: StatsHeader(stats: stats),
),
),
);
expect(find.text('1.5M'), findsOneWidget); // XP formatted as millions
expect(find.text('50'), findsOneWidget); // Level
expect(find.text('100'), findsOneWidget); // Streak
});
});
}