|
1 | 1 | from PyQt6.QtGui import QAction, QKeySequence |
2 | | -from PyQt6.QtWidgets import QMenuBar |
| 2 | +from PyQt6.QtWidgets import QMenuBar, QMessageBox |
| 3 | +from core.commands import COMMANDS |
| 4 | +from models.test_scenario import TestScenarioModel |
3 | 5 | from typing import TYPE_CHECKING |
4 | 6 |
|
5 | 7 | from ui.tab import TabWidget |
@@ -36,7 +38,7 @@ def create_menu_bar(self) -> None: |
36 | 38 |
|
37 | 39 | generate_action = QAction("Generate Test Cases", self.main) |
38 | 40 | generate_action.triggered.connect(self.generate_test_cases_action) |
39 | | - generate_action.setShortcut("") |
| 41 | + generate_action.setShortcut("Ctrl+G") |
40 | 42 | generate_action.setToolTip("Generate Test Cases") |
41 | 43 | menubar.addAction(generate_action) |
42 | 44 |
|
@@ -86,15 +88,54 @@ def _create_edit_menu(self, menubar: QMenuBar) -> None: |
86 | 88 |
|
87 | 89 | def generate_test_cases_action(self) -> None: |
88 | 90 | current_tab = self.main.get_current_tab() |
89 | | - if current_tab and hasattr(current_tab, 'controller'): |
90 | | - current_table = self.main.get_current_table() |
91 | | - if current_table: |
92 | | - num_generated = current_tab.controller.generate_test_cases(current_table.model) |
| 91 | + if not current_tab and hasattr(current_tab, 'controller'): |
| 92 | + return |
| 93 | + current_table = self.main.get_current_table() |
| 94 | + if not current_table: |
| 95 | + return |
| 96 | + |
| 97 | + model = current_table.model |
| 98 | + |
| 99 | + for row in range(model.rowCount()): |
| 100 | + command = model.data(model.index(row, TestScenarioModel.COMMAND_COL), 0) |
| 101 | + if command in COMMANDS: |
| 102 | + steps_data = model.data(model.index(row, TestScenarioModel.STEPS_COL), 0) |
| 103 | + expected_data = model.data(model.index(row, TestScenarioModel.EXPECTED_COL), 0) |
| 104 | + if steps_data or expected_data: |
| 105 | + overwrite_needed = True |
| 106 | + break |
| 107 | + |
| 108 | + should_proceed = True |
| 109 | + should_overwrite = False |
| 110 | + if overwrite_needed: |
| 111 | + msg_box = QMessageBox(self.main) |
| 112 | + msg_box.setWindowTitle("Generate Test Cases") |
| 113 | + msg_box.setText("Some test cases already have data.") |
| 114 | + msg_box.setInformativeText("How would you like to proceed?") |
| 115 | + |
| 116 | + reset_button = msg_box.addButton("Reset All", QMessageBox.ButtonRole.DestructiveRole) |
| 117 | + fill_empty_button = msg_box.addButton("Fill Empty", QMessageBox.ButtonRole.AcceptRole) |
| 118 | + cancel_button = msg_box.addButton("Cancel", QMessageBox.ButtonRole.RejectRole) |
| 119 | + |
| 120 | + msg_box.setDefaultButton(fill_empty_button) |
| 121 | + msg_box.exec() |
| 122 | + |
| 123 | + clicked_button = msg_box.clickedButton() |
| 124 | + if clicked_button == reset_button: |
| 125 | + should_overwrite = True |
| 126 | + elif clicked_button == fill_empty_button: |
| 127 | + should_overwrite = False |
| 128 | + else: |
| 129 | + should_proceed = False |
| 130 | + self.main.show_status_message("Operation cancelled.", "info", 3000) |
| 131 | + |
| 132 | + if should_proceed: |
| 133 | + num_generated = current_tab.controller.generate_test_cases(model, overwrite=should_overwrite) |
93 | 134 | if num_generated > 0: |
94 | | - message = f"Generated {num_generated} test case(s)." |
| 135 | + message = f"Successfully generated {num_generated} test case(s)." |
95 | 136 | self.main.show_status_message(message, "success", 5000) |
96 | 137 | else: |
97 | | - message = f"No empty fields found to generate." |
| 138 | + message = "No test cases were generated." |
98 | 139 | self.main.show_status_message(message, "info", 5000) |
99 | 140 |
|
100 | 141 | def auto_adjust_cells(self) -> None: |
|
0 commit comments