|
45 | 45 | import org.junit.jupiter.api.Test; |
46 | 46 |
|
47 | 47 | public class TestVue { |
48 | | - static IProject project; |
49 | | - static IFolder componentFolder; |
50 | | - |
51 | | - @BeforeAll |
52 | | - public static void setUp() throws Exception { |
53 | | - AllCleanRule.closeIntro(); |
54 | | - AllCleanRule.enableLogging(); |
55 | | - |
56 | | - project = Utils.provisionTestProject("vue-app"); |
57 | | - ProcessBuilder builder = NodeJSManager.prepareNPMProcessBuilder("install", "--no-bin-links", "--ignore-scripts") |
58 | | - .directory(project.getLocation().toFile()); |
59 | | - Process process = builder.start(); |
60 | | - System.out.println(builder.command().toString()); |
61 | | - String result = process.errorReader().lines().collect(Collectors.joining("\n")); |
62 | | - System.out.println("Error Stream: >>>\n" + result + "\n<<<"); |
63 | | - |
64 | | - result = process.inputReader().lines().collect(Collectors.joining("\n")); |
65 | | - System.out.println("Output Stream: >>>\n" + result + "\n<<<"); |
66 | | - |
67 | | - assertEquals(0, process.waitFor(), "npm install didn't complete property"); |
68 | | - |
69 | | - project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); |
70 | | - assertTrue(project.exists()); |
71 | | - componentFolder = project.getFolder("src").getFolder("components"); |
72 | | - assertTrue(componentFolder.exists()); |
73 | | - } |
74 | | - |
75 | | - @BeforeEach |
76 | | - public void setUpTestCase() { |
77 | | - AllCleanRule.enableLogging(); |
78 | | - } |
79 | | - |
80 | | - @AfterAll |
81 | | - public static void tearDown() throws Exception { |
82 | | - new AllCleanRule().afterEach(null); |
83 | | - } |
84 | | - |
85 | | - @Test |
86 | | - void testVueApp() throws Exception { |
87 | | - IFile appComponentFile = project.getFile("src/App.vue"); |
88 | | - TextEditor editor = (TextEditor) IDE |
89 | | - .openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), appComponentFile); |
90 | | - LanguageServerWrapper lsWrapper = LanguageServiceAccessor.getLSWrapper(project, |
91 | | - LanguageServersRegistry.getInstance().getDefinition("org.eclipse.wildwebdeveloper.vue")); |
92 | | - |
93 | | - assertTrue(DisplayHelper.waitForCondition(editor.getSite().getShell().getDisplay(), 30000, () -> { |
94 | | - try { |
95 | | - return Arrays |
96 | | - .stream(appComponentFile.findMarkers("org.eclipse.lsp4e.diagnostic", true, |
97 | | - IResource.DEPTH_ZERO)) |
98 | | - .anyMatch(marker -> marker.getAttribute(IMarker.MESSAGE, "").contains("never read")); |
99 | | - } catch (CoreException e) { |
100 | | - e.printStackTrace(); |
101 | | - return false; |
102 | | - } |
103 | | - }), |
104 | | - "Diagnostic not published in standalone component file"); |
105 | | - IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput()); |
106 | | - assertTrue(DisplayHelper.waitForCondition(editor.getSite().getShell().getDisplay(), 30000, |
107 | | - () -> lsWrapper.isActive() && lsWrapper.isConnectedTo(LSPEclipseUtils.toUri(document)) |
108 | | - && lsWrapper.canOperate(project) && lsWrapper.canOperate(document))); |
109 | | - LSContentAssistProcessor contentAssistProcessor = new LSContentAssistProcessor(); |
110 | | - ICompletionProposal[] proposals = contentAssistProcessor.computeCompletionProposals(Utils.getViewer(editor), |
111 | | - document.get().indexOf(" }}")); |
112 | | - Optional<ICompletionProposal> proposal = Arrays.stream(proposals) |
113 | | - .filter(item -> item.getDisplayString().equals("appParameter")).findFirst(); |
114 | | - |
115 | | - assertTrue(proposal.isPresent(), "Proposal not exists"); |
116 | | - proposal.get().apply(document); |
117 | | - |
118 | | - assertTrue(document.get().contains("{{ this.appParameter }}"), "Incorrect completion insertion"); |
119 | | - |
120 | | - editor.close(false); |
121 | | - } |
122 | | - |
123 | | - @Test |
124 | | - void testVueTemplate() throws Exception { |
125 | | - TextEditor editor = (TextEditor) IDE.openEditor( |
126 | | - PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), |
127 | | - componentFolder.getFile("HelloWorld.vue")); |
128 | | - LanguageServerWrapper lsWrapper = LanguageServiceAccessor.getLSWrapper(project, |
129 | | - LanguageServersRegistry.getInstance().getDefinition("org.eclipse.wildwebdeveloper.vue")); |
130 | | - IFile appComponentHTML = componentFolder.getFile("HelloWorld.vue"); |
131 | | - editor = (TextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), |
132 | | - appComponentHTML); |
133 | | - IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput()); |
134 | | - String tagName = "only-start"; |
135 | | - String tag = '<' + tagName + '>'; |
136 | | - document.set(document.get().replace(tag, tag + "<")); |
137 | | - assertTrue(DisplayHelper.waitForCondition(editor.getSite().getShell().getDisplay(), 30000, () -> { |
138 | | - IMarker[] markers; |
139 | | - try { |
140 | | - markers = appComponentHTML.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO); |
141 | | - return Arrays.stream(markers).anyMatch( |
142 | | - marker -> marker.getAttribute(IMarker.MESSAGE, "").contains("Element is missing end tag.")); |
143 | | - } catch (CoreException e) { |
144 | | - e.printStackTrace(); |
145 | | - return false; |
146 | | - } |
147 | | - }), |
148 | | - "No error found on erroneous HTML component file"); |
149 | | - |
150 | | - assertTrue(DisplayHelper.waitForCondition(editor.getSite().getShell().getDisplay(), 30000, |
151 | | - () -> lsWrapper.isActive() && lsWrapper.isConnectedTo(LSPEclipseUtils.toUri(document)) |
152 | | - && lsWrapper.canOperate(project) && lsWrapper.canOperate(document))); |
153 | | - |
154 | | - LSContentAssistProcessor contentAssistProcessor = new LSContentAssistProcessor(); |
155 | | - |
156 | | - int pos = document.get().indexOf(tag) + tag.length(); |
157 | | - ICompletionProposal[] proposals = contentAssistProcessor.computeCompletionProposals(Utils.getViewer(editor), |
158 | | - pos + 1); |
159 | | - |
160 | | - // Find closing tag proposal |
161 | | - ICompletionProposal closingTagProposal = Arrays.stream(proposals) |
162 | | - .filter(p -> p.getDisplayString().equals('/' + tagName)).findFirst().orElse(null); |
163 | | - assertNotNull(closingTagProposal, "Closing tag proposal not found for '" + tag + "'"); |
164 | | - |
165 | | - closingTagProposal.apply(document); |
166 | | - assertEquals(new String(componentFolder.getFile("HelloWorldCorrect.vue").getContents().readAllBytes()).trim(), |
167 | | - document.get().trim(), "Incorrect completion insertion"); |
168 | | - |
169 | | - editor.close(false); |
170 | | - } |
| 48 | + static IProject project; |
| 49 | + static IFolder componentFolder; |
| 50 | + |
| 51 | + @BeforeAll |
| 52 | + public static void setUp() throws Exception { |
| 53 | + AllCleanRule.closeIntro(); |
| 54 | + AllCleanRule.enableLogging(); |
| 55 | + |
| 56 | + project = Utils.provisionTestProject("vue-app"); |
| 57 | + ProcessBuilder builder = NodeJSManager.prepareNPMProcessBuilder("install", "--no-bin-links", "--ignore-scripts") |
| 58 | + .directory(project.getLocation().toFile()); |
| 59 | + Process process = builder.start(); |
| 60 | + System.out.println(builder.command().toString()); |
| 61 | + String result = process.errorReader().lines().collect(Collectors.joining("\n")); |
| 62 | + System.out.println("Error Stream: >>>\n" + result + "\n<<<"); |
| 63 | + |
| 64 | + result = process.inputReader().lines().collect(Collectors.joining("\n")); |
| 65 | + System.out.println("Output Stream: >>>\n" + result + "\n<<<"); |
| 66 | + |
| 67 | + assertEquals(0, process.waitFor(), "npm install didn't complete property"); |
| 68 | + |
| 69 | + project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); |
| 70 | + assertTrue(project.exists()); |
| 71 | + componentFolder = project.getFolder("src").getFolder("components"); |
| 72 | + assertTrue(componentFolder.exists()); |
| 73 | + } |
| 74 | + |
| 75 | + @BeforeEach |
| 76 | + public void setUpTestCase() { |
| 77 | + AllCleanRule.enableLogging(); |
| 78 | + } |
| 79 | + |
| 80 | + @AfterAll |
| 81 | + public static void tearDown() throws Exception { |
| 82 | + new AllCleanRule().afterEach(null); |
| 83 | + } |
| 84 | + |
| 85 | + @Test |
| 86 | + void testVueApp() throws Exception { |
| 87 | + IFile appComponentFile = project.getFile("src/App.vue"); |
| 88 | + TextEditor editor = (TextEditor) IDE |
| 89 | + .openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), appComponentFile); |
| 90 | + LanguageServerWrapper lsWrapper = LanguageServiceAccessor.getLSWrapper(project, |
| 91 | + LanguageServersRegistry.getInstance().getDefinition("org.eclipse.wildwebdeveloper.vue")); |
| 92 | + |
| 93 | + assertTrue(DisplayHelper.waitForCondition(editor.getSite().getShell().getDisplay(), 30000, () -> { |
| 94 | + try { |
| 95 | + return Arrays |
| 96 | + .stream(appComponentFile.findMarkers("org.eclipse.lsp4e.diagnostic", true, |
| 97 | + IResource.DEPTH_ZERO)) |
| 98 | + .anyMatch(marker -> marker.getAttribute(IMarker.MESSAGE, "").contains("never read")); |
| 99 | + } catch (CoreException e) { |
| 100 | + e.printStackTrace(); |
| 101 | + return false; |
| 102 | + } |
| 103 | + }), "Diagnostic not published in standalone component file"); |
| 104 | + IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput()); |
| 105 | + assertTrue(DisplayHelper.waitForCondition(editor.getSite().getShell().getDisplay(), 30000, |
| 106 | + () -> lsWrapper.isActive() && lsWrapper.isConnectedTo(LSPEclipseUtils.toUri(document)) |
| 107 | + && lsWrapper.canOperate(project) && lsWrapper.canOperate(document))); |
| 108 | + LSContentAssistProcessor contentAssistProcessor = new LSContentAssistProcessor(); |
| 109 | + ICompletionProposal[] proposals = contentAssistProcessor.computeCompletionProposals(Utils.getViewer(editor), |
| 110 | + document.get().indexOf(" }}")); |
| 111 | + Optional<ICompletionProposal> proposal = Arrays.stream(proposals) |
| 112 | + .filter(item -> item.getDisplayString().equals("appParameter")).findFirst(); |
| 113 | + |
| 114 | + assertTrue(proposal.isPresent(), "Proposal not exists"); |
| 115 | + proposal.get().apply(document); |
| 116 | + |
| 117 | + assertTrue(document.get().contains("{{ this.appParameter }}"), "Incorrect completion insertion"); |
| 118 | + |
| 119 | + editor.close(false); |
| 120 | + } |
| 121 | + |
| 122 | + @Test |
| 123 | + void testVueTemplate() throws Exception { |
| 124 | + TextEditor editor = (TextEditor) IDE.openEditor( |
| 125 | + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), |
| 126 | + componentFolder.getFile("HelloWorld.vue")); |
| 127 | + LanguageServerWrapper lsWrapper = LanguageServiceAccessor.getLSWrapper(project, |
| 128 | + LanguageServersRegistry.getInstance().getDefinition("org.eclipse.wildwebdeveloper.vue")); |
| 129 | + IFile appComponentHTML = componentFolder.getFile("HelloWorld.vue"); |
| 130 | + editor = (TextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), |
| 131 | + appComponentHTML); |
| 132 | + IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput()); |
| 133 | + String tagName = "only-start"; |
| 134 | + String tag = '<' + tagName + '>'; |
| 135 | + document.set(document.get().replace(tag, tag + "<")); |
| 136 | + assertTrue(DisplayHelper.waitForCondition(editor.getSite().getShell().getDisplay(), 30000, () -> { |
| 137 | + IMarker[] markers; |
| 138 | + try { |
| 139 | + markers = appComponentHTML.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO); |
| 140 | + return Arrays.stream(markers).anyMatch( |
| 141 | + marker -> marker.getAttribute(IMarker.MESSAGE, "").contains("Element is missing end tag.")); |
| 142 | + } catch (CoreException e) { |
| 143 | + e.printStackTrace(); |
| 144 | + return false; |
| 145 | + } |
| 146 | + }), "No error found on erroneous HTML component file"); |
| 147 | + |
| 148 | + assertTrue(DisplayHelper.waitForCondition(editor.getSite().getShell().getDisplay(), 30000, |
| 149 | + () -> lsWrapper.isActive() && lsWrapper.isConnectedTo(LSPEclipseUtils.toUri(document)) |
| 150 | + && lsWrapper.canOperate(project) && lsWrapper.canOperate(document))); |
| 151 | + |
| 152 | + LSContentAssistProcessor contentAssistProcessor = new LSContentAssistProcessor(); |
| 153 | + |
| 154 | + int pos = document.get().indexOf(tag) + tag.length(); |
| 155 | + ICompletionProposal[] proposals = contentAssistProcessor.computeCompletionProposals(Utils.getViewer(editor), |
| 156 | + pos + 1); |
| 157 | + |
| 158 | + System.out.println("TestVue.testVueTemplate$ Position: " + pos + " [..." |
| 159 | + + document.get().substring(pos - 3, pos) + "|" + document.get().substring(pos, pos + 3) + "...]"); |
| 160 | + |
| 161 | + System.out.println("TestVue.testVueTemplate$ >>> proposals >>>"); |
| 162 | + for (ICompletionProposal p : proposals) { |
| 163 | + System.out.println("TestVue.testVueTemplate$\tproposal: " + p.getDisplayString()); |
| 164 | + } |
| 165 | + System.out.println("TestVue.testVueTemplate$ <<< proposals <<<"); |
| 166 | + |
| 167 | + // Find closing tag proposal |
| 168 | + ICompletionProposal closingTagProposal = Arrays.stream(proposals) |
| 169 | + .filter(p -> p.getDisplayString().equals('/' + tagName)).findFirst().orElse(null); |
| 170 | + assertNotNull(closingTagProposal, "Closing tag proposal not found for '" + tag + "'"); |
| 171 | + |
| 172 | + closingTagProposal.apply(document); |
| 173 | + assertEquals(new String(componentFolder.getFile("HelloWorldCorrect.vue").getContents().readAllBytes()).trim(), |
| 174 | + document.get().trim(), "Incorrect completion insertion"); |
| 175 | + |
| 176 | + editor.close(false); |
| 177 | + } |
171 | 178 | } |
0 commit comments