mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-27 19:04:25 +01:00
This commit introduces the ChatViewModel, which manages the business logic for chat interactions associated with tasks. The ViewModel communicates with a mock data source, offering functionalities like fetching chats for a specific task and sending chat messages. In addition to the implementation, comprehensive tests for ChatViewModel have been provided to ensure its behavior is consistent with our design goals and expectations. Key Features: Chat management in ChatViewModel. Tests covering all major functionalities of ChatViewModel. Mock data source updates to emulate chat data interactions.
77 lines
2.2 KiB
Dart
77 lines
2.2 KiB
Dart
import 'package:auto_gpt_flutter_client/viewmodels/task_viewmodel.dart';
|
|
import 'package:auto_gpt_flutter_client/viewmodels/mock_data.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
group('TaskViewModel', () {
|
|
late TaskViewModel viewModel;
|
|
|
|
setUp(() {
|
|
viewModel = TaskViewModel();
|
|
});
|
|
|
|
test('Fetches tasks successfully', () {
|
|
viewModel.fetchTasks();
|
|
expect(viewModel.tasks, isNotEmpty);
|
|
});
|
|
|
|
test('Selects a task successfully', () {
|
|
viewModel.fetchTasks();
|
|
viewModel.selectTask(1);
|
|
expect(viewModel.selectedTask, isNotNull);
|
|
});
|
|
|
|
test(
|
|
'Notifiers are properly telling UI to update after fetching a task or selecting a task',
|
|
() {
|
|
bool hasNotified = false;
|
|
viewModel.addListener(() {
|
|
hasNotified = true;
|
|
});
|
|
|
|
viewModel.fetchTasks();
|
|
expect(hasNotified, true);
|
|
|
|
hasNotified = false; // Reset for next test
|
|
viewModel.selectTask(1);
|
|
expect(hasNotified, true);
|
|
});
|
|
|
|
test('No tasks are fetched', () {
|
|
// Clear mock data for this test
|
|
mockTasks.clear();
|
|
|
|
viewModel.fetchTasks();
|
|
expect(viewModel.tasks, isEmpty);
|
|
});
|
|
|
|
test('No task is selected', () {
|
|
expect(viewModel.selectedTask, isNull);
|
|
});
|
|
|
|
test('Creates a task successfully', () {
|
|
final initialCount = viewModel.tasks.length;
|
|
viewModel.createTask('New Task');
|
|
expect(viewModel.tasks.length, initialCount + 1);
|
|
});
|
|
|
|
test('Deletes a task successfully', () {
|
|
viewModel.fetchTasks();
|
|
final initialCount = viewModel.tasks.length;
|
|
viewModel.deleteTask(1);
|
|
expect(viewModel.tasks.length, initialCount - 1);
|
|
});
|
|
|
|
test('Deletes a task with invalid id', () {
|
|
// TODO: Update this test to expect an error once we have TaskService implemented
|
|
final initialCount = viewModel.tasks.length;
|
|
viewModel.deleteTask(9999); // Assuming no task with this id exists
|
|
expect(viewModel.tasks.length, initialCount); // Count remains same
|
|
});
|
|
|
|
test('Select a task that doesn\'t exist', () {
|
|
expect(() => viewModel.selectTask(9999), throwsA(isA<ArgumentError>()));
|
|
});
|
|
});
|
|
}
|