Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: Mickael Istria <mistria@redhat.com>
  • Loading branch information
mickaelistria committed Oct 11, 2019
1 parent 8fb84af commit c1ef37f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
3 changes: 2 additions & 1 deletion org.eclipse.wildwebdeveloper.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ Require-Bundle: org.eclipse.wildwebdeveloper;bundle-version="0.5.0",
org.eclipse.lsp4j,
org.eclipse.lsp4j.jsonrpc,
org.eclipse.debug.ui,
org.eclipse.core.filesystem
org.eclipse.core.filesystem,
org.eclipse.ui.editors
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.lsp4e.operations.completion.LSContentAssistProcessor;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.tests.harness.util.DisplayHelper;
import org.eclipse.ui.texteditor.ITextEditor;
import org.junit.Rule;
import org.junit.Test;

Expand All @@ -53,7 +55,7 @@ public void testAngular() throws Exception {
IFolder appFolder = project.getFolder("src").getFolder("app");

IFile appComponentFile = appFolder.getFile("app.component.ts");
ITextEditor editor = (ITextEditor) IDE
TextEditor editor = (TextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), appComponentFile);
DisplayHelper.sleep(4000); // Give time for LS to initialize enough before making edit and sending a didChange
// make an edit
Expand All @@ -73,10 +75,11 @@ protected boolean condition() {
}.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 50000));
editor.close(false);

editor = (ITextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), appFolder.getFile("app.componentWithHtml.ts"));
editor = (TextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), appFolder.getFile("app.componentWithHtml.ts"));
DisplayHelper.sleep(4000); // Give time for LS to initialize enough before making edit and sending a didChange
IFile appComponentHTML = appFolder.getFile("app.componentWithHtml.html");
editor = (ITextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), appComponentHTML);
editor = (TextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), appComponentHTML);
document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
assertTrue("No error found on erroneous HTML component file", new DisplayHelper() {
@Override protected boolean condition() {
IMarker[] markers;
Expand All @@ -89,6 +92,11 @@ protected boolean condition() {
}
}
}.waitForCondition(editor.getSite().getShell().getDisplay(), 30000));
// test completion
LSContentAssistProcessor contentAssistProcessor = new LSContentAssistProcessor();
ICompletionProposal[] proposals = contentAssistProcessor.computeCompletionProposals(Utils.getTextViewer(editor), document.get().indexOf("}}"));
proposals[0].apply(document);
assertEquals("Incorrect completion insertion", "<<h1>{{title}}</h1>", document.get());
}

public static String getNpmLocation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
*******************************************************************************/
package org.eclipse.wildwebdeveloper.tests;

import static org.junit.Assert.fail;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
Expand All @@ -26,6 +30,10 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.ui.texteditor.ITextEditor;

public class Utils {

Expand Down Expand Up @@ -61,4 +69,22 @@ public static IProject provisionTestProject(String folderName) throws CoreExcept
return null;
}

public static ITextViewer getTextViewer(IEditorPart part) throws InvocationTargetException {
try {
if (part instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor) part;

Method getSourceViewerMethod = AbstractTextEditor.class.getDeclaredMethod("getSourceViewer"); //$NON-NLS-1$
getSourceViewerMethod.setAccessible(true);
return (ITextViewer) getSourceViewerMethod.invoke(textEditor);
} else {
fail("Unable to open editor");
return null;
}
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException e) {
throw new InvocationTargetException(e);
}
}

}

0 comments on commit c1ef37f

Please sign in to comment.