Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yairco1990 committed Dec 10, 2023
1 parent f718275 commit 4712480
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions Tabnine/src/test/kotlin/TabnineLensIntegrationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,43 @@
import com.intellij.codeInsight.hints.CollectorWithSettings
import com.intellij.codeInsight.hints.InlayHintsSinkImpl
import com.intellij.codeInsight.hints.NoSettings
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.Inlay
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixture4TestCase
import com.intellij.testFramework.replaceService
import com.tabnineCommon.capabilities.CapabilitiesService
import com.tabnineCommon.capabilities.Capability
import com.tabnineCommon.chat.lens.TabnineLensJavaProvider
import com.tabnineCommon.chat.lens.TabnineLensJavaBaseProvider
import org.junit.Test

class TabnineLensIntegrationTest : LightPlatformCodeInsightFixture4TestCase() {

@Test
fun `should return inlay hints for java function`() {
ApplicationManager.getApplication().replaceService(
CapabilitiesService::class.java,
object : CapabilitiesService() {
override fun isCapabilityEnabled(capability: Capability): Boolean {
return when (capability) {
Capability.TABNINE_CHAT -> true
else -> false
}
}
},
testRootDisposable
)
fun `should show inlay hints for java function when chat is enabled`() {
setJavaFile()
val provider = TabnineLensJavaBaseProvider { true }
runCollector(provider)
val inlays = getRenderedInlays()

assertEquals(inlays[0].offset, 0)
assertEquals(inlays[1].offset, 20)
assertEquals(inlays.size, 2)
}

@Test
fun `should not show inlay hints for java function when chat is disabled`() {
setJavaFile()
val provider = TabnineLensJavaBaseProvider { false }
runCollector(provider)
val inlays = getRenderedInlays()

assertEquals(inlays.size, 0)
}

private fun setJavaFile() {
myFixture.configureByText(
"Test.java",
"public class Test {\n public void test() {\n System.out.println(\"Hello World\");\n }\n}"
)
}

val provider = TabnineLensJavaProvider()

private fun runCollector(provider: TabnineLensJavaBaseProvider) {
val file = myFixture.file
val editor = myFixture.editor
val sink = InlayHintsSinkImpl(editor)
Expand All @@ -45,13 +50,12 @@ class TabnineLensIntegrationTest : LightPlatformCodeInsightFixture4TestCase() {
file,
true
)
val blockElementsInRange = myFixture.editor.inlayModel.getBlockElementsInRange(
file.textRange.startOffset,
file.textRange.endOffset
)
}

assertEquals(blockElementsInRange.get(0).offset, 0)
assertEquals(blockElementsInRange.get(1).offset, 20)
assertEquals(blockElementsInRange.size, 2)
private fun getRenderedInlays(): MutableList<Inlay<*>> {
return myFixture.editor.inlayModel.getBlockElementsInRange(
myFixture.file.textRange.startOffset,
myFixture.file.textRange.endOffset
)
}
}

0 comments on commit 4712480

Please sign in to comment.