Skip to content

Commit caf3da8

Browse files
committed
test mode
1 parent 5de74bb commit caf3da8

File tree

3 files changed

+48
-39
lines changed

3 files changed

+48
-39
lines changed

src/main/kotlin/io/kotest/plugin/intellij/intentions/SurroundSelectionWithFunctionIntention.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import org.jetbrains.kotlin.psi.KtFile
1313
import org.jetbrains.kotlin.psi.KtPsiFactory
1414
import org.jetbrains.kotlin.resolve.ImportPath
1515

16+
internal var testMode = false
17+
1618
abstract class SurroundSelectionWithFunctionIntention : PsiElementBaseIntentionAction() {
1719

1820
override fun isAvailable(project: Project, editor: Editor?, element: PsiElement): Boolean {
19-
if (ApplicationManager.getApplication().isDispatchThread) {
21+
if (ApplicationManager.getApplication().isDispatchThread && !testMode) {
2022
return false
2123
}
2224
return try {

src/test/kotlin/io/kotest/plugin/intellij/intentions/AssertSoftlyIntentionTest.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import java.nio.file.Paths
99

1010
class AssertSoftlyIntentionTest : LightJavaCodeInsightFixtureTestCase() {
1111

12+
init {
13+
testMode = true
14+
}
15+
1216
override fun getTestDataPath(): String {
1317
val path = Paths.get("./src/test/resources/").toAbsolutePath()
1418
return path.toString()

src/test/kotlin/io/kotest/plugin/intellij/intentions/ShouldThrowIntentionTest.kt

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,33 @@ import java.nio.file.Paths
99

1010
class ShouldThrowIntentionTest : LightJavaCodeInsightFixtureTestCase() {
1111

12-
override fun getTestDataPath(): String {
13-
val path = Paths.get("./src/test/resources/").toAbsolutePath()
14-
return path.toString()
15-
}
16-
17-
fun testIntentionForPartialLine() {
18-
19-
myFixture.configureByFiles(
20-
"/intentions/should_throw.kt",
21-
"/io/kotest/core/spec/style/specs.kt"
22-
)
23-
editor.moveCaret(649)
24-
editor.selectionModel.setSelection(649, 651)
25-
26-
val intention = myFixture.findSingleIntention("Surround statements with shouldThrow assertion")
27-
intention.familyName shouldBe "Surround statements with shouldThrow assertion"
28-
29-
CommandProcessor.getInstance().runUndoTransparentAction {
30-
runWriteAction {
31-
intention.invoke(project, editor, file)
12+
init {
13+
testMode = true
14+
}
15+
16+
override fun getTestDataPath(): String {
17+
val path = Paths.get("./src/test/resources/").toAbsolutePath()
18+
return path.toString()
19+
}
20+
21+
fun testIntentionForPartialLine() {
22+
myFixture.configureByFiles(
23+
"/intentions/should_throw.kt",
24+
"/io/kotest/core/spec/style/specs.kt"
25+
)
26+
editor.moveCaret(649)
27+
editor.selectionModel.setSelection(649, 651)
28+
29+
val intention = myFixture.findSingleIntention("Surround statements with shouldThrow assertion")
30+
intention.familyName shouldBe "Surround statements with shouldThrow assertion"
31+
32+
CommandProcessor.getInstance().runUndoTransparentAction {
33+
runWriteAction {
34+
intention.invoke(project, editor, file)
35+
}
3236
}
33-
}
3437

35-
file.text shouldBe """package com.sksamuel.kotest.specs.behavior
38+
file.text shouldBe """package com.sksamuel.kotest.specs.behavior
3639
3740
import io.kotest.core.spec.style.BehaviorSpec
3841
import io.kotest.matchers.string.shouldStartWith
@@ -65,28 +68,28 @@ class BehaviorSpecExample : BehaviorSpec() {
6568
}
6669
}
6770
"""
68-
}
71+
}
6972

70-
fun testIntentionForFullSelection() {
73+
fun testIntentionForFullSelection() {
7174

72-
myFixture.configureByFiles(
73-
"/intentions/should_throw.kt",
74-
"/io/kotest/core/spec/style/specs.kt"
75-
)
75+
myFixture.configureByFiles(
76+
"/intentions/should_throw.kt",
77+
"/io/kotest/core/spec/style/specs.kt"
78+
)
7679

77-
editor.moveCaret(631)
78-
editor.selectionModel.setSelection(631, 658)
80+
editor.moveCaret(631)
81+
editor.selectionModel.setSelection(631, 658)
7982

80-
val intention = myFixture.findSingleIntention("Surround statements with shouldThrow assertion")
81-
intention.familyName shouldBe "Surround statements with shouldThrow assertion"
83+
val intention = myFixture.findSingleIntention("Surround statements with shouldThrow assertion")
84+
intention.familyName shouldBe "Surround statements with shouldThrow assertion"
8285

83-
CommandProcessor.getInstance().runUndoTransparentAction {
84-
runWriteAction {
85-
intention.invoke(project, editor, file)
86+
CommandProcessor.getInstance().runUndoTransparentAction {
87+
runWriteAction {
88+
intention.invoke(project, editor, file)
89+
}
8690
}
87-
}
8891

89-
file.text shouldBe """package com.sksamuel.kotest.specs.behavior
92+
file.text shouldBe """package com.sksamuel.kotest.specs.behavior
9093
9194
import io.kotest.core.spec.style.BehaviorSpec
9295
import io.kotest.matchers.string.shouldStartWith
@@ -119,5 +122,5 @@ class BehaviorSpecExample : BehaviorSpec() {
119122
}
120123
}
121124
"""
122-
}
125+
}
123126
}

0 commit comments

Comments
 (0)