aboutsummaryrefslogtreecommitdiff
path: root/frontend
diff options
context:
space:
mode:
authorGravatar hunteraraujo <hunter_araujo@msn.com> 2023-10-06 16:13:33 -0700
committerGravatar GitHub <noreply@github.com> 2023-10-06 16:13:33 -0700
commitb2d53d8d18c754a5b877ffeb9f42d3387c3324fd (patch)
treeb49a05008eae497233b545a393c0752f109a72bc /frontend
parentImplement Artifact Class for Enhanced Data Handling (#5585) (diff)
downloadAuto-GPT-b2d53d8d18c754a5b877ffeb9f42d3387c3324fd.tar.gz
Auto-GPT-b2d53d8d18c754a5b877ffeb9f42d3387c3324fd.tar.bz2
Auto-GPT-b2d53d8d18c754a5b877ffeb9f42d3387c3324fd.zip
Introduce TestOption Enum for Enhanced Test Selection Clarity (#5586)
Diffstat (limited to 'frontend')
-rw-r--r--frontend/lib/models/test_option.dart65
-rw-r--r--frontend/lib/viewmodels/skill_tree_viewmodel.dart14
-rw-r--r--frontend/lib/views/task_queue/task_queue_view.dart5
-rw-r--r--frontend/lib/views/task_queue/test_suite_button.dart36
4 files changed, 95 insertions, 25 deletions
diff --git a/frontend/lib/models/test_option.dart b/frontend/lib/models/test_option.dart
new file mode 100644
index 000000000..368918c00
--- /dev/null
+++ b/frontend/lib/models/test_option.dart
@@ -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
+ }
+ }
+}
diff --git a/frontend/lib/viewmodels/skill_tree_viewmodel.dart b/frontend/lib/viewmodels/skill_tree_viewmodel.dart
index 833d8c11a..2a17f3adf 100644
--- a/frontend/lib/viewmodels/skill_tree_viewmodel.dart
+++ b/frontend/lib/viewmodels/skill_tree_viewmodel.dart
@@ -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/step.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/services/benchmark_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
List<SkillTreeNode>? _selectedNodeHierarchy;
- String _selectedOption = 'Run single test';
- String get selectedOption => _selectedOption;
+ TestOption _selectedOption = TestOption.runSingleTest;
+ TestOption get selectedOption => _selectedOption;
List<SkillTreeNode> get skillTreeNodes => _skillTreeNodes;
List<SkillTreeEdge> get skillTreeEdges => _skillTreeEdges;
@@ -110,21 +111,20 @@ class SkillTreeViewModel extends ChangeNotifier {
notifyListeners();
}
- void updateSelectedNodeHierarchyBasedOnOption(String selectedOption) {
+ void updateSelectedNodeHierarchyBasedOnOption(TestOption selectedOption) {
_selectedOption = selectedOption;
switch (selectedOption) {
- // TODO: Turn this into enum
- case 'Run single test':
+ case TestOption.runSingleTest:
_selectedNodeHierarchy = _selectedNode != null ? [_selectedNode!] : [];
break;
- case 'Run test suite including selected node and ancestors':
+ case TestOption.runTestSuiteIncludingSelectedNodeAndAncestors:
if (_selectedNode != null) {
populateSelectedNodeHierarchy(_selectedNode!.id);
}
break;
- case 'Run all tests in category':
+ case TestOption.runAllTestsInCategory:
if (_selectedNode != null) {
_getAllNodesInDepthFirstOrderEnsuringParents();
}
diff --git a/frontend/lib/views/task_queue/task_queue_view.dart b/frontend/lib/views/task_queue/task_queue_view.dart
index 4562b0a5a..256245a92 100644
--- a/frontend/lib/views/task_queue/task_queue_view.dart
+++ b/frontend/lib/views/task_queue/task_queue_view.dart
@@ -1,4 +1,5 @@
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/task_viewmodel.dart';
import 'package:auto_gpt_flutter_client/views/task_queue/leaderboard_submission_button.dart';
@@ -98,11 +99,11 @@ class TaskQueueView extends StatelessWidget {
// TestSuiteButton
TestSuiteButton(
isDisabled: viewModel.isBenchmarkRunning,
- selectedOption: viewModel.selectedOption,
+ selectedOptionString: viewModel.selectedOption.description,
onOptionSelected: (selectedOption) {
print('Option Selected: $selectedOption');
viewModel.updateSelectedNodeHierarchyBasedOnOption(
- selectedOption);
+ TestOptionExtension.fromDescription(selectedOption)!);
},
onPlayPressed: (selectedOption) {
print('Starting benchmark with option: $selectedOption');
diff --git a/frontend/lib/views/task_queue/test_suite_button.dart b/frontend/lib/views/task_queue/test_suite_button.dart
index 1e1f871fb..c1ddca279 100644
--- a/frontend/lib/views/task_queue/test_suite_button.dart
+++ b/frontend/lib/views/task_queue/test_suite_button.dart
@@ -1,17 +1,18 @@
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';
class TestSuiteButton extends StatefulWidget {
final bool isDisabled;
final Function(String) onOptionSelected;
final Function(String) onPlayPressed;
- String selectedOption;
+ String selectedOptionString;
TestSuiteButton({
this.isDisabled = false,
required this.onOptionSelected,
required this.onPlayPressed,
- required this.selectedOption,
+ required this.selectedOptionString,
});
@override
@@ -30,24 +31,27 @@ class _TestSuiteButtonState extends State<TestSuiteButton> {
enabled: !widget.isDisabled,
onSelected: (value) {
setState(() {
- widget.selectedOption = value;
+ widget.selectedOptionString = value;
});
- widget.onOptionSelected(widget.selectedOption);
+ widget.onOptionSelected(widget.selectedOptionString);
},
itemBuilder: (BuildContext context) {
return [
- const PopupMenuItem(
- value: 'Run single test',
- child: Text('Run single test'),
+ PopupMenuItem(
+ value: TestOption.runSingleTest.description,
+ child: Text(TestOption.runSingleTest.description),
),
- const PopupMenuItem(
- value: 'Run test suite including selected node and ancestors',
- child: Text(
- 'Run test suite including selected node and ancestors'),
+ PopupMenuItem(
+ value: TestOption
+ .runTestSuiteIncludingSelectedNodeAndAncestors
+ .description,
+ child: Text(TestOption
+ .runTestSuiteIncludingSelectedNodeAndAncestors
+ .description),
),
- const PopupMenuItem(
- value: 'Run all tests in category',
- child: Text('Run all tests in category'),
+ PopupMenuItem(
+ value: TestOption.runAllTestsInCategory.description,
+ child: Text(TestOption.runAllTestsInCategory.description),
),
];
},
@@ -63,7 +67,7 @@ class _TestSuiteButtonState extends State<TestSuiteButton> {
children: [
Flexible(
child: Text(
- widget.selectedOption,
+ widget.selectedOptionString,
style: const TextStyle(
color: Colors.white,
fontSize: 12.50,
@@ -100,7 +104,7 @@ class _TestSuiteButtonState extends State<TestSuiteButton> {
onPressed: widget.isDisabled
? null
: () {
- widget.onPlayPressed(widget.selectedOption);
+ widget.onPlayPressed(widget.selectedOptionString);
},
child: const Icon(
Icons.play_arrow,