mirror of
https://github.com/foss42/apidash.git
synced 2025-12-01 10:17:47 +08:00
Test cases generator modification to only Run test cases feature without response
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import '../services/dashbot_service.dart';
|
import 'package:apidash/dashbot/services/dashbot_service.dart';
|
||||||
import 'package:apidash/models/request_model.dart';
|
import 'package:apidash/models/request_model.dart';
|
||||||
|
|
||||||
class TestGeneratorFeature {
|
class TestGeneratorFeature {
|
||||||
@@ -67,7 +67,12 @@ For each test case:
|
|||||||
Focus on creating realistic test values based on the API context (e.g., for a country flag API, use real country codes, invalid codes, etc.)
|
Focus on creating realistic test values based on the API context (e.g., for a country flag API, use real country codes, invalid codes, etc.)
|
||||||
""";
|
""";
|
||||||
|
|
||||||
return _service.generateResponse(prompt);
|
// Generate the test cases
|
||||||
|
final testCases = await _service.generateResponse(prompt);
|
||||||
|
|
||||||
|
// Return only a button trigger message with the test cases hidden
|
||||||
|
// This will be detected in DashBotWidget to show only a button instead of the full text
|
||||||
|
return "TEST_CASES_HIDDEN\n$testCases";
|
||||||
}
|
}
|
||||||
|
|
||||||
String _analyzeParameters(Map<String, String> parameters) {
|
String _analyzeParameters(Map<String, String> parameters) {
|
||||||
|
|||||||
@@ -48,15 +48,25 @@ class _DashBotWidgetState extends ConsumerState<DashBotWidget> {
|
|||||||
final response = await dashBotService.handleRequest(
|
final response = await dashBotService.handleRequest(
|
||||||
message, requestModel, responseModel);
|
message, requestModel, responseModel);
|
||||||
|
|
||||||
// If "Test API" is requested, append a button to the response
|
// Check if this is a test case response with hidden content
|
||||||
final botMessage = message == "Test API"
|
if (response.startsWith("TEST_CASES_HIDDEN\n")) {
|
||||||
? "$response\n\n**[Run Test Cases]**"
|
// Extract the test cases but don't show them in the message
|
||||||
: response;
|
final testCases = response.replaceFirst("TEST_CASES_HIDDEN\n", "");
|
||||||
|
|
||||||
ref.read(chatMessagesProvider.notifier).addMessage({
|
// Add a message with a marker that will trigger the button display
|
||||||
'role': 'bot',
|
ref.read(chatMessagesProvider.notifier).addMessage({
|
||||||
'message': botMessage,
|
'role': 'bot',
|
||||||
});
|
'message': "Test cases generated successfully. Click the button below to run them.",
|
||||||
|
'testCases': testCases,
|
||||||
|
'showTestButton': true,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Normal message handling
|
||||||
|
ref.read(chatMessagesProvider.notifier).addMessage({
|
||||||
|
'role': 'bot',
|
||||||
|
'message': response,
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
debugPrint('Error in _sendMessage: $error');
|
debugPrint('Error in _sendMessage: $error');
|
||||||
debugPrint('StackTrace: $stackTrace');
|
debugPrint('StackTrace: $stackTrace');
|
||||||
@@ -191,20 +201,20 @@ class _DashBotWidgetState extends ConsumerState<DashBotWidget> {
|
|||||||
final message = messages.reversed.toList()[index];
|
final message = messages.reversed.toList()[index];
|
||||||
final isBot = message['role'] == 'bot';
|
final isBot = message['role'] == 'bot';
|
||||||
final text = message['message'] as String;
|
final text = message['message'] as String;
|
||||||
|
final showTestButton = message['showTestButton'] == true;
|
||||||
|
final testCases = message['testCases'] as String?;
|
||||||
|
|
||||||
// Check if the message contains the "Run Test Cases" button
|
if (isBot && showTestButton && testCases != null) {
|
||||||
if (isBot && text.contains("[Run Test Cases]")) {
|
|
||||||
final testCases = text.replaceAll("\n\n**[Run Test Cases]**", "");
|
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment:
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
isBot ? CrossAxisAlignment.start : CrossAxisAlignment.end,
|
|
||||||
children: [
|
children: [
|
||||||
ChatBubble(message: testCases, isUser: false),
|
ChatBubble(message: text, isUser: false),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(left: 12, top: 4, bottom: 4),
|
padding: const EdgeInsets.only(left: 12, top: 4, bottom: 4),
|
||||||
child: ElevatedButton(
|
child: ElevatedButton.icon(
|
||||||
onPressed: () => _showTestRunner(testCases),
|
onPressed: () => _showTestRunner(testCases),
|
||||||
child: const Text("Run Test Cases"),
|
icon: const Icon(Icons.play_arrow),
|
||||||
|
label: const Text("Run Test Cases"),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user