Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recover panel for deleted test #404

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.intellijPlatform
.gradle/
.idea/
.qodana/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import javax.swing.JPanel

class GeneratedTestsTabData {
val testCaseNameToPanel: HashMap<String, JPanel> = HashMap()
val removedtestCaseNameToPanel: HashMap<String, JPanel> = HashMap()
val testCaseNameToSelectedCheckbox: HashMap<String, JCheckBox> = HashMap()
val testCaseNameToEditorTextField: HashMap<String, EditorTextField> = HashMap()
var testsSelected: Int = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ class TestCasePanelBuilder(
resetButton.addActionListener { reset() }
resetToLastRunButton.addActionListener { resetToLastRun() }
removeButton.addActionListener { remove() }

sendButton.addActionListener { sendRequest() }

/**
Expand Down Expand Up @@ -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)

Expand All @@ -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.
*
Expand Down