mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-09-21 05:52:35 +08:00
test(jetbrains): stabilize ContextSettingsStateTest against platform app
ContextDraft's default editor value reads a PropertiesComponent app service, so constructing it requires an initialized IntelliJ Application. As a plain unit test this only passed when another BasePlatformTestCase initialized the app first in the same fork, making it order-dependent. Extend BasePlatformTestCase so the Application is always available.
This commit is contained in:
+12
-17
@@ -3,15 +3,16 @@ package ai.kilocode.client.settings.context
|
||||
import ai.kilocode.rpc.dto.CompactionConfigDto
|
||||
import ai.kilocode.rpc.dto.ConfigDto
|
||||
import ai.kilocode.rpc.dto.WatcherConfigDto
|
||||
import kotlin.test.Test
|
||||
import com.intellij.testFramework.fixtures.BasePlatformTestCase
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertNull
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class ContextSettingsStateTest {
|
||||
@Test
|
||||
fun `draft reads context config`() {
|
||||
// Extends BasePlatformTestCase so the IntelliJ Application is initialized: ContextDraft's default
|
||||
// editor value reads a PropertiesComponent app service, which is null in a plain unit test.
|
||||
class ContextSettingsStateTest : BasePlatformTestCase() {
|
||||
fun `test draft reads context config`() {
|
||||
val draft = contextDraft(ConfigDto(
|
||||
watcher = WatcherConfigDto(ignore = listOf("**/dist/**")),
|
||||
compaction = CompactionConfigDto(auto = true, threshold_percent = 75.0, prune = true),
|
||||
@@ -23,15 +24,13 @@ class ContextSettingsStateTest {
|
||||
assertEquals(listOf("**/dist/**"), draft.ignore)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `unchanged draft emits no patch`() {
|
||||
fun `test unchanged draft emits no patch`() {
|
||||
val draft = ContextDraft(auto = true, threshold = "75", prune = false, ignore = listOf("tmp/**"))
|
||||
|
||||
assertEquals(false, patch(draft, draft)?.let(::changed))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `boolean false values are emitted`() {
|
||||
fun `test boolean false values are emitted`() {
|
||||
val from = ContextDraft(auto = true, prune = true)
|
||||
val to = ContextDraft(auto = false, prune = false)
|
||||
val patch = patch(from, to)
|
||||
@@ -40,8 +39,7 @@ class ContextSettingsStateTest {
|
||||
assertEquals(false, patch?.compaction?.prune)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `threshold set and clear use explicit semantics`() {
|
||||
fun `test threshold set and clear use explicit semantics`() {
|
||||
val from = ContextDraft(threshold = "")
|
||||
val set = ContextDraft(threshold = "80")
|
||||
val clear = ContextDraft(threshold = "")
|
||||
@@ -51,16 +49,14 @@ class ContextSettingsStateTest {
|
||||
assertNull(patch(set, clear)?.compaction?.threshold_percent)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `watcher empty list is emitted`() {
|
||||
fun `test watcher empty list is emitted`() {
|
||||
val from = ContextDraft(ignore = listOf("**/dist/**"))
|
||||
val to = ContextDraft(ignore = emptyList())
|
||||
|
||||
assertEquals(emptyList(), patch(from, to)?.watcher?.ignore)
|
||||
assertEquals(emptyList<String>(), patch(from, to)?.watcher?.ignore)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `invalid threshold prevents patch without looking like no changes`() {
|
||||
fun `test invalid threshold prevents patch without looking like no changes`() {
|
||||
val from = ContextDraft(threshold = "50")
|
||||
val to = ContextDraft(auto = true, threshold = "101", prune = true, ignore = listOf("tmp/**"))
|
||||
|
||||
@@ -68,8 +64,7 @@ class ContextSettingsStateTest {
|
||||
assertNull(patch(from, to))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `saved match normalizes threshold formatting`() {
|
||||
fun `test saved match normalizes threshold formatting`() {
|
||||
assertTrue(savedMatches(ContextDraft(threshold = "75"), ContextDraft(threshold = "75.0")))
|
||||
assertFalse(savedMatches(ContextDraft(threshold = "75"), ContextDraft(threshold = "76")))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user