Skip to content

Commit 15ebab4

Browse files
Michael NedzelskyMichael Nedzelsky
authored andcommitted
JS: add tests for quickfix: autoimport for Kotlin/Javascript projects
1 parent 53ef521 commit 15ebab4

9 files changed

+90
-8
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// "Import" "true"
2+
// ERROR: Please specify constructor invocation; classifier 'HTMLStyleElement' does not have a companion object
3+
4+
package test
5+
6+
import kotlin.js.dom.html.HTMLStyleElement
7+
8+
fun foo() {
9+
HTMLStyleElement
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// "Import" "true"
2+
3+
package test
4+
5+
import kotlin.js.dom.html5.localStorage
6+
7+
fun foo() {
8+
localStorage
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// "Import" "true"
2+
package some
3+
4+
import jquery.jq
5+
6+
fun testFun() {
7+
jq()
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// "Import" "true"
2+
// ERROR: Please specify constructor invocation; classifier 'HTMLStyleElement' does not have a companion object
3+
4+
package test
5+
6+
fun foo() {
7+
<caret>HTMLStyleElement
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// "Import" "true"
2+
3+
package test
4+
5+
fun foo() {
6+
<caret>localStorage
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// "Import" "true"
2+
package some
3+
4+
fun testFun() {
5+
<caret>jq()
6+
}

idea/tests/org/jetbrains/kotlin/idea/quickfix/AbstractQuickFixTest.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,8 @@ private static File findInspectionFile(@NotNull File startDir) {
6767
}
6868

6969
protected void doTest(@NotNull String beforeFileName) throws Exception {
70-
boolean isWithRuntime = beforeFileName.endsWith("Runtime.kt");
71-
7270
try {
73-
if (isWithRuntime) {
74-
ConfigLibraryUtil.configureKotlinRuntime(getModule(), getFullJavaJDK());
75-
}
71+
configureRuntimeIfNeeded(beforeFileName);
7672

7773
enableInspections(beforeFileName);
7874

@@ -81,9 +77,25 @@ protected void doTest(@NotNull String beforeFileName) throws Exception {
8177
checkForUnexpectedErrors();
8278
}
8379
finally {
84-
if (isWithRuntime) {
85-
ConfigLibraryUtil.unConfigureKotlinRuntime(getModule(), getProjectJDK());
86-
}
80+
unConfigureRuntimeIfNeeded(beforeFileName);
81+
}
82+
}
83+
84+
private static void configureRuntimeIfNeeded(@NotNull String beforeFileName) {
85+
if (beforeFileName.endsWith("JsRuntime.kt")) {
86+
ConfigLibraryUtil.configureKotlinJsRuntime(getModule(), getFullJavaJDK());
87+
}
88+
else if (beforeFileName.endsWith("Runtime.kt")) {
89+
ConfigLibraryUtil.configureKotlinRuntime(getModule(), getFullJavaJDK());
90+
}
91+
}
92+
93+
private void unConfigureRuntimeIfNeeded(@NotNull String beforeFileName) {
94+
if (beforeFileName.endsWith("JsRuntime.kt")) {
95+
ConfigLibraryUtil.unConfigureKotlinJsRuntime(getModule(), getProjectJDK());
96+
}
97+
else if (beforeFileName.endsWith("Runtime.kt")) {
98+
ConfigLibraryUtil.unConfigureKotlinRuntime(getModule(), getProjectJDK());
8799
}
88100
}
89101

idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,12 +395,30 @@ public void testCheckNoStackOverflowInImportInnerClassInCurrentFile() throws Exc
395395
doTest(fileName);
396396
}
397397

398+
@TestMetadata("beforeLibraryClassJsRuntime.kt")
399+
public void testLibraryClassJsRuntime() throws Exception {
400+
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/beforeLibraryClassJsRuntime.kt");
401+
doTest(fileName);
402+
}
403+
404+
@TestMetadata("beforeLibraryPropertyJsRuntime.kt")
405+
public void testLibraryPropertyJsRuntime() throws Exception {
406+
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/beforeLibraryPropertyJsRuntime.kt");
407+
doTest(fileName);
408+
}
409+
398410
@TestMetadata("beforeLibraryPropertyRuntime.kt")
399411
public void testLibraryPropertyRuntime() throws Exception {
400412
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/beforeLibraryPropertyRuntime.kt");
401413
doTest(fileName);
402414
}
403415

416+
@TestMetadata("beforeLibraryTopLevelFunctionImportJsRuntime.kt")
417+
public void testLibraryTopLevelFunctionImportJsRuntime() throws Exception {
418+
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/beforeLibraryTopLevelFunctionImportJsRuntime.kt");
419+
doTest(fileName);
420+
}
421+
404422
@TestMetadata("beforeLibraryTopLevelFunctionImportRuntime.kt")
405423
public void testLibraryTopLevelFunctionImportRuntime() throws Exception {
406424
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/beforeLibraryTopLevelFunctionImportRuntime.kt");

idea/tests/org/jetbrains/kotlin/test/ConfigLibraryUtil.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public static void unConfigureKotlinRuntime(Module module, Sdk sdk) {
6060
unConfigureLibrary(module, sdk, DEFAULT_JAVA_RUNTIME_LIB_NAME);
6161
}
6262

63+
public static void unConfigureKotlinJsRuntime(Module module, Sdk sdk) {
64+
unConfigureLibrary(module, sdk, DEFAULT_KOTLIN_JS_STDLIB_NAME);
65+
}
66+
6367
public static void configureLibrary(Module module, Sdk sdk, NewLibraryEditor libraryEditor) {
6468
configureSdk(module, sdk);
6569
addLibrary(libraryEditor, module);

0 commit comments

Comments
 (0)