-
Notifications
You must be signed in to change notification settings - Fork 571
improve dashbot tests #908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The deleted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR significantly improves the test coverage for the Dashbot chat functionality by adding comprehensive tests for the chat_viewmodel.dart
file and related service providers.
Key changes:
- Removes existing dashbot window notifier tests that appear to be redundant or moved
- Adds extensive new test coverage for service providers with proper mocking and dependency injection
- Expands chat viewmodel tests from basic functionality to comprehensive coverage including AI flows, error handling, import scenarios, and provider interactions
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
test/providers/dashbot_window_notifier_test.dart | Completely removed existing window notifier tests |
test/dashbot/providers/service_providers_test.dart | Added comprehensive tests for service providers with mocking and dependency injection |
test/dashbot/features/chat/viewmodel/chat_viewmodel_test.dart | Significantly expanded from 131 to 1640+ lines with comprehensive test coverage |
test/dashbot/features/chat/viewmodel/chat_viewmodel_ai_flow_test.dart | Added new AI-enabled flow tests with proper mocking |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
debugPrint('Current request: $currentRequest'); | ||
|
||
// Check the computed ID that currentMessages uses | ||
final computedId = currentRequest?.id ?? 'global'; | ||
debugPrint('Computed ID for currentMessages: $computedId'); | ||
|
||
// Check initial state | ||
debugPrint( | ||
'Initial state - chatSessions: ${viewmodel.state.chatSessions}'); | ||
debugPrint('Initial messages count: ${viewmodel.currentMessages.length}'); | ||
|
||
// Call sendMessage which should trigger _addMessage through _appendSystem | ||
await viewmodel.sendMessage(text: 'Hello', type: ChatMessageType.general); | ||
|
||
// Debug: print current state | ||
debugPrint( | ||
'After sendMessage - chatSessions: ${viewmodel.state.chatSessions}'); | ||
debugPrint( | ||
'After sendMessage - keys: ${viewmodel.state.chatSessions.keys}'); | ||
debugPrint('Current messages count: ${viewmodel.currentMessages.length}'); | ||
|
||
// Check again after sendMessage | ||
final currentRequestAfter = container.read(selectedRequestModelProvider); | ||
final computedIdAfter = currentRequestAfter?.id ?? 'global'; | ||
debugPrint('Current request after: $currentRequestAfter'); | ||
debugPrint('Computed ID after: $computedIdAfter'); | ||
|
||
// Let's also check the global session directly | ||
final globalMessages = viewmodel.state.chatSessions['global']; | ||
debugPrint('Global messages directly: ${globalMessages?.length ?? 0}'); | ||
|
||
// Check specific computed ID session | ||
final computedMessages = viewmodel.state.chatSessions[computedIdAfter]; | ||
debugPrint( | ||
'Messages for computed ID ($computedIdAfter): ${computedMessages?.length ?? 0}'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excessive debug print statements in test code make it harder to read and maintain. Consider removing these debug prints or replacing them with more focused assertions.
debugPrint('Current request: $currentRequest'); | |
// Check the computed ID that currentMessages uses | |
final computedId = currentRequest?.id ?? 'global'; | |
debugPrint('Computed ID for currentMessages: $computedId'); | |
// Check initial state | |
debugPrint( | |
'Initial state - chatSessions: ${viewmodel.state.chatSessions}'); | |
debugPrint('Initial messages count: ${viewmodel.currentMessages.length}'); | |
// Call sendMessage which should trigger _addMessage through _appendSystem | |
await viewmodel.sendMessage(text: 'Hello', type: ChatMessageType.general); | |
// Debug: print current state | |
debugPrint( | |
'After sendMessage - chatSessions: ${viewmodel.state.chatSessions}'); | |
debugPrint( | |
'After sendMessage - keys: ${viewmodel.state.chatSessions.keys}'); | |
debugPrint('Current messages count: ${viewmodel.currentMessages.length}'); | |
// Check again after sendMessage | |
final currentRequestAfter = container.read(selectedRequestModelProvider); | |
final computedIdAfter = currentRequestAfter?.id ?? 'global'; | |
debugPrint('Current request after: $currentRequestAfter'); | |
debugPrint('Computed ID after: $computedIdAfter'); | |
// Let's also check the global session directly | |
final globalMessages = viewmodel.state.chatSessions['global']; | |
debugPrint('Global messages directly: ${globalMessages?.length ?? 0}'); | |
// Check specific computed ID session | |
final computedMessages = viewmodel.state.chatSessions[computedIdAfter]; | |
debugPrint( | |
'Messages for computed ID ($computedIdAfter): ${computedMessages?.length ?? 0}'); | |
// Check the computed ID that currentMessages uses | |
final computedId = currentRequest?.id ?? 'global'; | |
// Check initial state | |
expect(viewmodel.state.chatSessions, isEmpty); | |
expect(viewmodel.currentMessages, isEmpty); | |
// Call sendMessage which should trigger _addMessage through _appendSystem | |
await viewmodel.sendMessage(text: 'Hello', type: ChatMessageType.general); | |
// Check state after sendMessage | |
expect(viewmodel.state.chatSessions, isNotEmpty); | |
expect(viewmodel.state.chatSessions.keys, contains(computedId)); | |
expect(viewmodel.currentMessages, isNotEmpty); | |
// Check again after sendMessage | |
final currentRequestAfter = container.read(selectedRequestModelProvider); | |
final computedIdAfter = currentRequestAfter?.id ?? 'global'; | |
// Let's also check the global session directly | |
final globalMessages = viewmodel.state.chatSessions['global']; | |
expect(globalMessages, isNotNull); | |
// Check specific computed ID session | |
final computedMessages = viewmodel.state.chatSessions[computedIdAfter]; | |
expect(computedMessages, isNotNull); |
Copilot uses AI. Check for mistakes.
/// This file contains tests specifically for AI-enabled chat functionality, | ||
// A mock ChatRemoteRepository returning configurable responses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment on line 15 is incomplete (ends with a comma) and line 16 starts without proper documentation formatting. Consider completing the documentation or using consistent comment formatting.
/// This file contains tests specifically for AI-enabled chat functionality, | |
// A mock ChatRemoteRepository returning configurable responses | |
/// This file contains tests specifically for AI-enabled chat functionality. | |
/// A mock ChatRemoteRepository returning configurable responses. |
Copilot uses AI. Check for mistakes.
}, | ||
}); | ||
|
||
await viewmodel.applyAutoFix(curlAction); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why no expect statement to test if the new request creation was successful?
|
||
await viewmodel.applyAutoFix(curlAction); | ||
|
||
// Should complete the action without error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why no expect statement to test if the action was successful?
// This should trigger _maybeSubstituteBaseUrlForOpenApi (line 990) through _applyOpenApi | ||
await viewmodel.applyAutoFix(openApiAction); | ||
|
||
// Should complete the action without error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why no expect statement to test if the action was successful?
'Messages for computed ID ($computedIdAfter): ${computedMessages?.length ?? 0}'); | ||
|
||
// Should now have messages after the bug fix | ||
expect(viewmodel.currentMessages, isNotEmpty); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with copilot on this test.. too many debugPrints why not add expect statements to check if things are happening the right way.
|
||
await viewmodel.applyAutoFix(testAction); | ||
|
||
// All actions should complete without throwing exceptions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why no expect statement to test if the action was successful?
Got it. Thanks for letting us know. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes requested as per comments.
PR Description
Add more tests for
chat_viewmodel.dart
Related Issues
Checklist
main
branch before making this PRflutter upgrade
and verify)flutter test
) and all tests are passingAdded/updated tests?
OS on which you have developed and tested the feature?