|
import 'package:auto_gpt_flutter_client/models/message_type.dart'; |
|
import 'package:auto_gpt_flutter_client/viewmodels/chat_viewmodel.dart'; |
|
import 'package:flutter_test/flutter_test.dart'; |
|
|
|
void main() { |
|
|
|
|
|
final viewModel = ChatViewModel(); |
|
|
|
group('ChatViewModel', () { |
|
test('fetch chats for a specific task', () { |
|
viewModel |
|
.fetchChatsForTask(1); |
|
expect(viewModel.chats.isNotEmpty, true); |
|
expect(viewModel.chats.every((chat) => chat.taskId == 1), true); |
|
}); |
|
|
|
test('send chat message for a specific task', () { |
|
final initialChatsLength = viewModel.chats.length; |
|
viewModel.sendChatMessage(1, 'Test message'); |
|
expect(viewModel.chats.length, |
|
initialChatsLength + 2); |
|
expect(viewModel.chats.last.messageType, |
|
MessageType.agent); |
|
}); |
|
|
|
|
|
test('fetch chats for invalid task id', () { |
|
viewModel.fetchChatsForTask( |
|
9999); |
|
expect( |
|
viewModel.chats.where((chat) => chat.taskId == 9999).isEmpty, true); |
|
}); |
|
|
|
|
|
test('send chat message for invalid task id', () { |
|
final initialChatsLength = viewModel.chats.length; |
|
viewModel.sendChatMessage(9999, 'Invalid test message'); |
|
expect( |
|
viewModel.chats.length, |
|
initialChatsLength + |
|
2); |
|
expect(viewModel.chats.last.messageType, |
|
MessageType.agent); |
|
}); |
|
}); |
|
} |
|
|