1
1
package org.utbot.intellij.plugin.language.python
2
2
3
3
import com.intellij.openapi.components.service
4
- import com.intellij.openapi.project.Project
5
- import com.intellij.openapi.ui.*
6
- import com.intellij.ui.ContextHelpLabel
4
+ import com.intellij.openapi.ui.ComboBox
5
+ import com.intellij.openapi.ui.DialogPanel
6
+ import com.intellij.openapi.ui.DialogWrapper
7
+ import com.intellij.openapi.ui.ValidationInfo
7
8
import com.intellij.ui.JBIntSpinner
8
- import com.intellij.ui.components.Panel
9
- import com.intellij.ui.layout.CellBuilder
10
- import com.intellij.ui.layout.Row
11
- import com.intellij.ui.layout .panel
9
+ import com.intellij.ui.components.JBLabel
10
+ import com.intellij.ui.components.JBScrollPane
11
+ import com.intellij.ui.dsl.builder.Align
12
+ import com.intellij.ui.dsl.builder .panel
12
13
import com.intellij.util.ui.JBUI
13
- import com.jetbrains.python.psi.*
14
- import org.utbot.framework.UtSettings
14
+ import com.intellij.util.ui.components.BorderLayoutPanel
15
+ import com.jetbrains.python.psi.PyClass
16
+ import com.jetbrains.python.psi.PyFunction
15
17
import org.utbot.framework.codegen.domain.ProjectType
18
+ import org.utbot.framework.codegen.domain.TestFramework
19
+ import org.utbot.intellij.plugin.language.python.settings.loadStateFromModel
16
20
import org.utbot.intellij.plugin.language.python.table.UtPyClassItem
17
21
import org.utbot.intellij.plugin.language.python.table.UtPyFunctionItem
18
22
import org.utbot.intellij.plugin.language.python.table.UtPyMemberSelectionTable
19
23
import org.utbot.intellij.plugin.language.python.table.UtPyTableItem
20
24
import org.utbot.intellij.plugin.settings.Settings
21
- import java.awt.BorderLayout
22
- import java.util.concurrent.TimeUnit
23
25
import org.utbot.intellij.plugin.ui.components.TestSourceDirectoryChooser
24
26
import org.utbot.intellij.plugin.ui.utils.createTestFrameworksRenderer
25
27
import java.awt.event.ActionEvent
26
- import javax.swing.*
27
-
28
+ import java.util.concurrent.TimeUnit
29
+ import javax.swing.AbstractAction
30
+ import javax.swing.Action
31
+ import javax.swing.DefaultComboBoxModel
32
+ import javax.swing.JComponent
28
33
29
34
private const val WILL_BE_INSTALLED_LABEL = " (will be installed)"
30
- private const val MINIMUM_TIMEOUT_VALUE_IN_SECONDS = 1
35
+ private const val MINIMUM_TIMEOUT_VALUE_IN_SECONDS = 5
31
36
private const val STEP_TIMEOUT_VALUE_IN_SECONDS = 5
32
37
private const val ACTION_GENERATE = " Generate Tests"
33
38
@@ -37,7 +42,7 @@ class PythonDialogWindow(val model: PythonTestsModel) : DialogWrapper(model.proj
37
42
private val testSourceFolderField = TestSourceDirectoryChooser (model)
38
43
private val timeoutSpinnerForTotalTimeout =
39
44
JBIntSpinner (
40
- TimeUnit .MILLISECONDS .toSeconds(UtSettings .utBotGenerationTimeoutInMillis ).toInt(),
45
+ TimeUnit .MILLISECONDS .toSeconds(model.timeout ).toInt(),
41
46
MINIMUM_TIMEOUT_VALUE_IN_SECONDS ,
42
47
Int .MAX_VALUE ,
43
48
STEP_TIMEOUT_VALUE_IN_SECONDS
@@ -46,6 +51,7 @@ class PythonDialogWindow(val model: PythonTestsModel) : DialogWrapper(model.proj
46
51
ComboBox (DefaultComboBoxModel (model.cgLanguageAssistant.getLanguageTestFrameworkManager().testFrameworks.toTypedArray()))
47
52
48
53
private lateinit var panel: DialogPanel
54
+ private lateinit var currentFrameworkItem: TestFramework
49
55
50
56
init {
51
57
title = " Generate Tests with UnitTestBot"
@@ -59,36 +65,42 @@ class PythonDialogWindow(val model: PythonTestsModel) : DialogWrapper(model.proj
59
65
}
60
66
61
67
override fun createCenterPanel (): JComponent {
62
-
63
68
panel = panel {
64
69
row(" Test sources root:" ) {
65
- component (testSourceFolderField)
70
+ cell (testSourceFolderField).align( Align . FILL )
66
71
}
67
- row(" Test framework:" ) {
68
- makePanelWithHelpTooltip(
69
- testFrameworks,
70
- null
71
- )
72
+ row(" Testing framework:" ) {
73
+ cell(testFrameworks)
72
74
}
73
- row(" Timeout for all selected functions :" ) {
74
- cell {
75
- component (timeoutSpinnerForTotalTimeout)
76
- label( " seconds" )
77
- component( ContextHelpLabel .create( " Set the timeout for all test generation processes. " ) )
78
- }
75
+ row(" Test generation timeout :" ) {
76
+ cell( BorderLayoutPanel (). apply {
77
+ addToLeft (timeoutSpinnerForTotalTimeout)
78
+ addToRight( JBLabel ( " seconds per module " ) )
79
+ } )
80
+ contextHelp( " Set the timeout for all test generation processes per module to complete. " )
79
81
}
80
- row(" Generate test methods for:" ) {}
82
+ row(" Generate tests for:" ) {}
81
83
row {
82
- scrollPane( pyElementsTable)
84
+ cell( JBScrollPane ( pyElementsTable)).align( Align . FILL )
83
85
}
84
86
}
85
87
88
+ initDefaultValues()
86
89
updatePyElementsTable()
87
- updateTestFrameworksList()
88
90
return panel
89
91
}
90
92
93
+ private fun initDefaultValues () {
94
+ val settings = model.project.service<Settings >()
95
+
96
+ val installedTestFramework = TestFramework .allItems.singleOrNull { it.isInstalled }
97
+ currentFrameworkItem = installedTestFramework ? : settings.testFramework
98
+
99
+ updateTestFrameworksList()
100
+ }
101
+
91
102
private fun updateTestFrameworksList () {
103
+ testFrameworks.item = currentFrameworkItem
92
104
testFrameworks.renderer = createTestFrameworksRenderer(WILL_BE_INSTALLED_LABEL )
93
105
}
94
106
@@ -126,15 +138,6 @@ class PythonDialogWindow(val model: PythonTestsModel) : DialogWrapper(model.proj
126
138
127
139
private fun checkMembers (members : Collection <UtPyTableItem >) = members.forEach { it.isChecked = true }
128
140
129
- private fun Row.makePanelWithHelpTooltip (
130
- mainComponent : JComponent ,
131
- contextHelpLabel : ContextHelpLabel ?
132
- ): CellBuilder <JPanel > =
133
- component(Panel ().apply {
134
- add(mainComponent, BorderLayout .LINE_START )
135
- contextHelpLabel?.let { add(it, BorderLayout .LINE_END ) }
136
- })
137
-
138
141
class OKOptionAction (private val okAction : Action ) : AbstractAction(ACTION_GENERATE ) {
139
142
init {
140
143
putValue(DEFAULT_ACTION , java.lang.Boolean .TRUE )
@@ -162,6 +165,8 @@ class PythonDialogWindow(val model: PythonTestsModel) : DialogWrapper(model.proj
162
165
model.runtimeExceptionTestsBehaviour = runtimeExceptionTestsBehaviour
163
166
}
164
167
168
+ loadStateFromModel(settings, model)
169
+
165
170
super .doOKAction()
166
171
}
167
172
0 commit comments