Skip to content

OK action is enabled if all members are deselected #168 #238

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

Conversation

Vassiliy-Kudryashov
Copy link
Member

Description

Now OK button is disabled if no members is selected (ticked), better validation and hints were added for:

  1. Not configured test root directory
  2. Not valid test root directory (for example a directory out of project scope)
  3. Empty members (methods) selection

Fixes #168

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Manual Scenario

  1. Call "Generate action" on some class with methods.
  2. Delselect all methods (Ctrl+A, then Space)
  3. Observe disabled OK button.

Checklist (remove irrelevant options):

  • The change followed the style guidelines of the UTBot project
  • Self-review of the code is passed
  • The change contains enough commentaries, particularly in hard-to-understand areas
  • No new warnings

@Vassiliy-Kudryashov Vassiliy-Kudryashov linked an issue Jun 17, 2022 that may be closed by this pull request
@Vassiliy-Kudryashov Vassiliy-Kudryashov force-pushed the Vassiliy-Kudryashov/168-ok-action-is-enabled-if-all-members-are-deselected branch 2 times, most recently from 9ae9a68 to 4166ee4 Compare June 22, 2022 05:41
import com.intellij.openapi.roots.ExternalLibraryDescriptor
import com.intellij.openapi.roots.JavaProjectModelModificationService
import com.intellij.openapi.roots.ModuleRootManager
import com.intellij.openapi.roots.*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not use imports with * by some reasons. Correct this setting in your IntelliJ Idea and in the already commited files after that, please.

@@ -704,7 +715,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
testSourceFolderField.childComponent.addActionListener { event ->
val item = (event.source as JComboBox<*>).selectedItem as String

pathToFile(item)?.let { model.testSourceRoot = it }
pathToFile(item)?.let { model.testSourceRoot = it } ?: run { model.testSourceRoot = null }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that you have just mentioned smth like

model.testSourceRoot = pathToFile(item)

}
return true
if (cbSpecifyTestPackage.isSelected) {
createSelectedPackage(sourceRootAndEntry.first)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such code is not very easy to understand... What is "first"? How to understand that it is actually the testSourceRoot. I would suggest to use something like named tuples or a structure.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

val (a, b) = getAOrb()

WriteCommandAction.runWriteCommandAction(model.project) { modifiableModel.commit() }
private fun getRootDirectoryAndContentEntry() : Pair<VirtualFile, ContentEntry>? {
val testSourceRoot = model.testSourceRoot ?: return null
if (!testSourceRoot.isDirectory) return null
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we incapsulate this logic just in one place, for example, in doValidate method?

if (testSourceRoot == null || !testSourceRoot.isDirectory) {
return ValidationInfo("Test source root is not configured", testSourceFolderField.childComponent)
}
if (getRootDirectoryAndContentEntry() == null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually here you check just it's "second" as "first" is checked in the previous condition.

override fun doValidate(): ValidationInfo? {
val testSourceRoot = model.testSourceRoot
if (testSourceRoot == null || !testSourceRoot.isDirectory) {
return ValidationInfo("Test source root is not configured", testSourceFolderField.childComponent)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we have another validator for it.

@Vassiliy-Kudryashov Vassiliy-Kudryashov force-pushed the Vassiliy-Kudryashov/168-ok-action-is-enabled-if-all-members-are-deselected branch from 28a8cf4 to 6b9eb8c Compare June 22, 2022 10:41
@Vassiliy-Kudryashov Vassiliy-Kudryashov enabled auto-merge (squash) June 22, 2022 17:38
@Vassiliy-Kudryashov Vassiliy-Kudryashov merged commit 93bee98 into main Jun 22, 2022
@Vassiliy-Kudryashov Vassiliy-Kudryashov deleted the Vassiliy-Kudryashov/168-ok-action-is-enabled-if-all-members-are-deselected branch June 22, 2022 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OK action is enabled if all members are deselected
2 participants