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

Clean coverage after tests applying #349

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ class TestSparkDisplayManager {
clear()
}
}

generatedTestsTabBuilder!!.getApplyButton().addActionListener {
if (generatedTestsTabBuilder!!.applyTests()) clear()
}
}

fun clear() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import java.awt.BorderLayout
import java.awt.Dimension
import javax.swing.Box
import javax.swing.BoxLayout
import javax.swing.JButton
import javax.swing.JCheckBox
import javax.swing.JPanel
import javax.swing.JSeparator
Expand Down Expand Up @@ -47,6 +46,8 @@ class GeneratedTestsTabBuilder(

fun getRemoveAllButton() = generatedTestsTabData.topButtonsPanelBuilder.getRemoveAllButton()

fun getApplyButton() = generatedTestsTabData.applyButton

/**
* Displays the generated tests tab in the tool window.
* This method initializes necessary components based on the selected language and shows the tab.
Expand Down Expand Up @@ -91,20 +92,17 @@ class GeneratedTestsTabBuilder(
* Initializes and fills the main panel with subcomponents.
*/
private fun fillMainPanel() {
val applyButton = JButton(PluginLabelsBundle.get("applyButton"))

mainPanel.layout = BorderLayout()

mainPanel.add(
generatedTestsTabData.topButtonsPanelBuilder.getPanel(project, generatedTestsTabData),
BorderLayout.NORTH,
)
mainPanel.add(generatedTestsTabData.scrollPane, BorderLayout.CENTER)
mainPanel.add(applyButton, BorderLayout.SOUTH)
mainPanel.add(generatedTestsTabData.applyButton, BorderLayout.SOUTH)

applyButton.isOpaque = false
applyButton.isContentAreaFilled = false
applyButton.addActionListener { applyTests() }
generatedTestsTabData.applyButton.isOpaque = false
generatedTestsTabData.applyButton.isContentAreaFilled = false
}

/**
Expand Down Expand Up @@ -188,7 +186,7 @@ class GeneratedTestsTabBuilder(
/**
* Applies the selected test cases by passing them to the display utility for execution.
*/
private fun applyTests() {
fun applyTests(): Boolean {
// Filter the selected test cases
val selectedTestCasePanels =
generatedTestsTabData.testCaseNameToPanel.filter { (it.value.getComponent(0) as JCheckBox).isSelected }
Expand All @@ -203,6 +201,8 @@ class GeneratedTestsTabBuilder(

// Remove the selected test cases from the cache and the tool window UI
if (applyingResult) clear()

return applyingResult
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import com.intellij.ui.EditorTextField
import com.intellij.ui.components.JBScrollPane
import com.intellij.ui.content.Content
import com.intellij.ui.content.ContentManager
import org.jetbrains.research.testspark.bundles.plugin.PluginLabelsBundle
import org.jetbrains.research.testspark.core.data.TestCase
import javax.swing.JButton
import javax.swing.JCheckBox
import javax.swing.JPanel

Expand All @@ -16,6 +18,7 @@ class GeneratedTestsTabData {
val unselectedTestCases: HashMap<Int, TestCase> = HashMap()
val testCasePanelFactories: ArrayList<TestCasePanelBuilder> = arrayListOf()
var allTestCasePanel: JPanel = JPanel()
val applyButton: JButton = JButton(PluginLabelsBundle.get("applyButton"))
var scrollPane: JBScrollPane = JBScrollPane(
allTestCasePanel,
JBScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ class TestCasePanelBuilder(
*/
private fun sendRequest() {
loadingLabel.isVisible = true
enableComponents(false)
enableGlobalComponents(false)
enableLocalComponents(false)

ProgressManager.getInstance()
.run(object : Task.Backgroundable(project, PluginMessagesBundle.get("sendingFeedback")) {
Expand Down Expand Up @@ -456,13 +457,19 @@ class TestCasePanelBuilder(
})
}

private fun finishProcess() {
private fun finishProcess(enableGlobal: Boolean = true) {
uiContext!!.errorMonitor.clear()
loadingLabel.isVisible = false
enableComponents(true)
if (enableGlobal) enableGlobalComponents(true)
enableLocalComponents(true)
}

private fun enableComponents(isEnabled: Boolean) {
private fun enableGlobalComponents(isEnabled: Boolean) {
generatedTestsTabData.topButtonsPanelBuilder.getRemoveAllButton().isEnabled = isEnabled
generatedTestsTabData.applyButton.isEnabled = isEnabled
}

private fun enableLocalComponents(isEnabled: Boolean) {
nextButton.isEnabled = isEnabled
previousButton.isEnabled = isEnabled
runTestButton.isEnabled = isEnabled
Expand Down Expand Up @@ -511,12 +518,13 @@ class TestCasePanelBuilder(
if (!runTestButton.isEnabled) return

loadingLabel.isVisible = true
enableComponents(false)
enableGlobalComponents(false)
enableLocalComponents(false)

ProgressManager.getInstance()
.run(object : Task.Backgroundable(project, PluginMessagesBundle.get("sendingFeedback")) {
override fun run(indicator: ProgressIndicator) {
runTest(IJProgressIndicator(indicator))
runTest(IJProgressIndicator(indicator), true)
}
})
}
Expand All @@ -526,10 +534,11 @@ class TestCasePanelBuilder(
if (!runTestButton.isEnabled) return

loadingLabel.isVisible = true
enableComponents(false)
enableGlobalComponents(false)
enableLocalComponents(false)

tasks.add { indicator ->
runTest(indicator)
runTest(indicator, false)
}
}

Expand All @@ -538,7 +547,7 @@ class TestCasePanelBuilder(
update()
}

private fun runTest(indicator: CustomProgressIndicator) {
private fun runTest(indicator: CustomProgressIndicator, enableGlobal: Boolean) {
indicator.setText("Executing ${testCase.testName}")

val fileName = TestAnalyzerFactory.create(language).getFileNameFromTestCaseCode(testCase.testCode)
Expand Down Expand Up @@ -572,7 +581,7 @@ class TestCasePanelBuilder(
update()
}

finishProcess()
finishProcess(enableGlobal)
indicator.stop()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ class TopButtonsPanelBuilder {
executeTasks(project, tasks, generatedTestsTabData)
}

private fun executeTasks(project: Project, tasks: Queue<(CustomProgressIndicator) -> Unit>, generatedTestsTabData: GeneratedTestsTabData) {
private fun executeTasks(
project: Project,
tasks: Queue<(CustomProgressIndicator) -> Unit>,
generatedTestsTabData: GeneratedTestsTabData,
) {
val nextTask = tasks.poll()

nextTask?.let { task ->
Expand Down Expand Up @@ -141,6 +145,10 @@ class TopButtonsPanelBuilder {
}
})
}
if (nextTask == null) {
generatedTestsTabData.topButtonsPanelBuilder.getRemoveAllButton().isEnabled = true
generatedTestsTabData.applyButton.isEnabled = true
}
}

fun getPanel(project: Project, generatedTestsTabData: GeneratedTestsTabData): JPanel {
Expand Down
Loading