Skip to content

Commit

Permalink
fix: show hand icon, refactor info node text construction (#609)
Browse files Browse the repository at this point in the history
* fix: show hand icon, refactor info node text construction

* fix: tests

* fix: tests
  • Loading branch information
bastiandoetsch authored Sep 11, 2024
1 parent fc50f9b commit e5391ab
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,12 @@ class SnykToolWindowSnykScanListenerLS(
val issuesCount = issues.size
val ignoredIssuesCount = issues.count { it.isIgnored() }
if (issuesCount != 0) {
text = if (issuesCount == 1) {
"$issuesCount vulnerability found by Snyk"
val plural = if (issuesCount == 1) {
"y"
} else {
"$issuesCount vulnerabilities found by Snyk"
"ies"
}
text = "$issuesCount vulnerabilit$plural found by Snyk"
if (pluginSettings().isGlobalIgnoresFeatureEnabled) {
text += ", $ignoredIssuesCount ignored"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class SnykControllerImplTest : LightPlatformTestCase() {
val controller = SnykControllerImpl(project)
controller.scan()

PlatformTestUtil.dispatchAllInvocationEventsInIdeEventQueue()
PlatformTestUtil.dispatchAllEventsInIdeEventQueue()

verify { languageServerWrapper.sendScanCommand(project) }
verify (timeout = 5000){ languageServerWrapper.sendScanCommand(project) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package io.snyk.plugin.ui
import com.intellij.openapi.components.service
import com.intellij.openapi.ui.ComboBox
import com.intellij.openapi.util.io.toNioPathOrNull
import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.openapi.vfs.VirtualFileSystem
import com.intellij.testFramework.LightPlatform4TestCase
import com.intellij.testFramework.PlatformTestUtil
import io.mockk.CapturingSlot
import io.mockk.mockk
import io.mockk.unmockkAll
import io.mockk.verify
import io.snyk.plugin.toVirtualFile
import okio.Path.Companion.toPath
import org.eclipse.lsp4j.DidChangeConfigurationParams
import org.eclipse.lsp4j.services.LanguageServer
Expand All @@ -30,10 +33,10 @@ class BranchChooserComboBoxDialogTest : LightPlatform4TestCase() {
unmockkAll()
folderConfig = FolderConfig(project.basePath.toString(), "testBranch")
service<FolderConfigSettings>().addFolderConfig(folderConfig)
project.basePath?.let { service<WorkspaceTrustService>().addTrustedPath(it.toNioPathOrNull()!!) }
val languageServerWrapper = LanguageServerWrapper.getInstance()
languageServerWrapper.isInitialized = true
languageServerWrapper.languageServer = lsMock
project.basePath?.let { service<WorkspaceTrustService>().addTrustedPath(it.toPath().parent!!.toNioPath()) }
cut = BranchChooserComboBoxDialog(project)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ class SnykToolWindowSnykScanListenerLSTest : BasePlatformTestCase() {
TestCase.assertEquals(rootTreeNode.children().toList()[1].toString(), " Code Security")
TestCase.assertEquals(rootTreeNode.children().toList()[2].toString(), " Code Quality")
TestCase.assertEquals(
"✋ 1 vulnerability found by Snyk, 0 ignored",
rootTreeNode.children().toList()[4].toString(),
"1 vulnerability found by Snyk, 0 ignored",
)
TestCase.assertEquals(
rootTreeNode.children().toList()[5].toString(),
Expand Down Expand Up @@ -188,12 +188,12 @@ class SnykToolWindowSnykScanListenerLSTest : BasePlatformTestCase() {
TestCase.assertEquals(rootTreeNode.children().toList()[2].toString(), " Code Quality")
TestCase.assertTrue(rootTreeNode.children().toList()[3].toString().contains("Click to choose base branch for"))
TestCase.assertEquals(
"✋ 1 vulnerability found by Snyk, 0 ignored",
rootTreeNode.children().toList()[4].toString(),
"1 vulnerability found by Snyk, 0 ignored",
)
TestCase.assertEquals(
rootTreeNode.children().toList()[5].toString(),
"⚡ 1 vulnerabilities can be fixed automatically",
rootTreeNode.children().toList()[5].toString(),
)
}

Expand Down
12 changes: 9 additions & 3 deletions src/test/kotlin/snyk/container/ContainerBulkFileListenerTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package snyk.container

import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.WriteAction
import com.intellij.openapi.application.invokeAndWaitIfNeeded
import com.intellij.openapi.application.invokeLater
import com.intellij.openapi.components.service
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.vfs.VirtualFile
Expand Down Expand Up @@ -28,6 +31,7 @@ import java.io.File
import java.nio.file.Files
import java.nio.file.LinkOption
import java.nio.file.Paths
import java.time.Duration
import java.util.concurrent.TimeUnit
import kotlin.io.path.notExists

Expand Down Expand Up @@ -70,12 +74,14 @@ class ContainerBulkFileListenerTest : BasePlatformTestCase() {
setUpContainerTest()
val path = createNewFileInProjectRoot().toPath()
Files.write(path, "\n".toByteArray(Charsets.UTF_8))
VirtualFileManager.getInstance().syncRefresh()
var virtualFile: VirtualFile? = null
await().atMost(2, TimeUnit.SECONDS).until {
invokeLater {
VirtualFileManager.getInstance().syncRefresh()
virtualFile = VirtualFileManager.getInstance().findFileByNioPath(path)
virtualFile?.isValid ?: false
}
PlatformTestUtil.dispatchAllEventsInIdeEventQueue()
await().timeout(5, TimeUnit.SECONDS).until { virtualFile?.isValid ?: false }


ApplicationManager.getApplication().runWriteAction {
val file = PsiManager.getInstance(project).findFile(virtualFile!!)
Expand Down

0 comments on commit e5391ab

Please sign in to comment.