Skip to content

Conversation

Udhay-Adithya
Copy link
Contributor

PR Description

Add more tests for chat_viewmodel.dart

Related Issues

  • Closes #

Checklist

  • I have gone through the contributing guide
  • I have updated my branch and synced it with project main branch before making this PR
  • I am using the latest Flutter stable branch (run flutter upgrade and verify)
  • I have run the tests (flutter test) and all tests are passing

Added/updated tests?

  • Yes
  • No, and this is why: please replace this line with details on why tests have not been included

OS on which you have developed and tested the feature?

  • Windows
  • macOS
  • Linux

@Udhay-Adithya
Copy link
Contributor Author

Udhay-Adithya commented Oct 1, 2025

The deleted test/providers/dashbot_window_notifier_test.dart was written during the initial implementation of dashbot and is supposed to be removed. Now the latest tests for the same exists at test/dashbot/providers/dashbot_window_notifier_test.dart

@animator animator requested review from Copilot and animator October 2, 2025 12:27
@animator animator added the gsoc25 label Oct 2, 2025
Copy link
Contributor

@Copilot Copilot AI left a 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.

Comment on lines +778 to +812
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}');
Copy link
Preview

Copilot AI Oct 2, 2025

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.

Suggested change
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.

Comment on lines +16 to +17
/// This file contains tests specifically for AI-enabled chat functionality,
// A mock ChatRemoteRepository returning configurable responses
Copy link
Preview

Copilot AI Oct 2, 2025

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.

Suggested change
/// 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);
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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);
Copy link
Member

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
Copy link
Member

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?

@animator
Copy link
Member

animator commented Oct 2, 2025

The deleted test/providers/dashbot_window_notifier_test.dart was written during the initial implementation of dashbot and is supposed to be removed. Now the latest tests for the same exists at test/dashbot/providers/dashbot_window_notifier_test.dart

Got it. Thanks for letting us know.

Copy link
Member

@ashitaprasad ashitaprasad left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants