Refactor app to focus on match results instead of tasks
- Introduced MatchRepository and MatchResultsViewModel to handle match data. - Replaced task-related code with match-related functionality in the app. - Added match results view and updated navigation to reflect changes. - Removed task-related models, services, and view models. - Added JSON data for match results and integrated it into the app. - Updated tests to validate match results loading and UI behavior.
This commit is contained in:
1 parent
ffc2051e20
commit
4d377c1336
17 files changed
+500
-658
No files matched your search
@@ -1,65 +0,0 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mobile_app/data/repositories/task_repository.dart';
|
||||
import 'package:mobile_app/data/services/mock_task_service.dart';
|
||||
import 'package:mobile_app/ui/features/dashboard/view_models/dashboard_view_model.dart';
|
||||
|
||||
void main() {
|
||||
group('DashboardViewModel', () {
|
||||
late MockTaskService service;
|
||||
late TaskRepository repository;
|
||||
late DashboardViewModel viewModel;
|
||||
|
||||
setUp(() {
|
||||
service = MockTaskService();
|
||||
repository = TaskRepository(service: service);
|
||||
viewModel = DashboardViewModel(repository: repository);
|
||||
});
|
||||
|
||||
test('initial state has empty tasks and not loading', () {
|
||||
expect(viewModel.tasks, isEmpty);
|
||||
expect(viewModel.isLoading, isFalse);
|
||||
expect(viewModel.selectedCategory, 'All');
|
||||
});
|
||||
|
||||
test('loadTasks fetches items from repository', () async {
|
||||
await viewModel.loadTasks();
|
||||
|
||||
expect(viewModel.tasks.isNotEmpty, isTrue);
|
||||
expect(viewModel.isLoading, isFalse);
|
||||
expect(viewModel.totalCount, greaterThan(0));
|
||||
});
|
||||
|
||||
test('toggleTaskCompletion toggles status', () async {
|
||||
await viewModel.loadTasks();
|
||||
final initialItem = viewModel.tasks.first;
|
||||
final initialStatus = initialItem.isCompleted;
|
||||
|
||||
await viewModel.toggleTaskCompletion(initialItem);
|
||||
|
||||
final updatedItem = viewModel.tasks.firstWhere((t) => t.id == initialItem.id);
|
||||
expect(updatedItem.isCompleted, equals(!initialStatus));
|
||||
});
|
||||
|
||||
test('category filter filters task list', () async {
|
||||
await viewModel.loadTasks();
|
||||
viewModel.setCategoryFilter('Design');
|
||||
|
||||
expect(viewModel.selectedCategory, equals('Design'));
|
||||
expect(viewModel.tasks.every((t) => t.category == 'Design'), isTrue);
|
||||
});
|
||||
|
||||
test('addTask adds a new task to list', () async {
|
||||
await viewModel.loadTasks();
|
||||
final countBefore = viewModel.totalCount;
|
||||
|
||||
await viewModel.addTask(
|
||||
title: 'New Unit Test Task',
|
||||
description: 'Verify adding tasks',
|
||||
category: 'A11y',
|
||||
);
|
||||
|
||||
expect(viewModel.totalCount, equals(countBefore + 1));
|
||||
expect(viewModel.tasks.any((t) => t.title == 'New Unit Test Task'), isTrue);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mobile_app/data/repositories/match_repository.dart';
|
||||
import 'package:mobile_app/ui/features/dashboard/view_models/match_results_view_model.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
test('loads match results and their events from bundled JSON', () async {
|
||||
final viewModel = MatchResultsViewModel(repository: MatchRepository());
|
||||
addTearDown(viewModel.dispose);
|
||||
|
||||
await viewModel.loadMatches();
|
||||
|
||||
expect(viewModel.isLoading, isFalse);
|
||||
expect(viewModel.errorMessage, isNull);
|
||||
expect(viewModel.matches, hasLength(3));
|
||||
expect(viewModel.matches.first.homeScore, 1);
|
||||
expect(viewModel.matches.first.goals, hasLength(2));
|
||||
expect(viewModel.matches.first.goals.first.seconds, 88);
|
||||
expect(viewModel.matches.first.goals.first.team.name, 'away');
|
||||
expect(viewModel.matches.first.cards.first.cardType.name, 'red');
|
||||
});
|
||||
}
|
||||
@@ -2,15 +2,14 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mobile_app/app.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('App smoke test - renders dashboard, navigates to settings',
|
||||
testWidgets('App smoke test - renders match results, navigates to settings',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(const MobileApp());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Verify Dashboard is visible
|
||||
expect(find.text('Dashboard'), findsWidgets);
|
||||
expect(find.text('Task Progress'), findsOneWidget);
|
||||
expect(find.text('Add Task'), findsOneWidget);
|
||||
expect(find.text('Match Results'), findsOneWidget);
|
||||
expect(find.text('Home'), findsWidgets);
|
||||
expect(find.text('Away'), findsWidgets);
|
||||
|
||||
// Switch to Settings tab
|
||||
final settingsNav = find.text('Settings');
|
||||
@@ -24,10 +23,10 @@ void main() {
|
||||
expect(find.text('Android & iOS (iPhone/iPad)'), findsOneWidget);
|
||||
|
||||
// Switch back to Dashboard
|
||||
final dashboardNav = find.text('Dashboard');
|
||||
await tester.tap(dashboardNav.first);
|
||||
final resultsNav = find.text('Results');
|
||||
await tester.tap(resultsNav.first);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Task Progress'), findsOneWidget);
|
||||
expect(find.text('Match Results'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user