Skip to content

Commit

Permalink
add borders
Browse files Browse the repository at this point in the history
  • Loading branch information
arksap2002 committed Aug 15, 2023
1 parent 6b519b4 commit dbfc80e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,16 @@ class TestCaseDisplayService(private val project: Project) {
// Enable reset button when editor is changed
addListenerToTestDocument(document, resetButton, textFieldEditor, checkbox)

// Set border
textFieldEditor.border = getBorder(testCase.testName)

// Add "Remove" and "Reset" buttons to the test case panel
resetButton.addActionListener {
WriteCommandAction.runWriteCommandAction(project) {
document.setText(testCodeFormatted)
resetButton.isEnabled = false
textFieldEditor.border = JBUI.Borders.empty()
textFieldEditor.editor!!.markupModel.removeAllHighlighters()
textFieldEditor.border = getBorder(testCase.testName)
}
}
val bottomPanel = JPanel()
Expand Down Expand Up @@ -798,18 +801,6 @@ class TestCaseDisplayService(private val project: Project) {
override fun documentChanged(event: DocumentEvent) {
resetButton.isEnabled = true

// add border highlight
val settingsProjectState = project.service<SettingsProjectService>().state
val borderColor = JBColor(
TestSparkToolTipsBundle.defaultValue("colorName"),
Color(
settingsProjectState.colorRed,
settingsProjectState.colorGreen,
settingsProjectState.colorBlue,
),
)
textFieldEditor.border = BorderFactory.createLineBorder(borderColor)

// add line highlighting
if (event.newRange.startOffset + 1 >= document.textLength ||
event.newRange.endOffset >= document.textLength
Expand Down Expand Up @@ -872,4 +863,14 @@ class TestCaseDisplayService(private val project: Project) {
}.filter { it.modified != it.original },
)
}

/**
* Returns the border for a given test case.
*
* @param testCaseName the name of the test case
* @return the border for the test case
*/
private fun getBorder(testCaseName: String): Border =
if (project.service<TestsExecutionResultService>().isTestCasePassing(testCaseName)) BorderFactory.createLineBorder(JBColor.GREEN)
else BorderFactory.createLineBorder(JBColor.RED)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.jetbrains.research.testspark.services

import com.intellij.openapi.project.Project

class TestsExecutionResultService(private val project: Project) {
private val passingTests: MutableSet<String> = mutableSetOf()

fun addPassingTest(testName: String) { passingTests.add(testName) }

fun isTestCasePassing(testName: String): Boolean = passingTests.contains(testName)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.jetbrains.research.testspark.TestSparkBundle
import org.jetbrains.research.testspark.data.Report
import org.jetbrains.research.testspark.data.TestCase
import org.jetbrains.research.testspark.editor.Workspace
import org.jetbrains.research.testspark.services.TestsExecutionResultService
import org.jetbrains.research.testspark.tools.llm.error.LLMErrorManager
import org.jetbrains.research.testspark.tools.llm.test.TestCaseGeneratedByLLM
import java.io.File
Expand Down Expand Up @@ -171,6 +172,9 @@ class TestCoverageCollector(
),
)

// add passing test
if (testExecutionError.isEmpty()) project.service<TestsExecutionResultService>().addPassingTest(testCase.name)

// collect lines covered during the exception
linesCoveredDuringTheException[testCase.name] = collectLinesCoveredDuringException(testExecutionError)

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
serviceImplementation="org.jetbrains.research.testspark.services.RunnerService"/>
<projectService
serviceImplementation="org.jetbrains.research.testspark.services.ErrorService"/>
<projectService
serviceImplementation="org.jetbrains.research.testspark.services.TestsExecutionResultService"/>

<toolWindow id="TestSpark" secondary="true" anchor="right"
factoryClass="org.jetbrains.research.testspark.toolwindow.TestSparkToolWindowFactory"/>
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/defaults/TestSpark.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ junitCheckTimeout=60
populationLimit=INDIVIDUALS
population=50
javaPath=java
colorRed=100
colorGreen=150
colorBlue=20
colorRed=255
colorGreen=170
colorBlue=51
showCoverage=true
telemetryEnabled=false
sandbox=true
Expand Down

0 comments on commit dbfc80e

Please sign in to comment.