mirror of
https://github.com/foss42/apidash.git
synced 2025-12-01 18:28:25 +08:00
test: add tests for chat viewmodel(cv: 50)
This commit is contained in:
@@ -50,19 +50,8 @@ class ChatViewmodel extends StateNotifier<ChatState> {
|
||||
}) async {
|
||||
final ai = _selectedAIModel;
|
||||
if (text.trim().isEmpty && countAsUser) return;
|
||||
if (ai == null &&
|
||||
type != ChatMessageType.importCurl &&
|
||||
type != ChatMessageType.importOpenApi) {
|
||||
debugPrint('[Chat] No AI model configured');
|
||||
_appendSystem(
|
||||
'AI model is not configured. Please set one.',
|
||||
type,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final requestId = _currentRequest?.id ?? 'global';
|
||||
final existingMessages = state.chatSessions[requestId] ?? const [];
|
||||
|
||||
if (countAsUser) {
|
||||
_addMessage(
|
||||
@@ -77,6 +66,19 @@ class ChatViewmodel extends StateNotifier<ChatState> {
|
||||
);
|
||||
}
|
||||
|
||||
if (ai == null &&
|
||||
type != ChatMessageType.importCurl &&
|
||||
type != ChatMessageType.importOpenApi) {
|
||||
debugPrint('[Chat] No AI model configured');
|
||||
_appendSystem(
|
||||
'AI model is not configured. Please set one.',
|
||||
type,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final existingMessages = state.chatSessions[requestId] ?? const [];
|
||||
|
||||
final lastSystemImport = existingMessages.lastWhere(
|
||||
(m) =>
|
||||
m.role == MessageRole.system &&
|
||||
@@ -409,7 +411,6 @@ class ChatViewmodel extends StateNotifier<ChatState> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String sourceTitle = (payload['sourceName'] as String?) ?? '';
|
||||
if (sourceTitle.trim().isEmpty) {
|
||||
final specObj = payload['spec'];
|
||||
@@ -931,12 +932,10 @@ class ChatViewmodel extends StateNotifier<ChatState> {
|
||||
// Helpers
|
||||
void _addMessage(String requestId, ChatMessage m) {
|
||||
final msgs = state.chatSessions[requestId] ?? const [];
|
||||
state = state.copyWith(
|
||||
chatSessions: {
|
||||
...state.chatSessions,
|
||||
requestId: [...msgs, m],
|
||||
},
|
||||
);
|
||||
final updatedSessions =
|
||||
Map<String, List<ChatMessage>>.from(state.chatSessions);
|
||||
updatedSessions[requestId] = [...msgs, m];
|
||||
state = state.copyWith(chatSessions: updatedSessions);
|
||||
}
|
||||
|
||||
void _appendSystem(String text, ChatMessageType type) {
|
||||
|
||||
Reference in New Issue
Block a user