diff --git a/src/test/kotlin/io/snyk/plugin/ui/toolwindow/SnykToolWindowSnykScanListenerLSlTest.kt b/src/test/kotlin/io/snyk/plugin/ui/toolwindow/SnykToolWindowSnykScanListenerLSlTest.kt new file mode 100644 index 000000000..823db936b --- /dev/null +++ b/src/test/kotlin/io/snyk/plugin/ui/toolwindow/SnykToolWindowSnykScanListenerLSlTest.kt @@ -0,0 +1,93 @@ +package io.snyk.plugin.ui.toolwindow + +import com.intellij.openapi.application.WriteAction +import com.intellij.psi.PsiFile +import com.intellij.testFramework.fixtures.BasePlatformTestCase +import io.mockk.every +import io.mockk.mockk +import io.mockk.unmockkAll +import io.snyk.plugin.Severity +import io.snyk.plugin.SnykFile +import io.snyk.plugin.resetSettings +import io.snyk.plugin.ui.toolwindow.nodes.root.RootOssTreeNode +import io.snyk.plugin.ui.toolwindow.nodes.root.RootQualityIssuesTreeNode +import io.snyk.plugin.ui.toolwindow.nodes.root.RootSecurityIssuesTreeNode +import org.eclipse.lsp4j.Position +import org.eclipse.lsp4j.Range +import snyk.common.ProductType +import snyk.common.lsp.CommitChangeLine +import snyk.common.lsp.DataFlow +import snyk.common.lsp.ExampleCommitFix +import snyk.common.lsp.ScanIssue +import javax.swing.JTree +import javax.swing.tree.DefaultMutableTreeNode + +class SnykToolWindowSnykScanListenerLSlTest : BasePlatformTestCase() { + private lateinit var cut: SnykToolWindowSnykScanListenerLS + private lateinit var snykToolWindowPanel: SnykToolWindowPanel + private lateinit var vulnerabilitiesTree: JTree + private lateinit var rootOssIssuesTreeNode: DefaultMutableTreeNode + private lateinit var rootSecurityIssuesTreeNode: DefaultMutableTreeNode + private lateinit var rootQualityIssuesTreeNode: DefaultMutableTreeNode + + private lateinit var snykFile: SnykFile + private lateinit var issue: ScanIssue + + private val fileName = "app.js" + + override fun setUp() { + super.setUp() + unmockkAll() + resetSettings(project) + + snykToolWindowPanel = SnykToolWindowPanel(project) + rootOssIssuesTreeNode = RootOssTreeNode(project) + rootSecurityIssuesTreeNode = RootSecurityIssuesTreeNode(project) + rootQualityIssuesTreeNode = RootQualityIssuesTreeNode(project) + + val file = myFixture.copyFileToProject(fileName) + val psiFile = WriteAction.computeAndWait { psiManager.findFile(file)!! } + snykFile = SnykFile(psiFile.project, psiFile.virtualFile) + + issue = mockk() + every { issue.getSeverityAsEnum() } returns Severity.CRITICAL + every { issue.title() } returns "title" + every { issue.issueNaming() } returns "issueNaming" + every { issue.cwes() } returns emptyList() + every { issue.cves() } returns emptyList() + every { issue.cvssV3() } returns null + every { issue.cvssScore() } returns null + every { issue.id() } returns "id" + every { issue.additionalData.getProductType() } returns ProductType.CODE_SECURITY + every { issue.additionalData.message } returns "Test message" + every { issue.additionalData.repoDatasetSize } returns 1 + every { issue.additionalData.exampleCommitFixes } returns + listOf( + ExampleCommitFix( + "https://commit-url", + listOf( + CommitChangeLine("1", 1, "lineChange"), + ), + ), + ) + every { + issue.additionalData.dataFlow + } returns listOf(DataFlow(0, getTestDataPath(), Range(Position(1, 1), Position(1, 1)), "")) + } + + fun testDisplaySnykCodeResults() { + cut = + SnykToolWindowSnykScanListenerLS( + project, + snykToolWindowPanel, + vulnerabilitiesTree, + rootSecurityIssuesTreeNode, + rootQualityIssuesTreeNode, + rootOssIssuesTreeNode, + ) + + val snykResults: MutableMap> = mutableMapOf() + snykResults[snykFile] = listOf(issue) + cut.displaySnykCodeResults(snykResults) + } +}