mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-18 06:24:20 +01:00
Introduce TestOption Enum for Enhanced Test Selection Clarity (#5586)
This commit is contained in:
65
frontend/lib/models/test_option.dart
Normal file
65
frontend/lib/models/test_option.dart
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/// `TestOption` is an enumeration of the available test options that can be selected in the skill tree view.
|
||||||
|
///
|
||||||
|
/// Each value of this enum represents a distinct test option that can be executed.
|
||||||
|
/// The `description` getter can be used to get the string representation of each test option.
|
||||||
|
enum TestOption {
|
||||||
|
/// Represents the option to run a single test.
|
||||||
|
runSingleTest,
|
||||||
|
|
||||||
|
/// Represents the option to run a test suite including the selected node and its ancestors.
|
||||||
|
runTestSuiteIncludingSelectedNodeAndAncestors,
|
||||||
|
|
||||||
|
/// Represents the option to run all tests in a category.
|
||||||
|
runAllTestsInCategory,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An extension on the `TestOption` enum to provide a string representation for each test option.
|
||||||
|
///
|
||||||
|
/// This extension adds a `description` getter on `TestOption` to easily retrieve the human-readable
|
||||||
|
/// string associated with each option. This is particularly helpful for UI display purposes.
|
||||||
|
extension TestOptionExtension on TestOption {
|
||||||
|
/// Gets the string representation of the test option.
|
||||||
|
///
|
||||||
|
/// Returns a human-readable string that describes the test option. This string is intended
|
||||||
|
/// to be displayed in the UI for user selection.
|
||||||
|
String get description {
|
||||||
|
switch (this) {
|
||||||
|
/// In case of a single test option, return the corresponding string.
|
||||||
|
case TestOption.runSingleTest:
|
||||||
|
return 'Run single test';
|
||||||
|
|
||||||
|
/// In case of a test suite option that includes selected node and ancestors, return the corresponding string.
|
||||||
|
case TestOption.runTestSuiteIncludingSelectedNodeAndAncestors:
|
||||||
|
return 'Run test suite including selected node and ancestors';
|
||||||
|
|
||||||
|
/// In case of an option to run all tests in a category, return the corresponding string.
|
||||||
|
case TestOption.runAllTestsInCategory:
|
||||||
|
return 'Run all tests in category';
|
||||||
|
|
||||||
|
/// In case of an undefined or unknown test option, return a generic unknown string.
|
||||||
|
/// This case should ideally never be hit if all enum values are handled.
|
||||||
|
default:
|
||||||
|
return 'Unknown';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Converts a [description] string to its corresponding [TestOption] enum value.
|
||||||
|
///
|
||||||
|
/// This method is helpful for converting string representations of test options
|
||||||
|
/// received from various sources (like user input or server responses) into
|
||||||
|
/// their type-safe enum equivalents.
|
||||||
|
///
|
||||||
|
/// Returns the matching [TestOption] enum value if found, otherwise returns `null`.
|
||||||
|
static TestOption? fromDescription(String description) {
|
||||||
|
switch (description) {
|
||||||
|
case 'Run single test':
|
||||||
|
return TestOption.runSingleTest;
|
||||||
|
case 'Run test suite including selected node and ancestors':
|
||||||
|
return TestOption.runTestSuiteIncludingSelectedNodeAndAncestors;
|
||||||
|
case 'Run all tests in category':
|
||||||
|
return TestOption.runAllTestsInCategory;
|
||||||
|
default:
|
||||||
|
return null; // or throw an exception, or provide a default value, as per your requirement
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import 'package:auto_gpt_flutter_client/models/skill_tree/skill_tree_edge.dart';
|
|||||||
import 'package:auto_gpt_flutter_client/models/skill_tree/skill_tree_node.dart';
|
import 'package:auto_gpt_flutter_client/models/skill_tree/skill_tree_node.dart';
|
||||||
import 'package:auto_gpt_flutter_client/models/step.dart';
|
import 'package:auto_gpt_flutter_client/models/step.dart';
|
||||||
import 'package:auto_gpt_flutter_client/models/task.dart';
|
import 'package:auto_gpt_flutter_client/models/task.dart';
|
||||||
|
import 'package:auto_gpt_flutter_client/models/test_option.dart';
|
||||||
import 'package:auto_gpt_flutter_client/models/test_suite.dart';
|
import 'package:auto_gpt_flutter_client/models/test_suite.dart';
|
||||||
import 'package:auto_gpt_flutter_client/services/benchmark_service.dart';
|
import 'package:auto_gpt_flutter_client/services/benchmark_service.dart';
|
||||||
import 'package:auto_gpt_flutter_client/services/leaderboard_service.dart';
|
import 'package:auto_gpt_flutter_client/services/leaderboard_service.dart';
|
||||||
@@ -39,8 +40,8 @@ class SkillTreeViewModel extends ChangeNotifier {
|
|||||||
// TODO: Potentially move to task queue view model when we create one
|
// TODO: Potentially move to task queue view model when we create one
|
||||||
List<SkillTreeNode>? _selectedNodeHierarchy;
|
List<SkillTreeNode>? _selectedNodeHierarchy;
|
||||||
|
|
||||||
String _selectedOption = 'Run single test';
|
TestOption _selectedOption = TestOption.runSingleTest;
|
||||||
String get selectedOption => _selectedOption;
|
TestOption get selectedOption => _selectedOption;
|
||||||
|
|
||||||
List<SkillTreeNode> get skillTreeNodes => _skillTreeNodes;
|
List<SkillTreeNode> get skillTreeNodes => _skillTreeNodes;
|
||||||
List<SkillTreeEdge> get skillTreeEdges => _skillTreeEdges;
|
List<SkillTreeEdge> get skillTreeEdges => _skillTreeEdges;
|
||||||
@@ -110,21 +111,20 @@ class SkillTreeViewModel extends ChangeNotifier {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateSelectedNodeHierarchyBasedOnOption(String selectedOption) {
|
void updateSelectedNodeHierarchyBasedOnOption(TestOption selectedOption) {
|
||||||
_selectedOption = selectedOption;
|
_selectedOption = selectedOption;
|
||||||
switch (selectedOption) {
|
switch (selectedOption) {
|
||||||
// TODO: Turn this into enum
|
case TestOption.runSingleTest:
|
||||||
case 'Run single test':
|
|
||||||
_selectedNodeHierarchy = _selectedNode != null ? [_selectedNode!] : [];
|
_selectedNodeHierarchy = _selectedNode != null ? [_selectedNode!] : [];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'Run test suite including selected node and ancestors':
|
case TestOption.runTestSuiteIncludingSelectedNodeAndAncestors:
|
||||||
if (_selectedNode != null) {
|
if (_selectedNode != null) {
|
||||||
populateSelectedNodeHierarchy(_selectedNode!.id);
|
populateSelectedNodeHierarchy(_selectedNode!.id);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'Run all tests in category':
|
case TestOption.runAllTestsInCategory:
|
||||||
if (_selectedNode != null) {
|
if (_selectedNode != null) {
|
||||||
_getAllNodesInDepthFirstOrderEnsuringParents();
|
_getAllNodesInDepthFirstOrderEnsuringParents();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'package:auto_gpt_flutter_client/models/benchmark/benchmark_task_status.dart';
|
import 'package:auto_gpt_flutter_client/models/benchmark/benchmark_task_status.dart';
|
||||||
|
import 'package:auto_gpt_flutter_client/models/test_option.dart';
|
||||||
import 'package:auto_gpt_flutter_client/viewmodels/chat_viewmodel.dart';
|
import 'package:auto_gpt_flutter_client/viewmodels/chat_viewmodel.dart';
|
||||||
import 'package:auto_gpt_flutter_client/viewmodels/task_viewmodel.dart';
|
import 'package:auto_gpt_flutter_client/viewmodels/task_viewmodel.dart';
|
||||||
import 'package:auto_gpt_flutter_client/views/task_queue/leaderboard_submission_button.dart';
|
import 'package:auto_gpt_flutter_client/views/task_queue/leaderboard_submission_button.dart';
|
||||||
@@ -98,11 +99,11 @@ class TaskQueueView extends StatelessWidget {
|
|||||||
// TestSuiteButton
|
// TestSuiteButton
|
||||||
TestSuiteButton(
|
TestSuiteButton(
|
||||||
isDisabled: viewModel.isBenchmarkRunning,
|
isDisabled: viewModel.isBenchmarkRunning,
|
||||||
selectedOption: viewModel.selectedOption,
|
selectedOptionString: viewModel.selectedOption.description,
|
||||||
onOptionSelected: (selectedOption) {
|
onOptionSelected: (selectedOption) {
|
||||||
print('Option Selected: $selectedOption');
|
print('Option Selected: $selectedOption');
|
||||||
viewModel.updateSelectedNodeHierarchyBasedOnOption(
|
viewModel.updateSelectedNodeHierarchyBasedOnOption(
|
||||||
selectedOption);
|
TestOptionExtension.fromDescription(selectedOption)!);
|
||||||
},
|
},
|
||||||
onPlayPressed: (selectedOption) {
|
onPlayPressed: (selectedOption) {
|
||||||
print('Starting benchmark with option: $selectedOption');
|
print('Starting benchmark with option: $selectedOption');
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
import 'package:auto_gpt_flutter_client/constants/app_colors.dart';
|
import 'package:auto_gpt_flutter_client/constants/app_colors.dart';
|
||||||
|
import 'package:auto_gpt_flutter_client/models/test_option.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class TestSuiteButton extends StatefulWidget {
|
class TestSuiteButton extends StatefulWidget {
|
||||||
final bool isDisabled;
|
final bool isDisabled;
|
||||||
final Function(String) onOptionSelected;
|
final Function(String) onOptionSelected;
|
||||||
final Function(String) onPlayPressed;
|
final Function(String) onPlayPressed;
|
||||||
String selectedOption;
|
String selectedOptionString;
|
||||||
|
|
||||||
TestSuiteButton({
|
TestSuiteButton({
|
||||||
this.isDisabled = false,
|
this.isDisabled = false,
|
||||||
required this.onOptionSelected,
|
required this.onOptionSelected,
|
||||||
required this.onPlayPressed,
|
required this.onPlayPressed,
|
||||||
required this.selectedOption,
|
required this.selectedOptionString,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -30,24 +31,27 @@ class _TestSuiteButtonState extends State<TestSuiteButton> {
|
|||||||
enabled: !widget.isDisabled,
|
enabled: !widget.isDisabled,
|
||||||
onSelected: (value) {
|
onSelected: (value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
widget.selectedOption = value;
|
widget.selectedOptionString = value;
|
||||||
});
|
});
|
||||||
widget.onOptionSelected(widget.selectedOption);
|
widget.onOptionSelected(widget.selectedOptionString);
|
||||||
},
|
},
|
||||||
itemBuilder: (BuildContext context) {
|
itemBuilder: (BuildContext context) {
|
||||||
return [
|
return [
|
||||||
const PopupMenuItem(
|
PopupMenuItem(
|
||||||
value: 'Run single test',
|
value: TestOption.runSingleTest.description,
|
||||||
child: Text('Run single test'),
|
child: Text(TestOption.runSingleTest.description),
|
||||||
),
|
),
|
||||||
const PopupMenuItem(
|
PopupMenuItem(
|
||||||
value: 'Run test suite including selected node and ancestors',
|
value: TestOption
|
||||||
child: Text(
|
.runTestSuiteIncludingSelectedNodeAndAncestors
|
||||||
'Run test suite including selected node and ancestors'),
|
.description,
|
||||||
|
child: Text(TestOption
|
||||||
|
.runTestSuiteIncludingSelectedNodeAndAncestors
|
||||||
|
.description),
|
||||||
),
|
),
|
||||||
const PopupMenuItem(
|
PopupMenuItem(
|
||||||
value: 'Run all tests in category',
|
value: TestOption.runAllTestsInCategory.description,
|
||||||
child: Text('Run all tests in category'),
|
child: Text(TestOption.runAllTestsInCategory.description),
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
@@ -63,7 +67,7 @@ class _TestSuiteButtonState extends State<TestSuiteButton> {
|
|||||||
children: [
|
children: [
|
||||||
Flexible(
|
Flexible(
|
||||||
child: Text(
|
child: Text(
|
||||||
widget.selectedOption,
|
widget.selectedOptionString,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
fontSize: 12.50,
|
fontSize: 12.50,
|
||||||
@@ -100,7 +104,7 @@ class _TestSuiteButtonState extends State<TestSuiteButton> {
|
|||||||
onPressed: widget.isDisabled
|
onPressed: widget.isDisabled
|
||||||
? null
|
? null
|
||||||
: () {
|
: () {
|
||||||
widget.onPlayPressed(widget.selectedOption);
|
widget.onPlayPressed(widget.selectedOptionString);
|
||||||
},
|
},
|
||||||
child: const Icon(
|
child: const Icon(
|
||||||
Icons.play_arrow,
|
Icons.play_arrow,
|
||||||
|
|||||||
Reference in New Issue
Block a user