|
| 1 | +/** |
| 2 | + * Copyright (c) 2018-present, Jim Kynde Meyer |
| 3 | + * All rights reserved. |
| 4 | + * <p> |
| 5 | + * This source code is licensed under the MIT license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. |
| 7 | + */ |
| 8 | +package com.intellij.lang.jsgraphql.schema; |
| 9 | + |
| 10 | +import com.google.common.collect.Lists; |
| 11 | +import com.intellij.codeInsight.completion.CompletionType; |
| 12 | +import com.intellij.openapi.application.ApplicationManager; |
| 13 | +import com.intellij.psi.PsiDocumentManager; |
| 14 | +import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; |
| 15 | +import org.junit.Test; |
| 16 | + |
| 17 | +import java.util.List; |
| 18 | + |
| 19 | + |
| 20 | +public class JSGraphQLSchemaCodeInsightTest extends LightCodeInsightFixtureTestCase { |
| 21 | + |
| 22 | + @Override |
| 23 | + public void setUp() throws Exception { |
| 24 | + super.setUp(); |
| 25 | + } |
| 26 | + |
| 27 | + @Override |
| 28 | + protected String getTestDataPath() { |
| 29 | + return "test-resources/testData/graphql/schema"; |
| 30 | + } |
| 31 | + |
| 32 | + // ---- completion ---- |
| 33 | + |
| 34 | + @Test |
| 35 | + public void testCompletionImplementsFirstInterface() { |
| 36 | + doTestCompletion("CompletionImplementsFirstInterface.graphqls", Lists.newArrayList("KnownInterface1", "KnownInterface2")); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void testCompletionImplementsSecondInterface() { |
| 41 | + doTestCompletion("CompletionImplementsSecondInterface.graphqls", Lists.newArrayList("KnownInterface2")); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + public void testCompletionOperation() { |
| 46 | + doTestCompletion("CompletionOperation.graphqls", Lists.newArrayList("directive", "enum", "extend", "fragment", "input", "interface", "mutation", "query", "scalar", "schema", "subscription", "type", "union", "{")); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void testCompletionImplementsKeyword1() { |
| 51 | + doTestCompletion("CompletionImplementsKeyword1.graphqls", Lists.newArrayList("implements")); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + public void testCompletionImplementsKeyword2() { |
| 56 | + doTestCompletion("CompletionImplementsKeyword2.graphqls", Lists.newArrayList("implements")); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void testCompletionFieldType() { |
| 61 | + doTestCompletion("CompletionFieldType.graphqls", Lists.newArrayList("AnotherKnownType", "Boolean", "Float", "ID", "Int", "KnownInterface", "KnownType", "MyEnum", "MyUnion", "String")); |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + public void testCompletionInputFieldType() { |
| 66 | + doTestCompletion("CompletionInputFieldType.graphqls", Lists.newArrayList("Boolean", "Float", "ID", "Int", "MyEnum", "MyInput1", "String")); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + public void testCompletionArgumentType() { |
| 71 | + doTestCompletion("CompletionArgumentType.graphqls", Lists.newArrayList("Boolean", "Float", "ID", "Int", "MyCompletionInputABC", "MyEnum", "String")); |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + public void testCompletionSecondArgumentType() { |
| 76 | + doTestCompletion("CompletionSecondArgumentType.graphqls", Lists.newArrayList("Boolean", "Float", "ID", "Int", "MyCompletionInputABC", "MyEnum", "String")); |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + public void testCompletionDirective1() { |
| 81 | + doTestCompletion("CompletionDirective1.graphqls", Lists.newArrayList("foo")); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + public void testCompletionDirective2() { |
| 86 | + doTestCompletion("CompletionDirective2.graphqls", Lists.newArrayList("foo")); |
| 87 | + } |
| 88 | + |
| 89 | + @Test |
| 90 | + public void testCompletionDirective3() { |
| 91 | + // TODO: currently not supported by the completion contributor |
| 92 | + //doTestCompletion("CompletionDirective3.graphqls", Lists.newArrayList("arg")); |
| 93 | + } |
| 94 | + |
| 95 | + @Test |
| 96 | + public void testCompletionDirective4() { |
| 97 | + // TODO: currently not supported by the completion contributor |
| 98 | + //doTestCompletion("CompletionDirective4.graphqls", Lists.newArrayList("false", "true")); |
| 99 | + } |
| 100 | + |
| 101 | + @Test |
| 102 | + public void testCompletionFieldOverride() { |
| 103 | + doTestCompletion("CompletionFieldOverride.graphqls", Lists.newArrayList("fieldToImpl2: Boolean")); |
| 104 | + } |
| 105 | + |
| 106 | + private void doTestCompletion(String sourceFile, List<String> expectedCompletions) { |
| 107 | + myFixture.configureByFiles(sourceFile); |
| 108 | + myFixture.complete(CompletionType.BASIC, 1); |
| 109 | + final List<String> completions = myFixture.getLookupElementStrings(); |
| 110 | + assertEquals("Wrong completions", expectedCompletions, completions); |
| 111 | + ApplicationManager.getApplication().runWriteAction(() -> { |
| 112 | + myFixture.getEditor().getDocument().setText(""); // blank out the file so it doesn't affect other tests |
| 113 | + PsiDocumentManager.getInstance(myFixture.getProject()).commitAllDocuments(); |
| 114 | + }); |
| 115 | + } |
| 116 | + |
| 117 | + |
| 118 | + // ---- highlighting ----- |
| 119 | + |
| 120 | + // TODO |
| 121 | +// @Test |
| 122 | +// public void testErrorAnnotator() { |
| 123 | +// myFixture.configureByFiles("ErrorAnnotator.graphqls"); |
| 124 | +// myFixture.checkHighlighting(false, false, false); |
| 125 | +// } |
| 126 | + |
| 127 | +} |
0 commit comments