diff --git a/.gitignore b/.gitignore index aed022b20..55c35336f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.intellijPlatform .gradle/ .idea/ .qodana/ diff --git a/src/main/kotlin/org/jetbrains/research/testspark/display/generatedTests/GenerateTestsTabHelper.kt b/src/main/kotlin/org/jetbrains/research/testspark/display/generatedTests/GenerateTestsTabHelper.kt index 859e16c1a..9c7c84abe 100644 --- a/src/main/kotlin/org/jetbrains/research/testspark/display/generatedTests/GenerateTestsTabHelper.kt +++ b/src/main/kotlin/org/jetbrains/research/testspark/display/generatedTests/GenerateTestsTabHelper.kt @@ -2,7 +2,7 @@ package org.jetbrains.research.testspark.display.generatedTests object GenerateTestsTabHelper { /** - * A helper method to remove a test case from the cache and from the UI. + * A helper method to "remove" a test case from the cache and from the UI. * * @param testCaseName the name of the test */ @@ -12,6 +12,9 @@ object GenerateTestsTabHelper { generatedTestsTabData.testsSelected-- } + // Add the test panel to the removed test case panel + generatedTestsTabData.removedtestCaseNameToPanel[testCaseName] = generatedTestsTabData.testCaseNameToPanel[testCaseName]!! + // Remove the test panel from the UI generatedTestsTabData.allTestCasePanel.remove(generatedTestsTabData.testCaseNameToPanel[testCaseName]) diff --git a/src/main/kotlin/org/jetbrains/research/testspark/display/generatedTests/GeneratedTestsTabData.kt b/src/main/kotlin/org/jetbrains/research/testspark/display/generatedTests/GeneratedTestsTabData.kt index 97da647b9..c3e42779d 100644 --- a/src/main/kotlin/org/jetbrains/research/testspark/display/generatedTests/GeneratedTestsTabData.kt +++ b/src/main/kotlin/org/jetbrains/research/testspark/display/generatedTests/GeneratedTestsTabData.kt @@ -12,6 +12,7 @@ import javax.swing.JPanel class GeneratedTestsTabData { val testCaseNameToPanel: HashMap = HashMap() + val removedtestCaseNameToPanel: HashMap = HashMap() val testCaseNameToSelectedCheckbox: HashMap = HashMap() val testCaseNameToEditorTextField: HashMap = HashMap() var testsSelected: Int = 0 diff --git a/src/main/kotlin/org/jetbrains/research/testspark/display/generatedTests/TestCasePanelBuilder.kt b/src/main/kotlin/org/jetbrains/research/testspark/display/generatedTests/TestCasePanelBuilder.kt index 09ad48f01..e5404adad 100644 --- a/src/main/kotlin/org/jetbrains/research/testspark/display/generatedTests/TestCasePanelBuilder.kt +++ b/src/main/kotlin/org/jetbrains/research/testspark/display/generatedTests/TestCasePanelBuilder.kt @@ -303,7 +303,6 @@ class TestCasePanelBuilder( resetButton.addActionListener { reset() } resetToLastRunButton.addActionListener { resetToLastRun() } removeButton.addActionListener { remove() } - sendButton.addActionListener { sendRequest() } /** @@ -627,6 +626,7 @@ class TestCasePanelBuilder( * 3. Updating the UI. */ private fun remove() { + // Remove the test case from the cache GenerateTestsTabHelper.removeTestCase(testCase.testName, generatedTestsTabData) @@ -635,9 +635,75 @@ class TestCasePanelBuilder( ReportUpdater.removeTestCase(report, testCase, coverageVisualisationTabBuilder, generatedTestsTabData) + // Create a new test case panel with the recover button + val recoverTestPanel = createRecoverTestPanel() + generatedTestsTabData.allTestCasePanel.add(recoverTestPanel) + GenerateTestsTabHelper.update(generatedTestsTabData) } + /** + * Creates a recovery test panel for the specified test case. + * + * This method is responsible for: + * 1. Creating a new panel with a message indicating that the test case has been deleted. + * 2. Adding a "Recover" button to the panel. + * 3. Adding an action listener to the "Recover" button that recovers the test case, updates the panel and checkbox + * states, and updates the report with the recovered test case. + */ + private fun createRecoverTestPanel(): JPanel { + + val recoverTestPanel = JPanel() + recoverTestPanel.layout = BoxLayout(recoverTestPanel, BoxLayout.Y_AXIS) + + val messagePanel = JPanel() + messagePanel.layout = BoxLayout(messagePanel, BoxLayout.X_AXIS) + + // Text message label on the left + val deletionMessage = JLabel("Test ${testCase.testName} deleted.") + messagePanel.add(deletionMessage) + messagePanel.add(Box.createHorizontalGlue()) + + // Recover button on the right + val recoveryButton = JButton("Recover") + messagePanel.add(recoveryButton) + runTestButton.isEnabled = true + isRemoved = false + + recoveryButton.addActionListener { + val oldTestCasePanel = generatedTestsTabData.removedtestCaseNameToPanel.remove(testCase.testName) + if (oldTestCasePanel != null) { + // Remove the recoverTestPanel from the allTestCasePanel + generatedTestsTabData.allTestCasePanel.remove(recoverTestPanel) + + // Recover the test case that was deleted + generatedTestsTabData.allTestCasePanel.add(oldTestCasePanel) + + // Update panel and checkbox states + generatedTestsTabData.testCaseNameToPanel[testCase.testName] = oldTestCasePanel + val associatedCheckbox = oldTestCasePanel.components[0] as JCheckBox + generatedTestsTabData.testCaseNameToSelectedCheckbox[testCase.testName] = associatedCheckbox + + // Update the count of selected tests if the test is recovered successfully + if (!associatedCheckbox.isSelected) { + associatedCheckbox.isSelected = true + generatedTestsTabData.testsSelected++ + } + + // Update the report with the recovered test case + ReportUpdater.updateTestCase(report, testCase, coverageVisualisationTabBuilder, generatedTestsTabData) + + generatedTestsTabData.testsSelected = generatedTestsTabData.testCaseNameToPanel.size + generatedTestsTabData.topButtonsPanelBuilder.update(generatedTestsTabData) + } + } + + // Add the messagePanel to recoveryTestPanel + recoverTestPanel.add(messagePanel) + + return recoverTestPanel + } + /** * Determines if the "Run" button is enabled. *