Search in sources :

Example 1 with JasmineSuiteStructure

use of com.intellij.javascript.testFramework.jasmine.JasmineSuiteStructure in project intellij-plugins by JetBrains.

the class JstdTestLocationProvider method findJasmineTestLocation.

@Nullable
private static PsiElement findJasmineTestLocation(@NotNull Project project, @NotNull String testCaseName, @Nullable String testMethodName) {
    VirtualFile file = findJasmineTestFileSource(project, testCaseName);
    if (file == null) {
        return null;
    }
    PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
    if (psiFile instanceof JSFile) {
        JSFile jsFile = (JSFile) psiFile;
        JasmineFileStructureBuilder builder = JasmineFileStructureBuilder.getInstance();
        JasmineFileStructure jasmineFileStructure = builder.fetchCachedTestFileStructure(jsFile);
        Map<String, JasmineSuiteStructure> map = Maps.newHashMap();
        for (JasmineSuiteStructure suite : jasmineFileStructure.getSuites()) {
            visitSuite("", map, suite);
        }
        JasmineSuiteStructure suite = map.get(testCaseName);
        if (suite != null) {
            if (testMethodName == null) {
                return suite.getEnclosingCallExpression();
            }
            JasmineSpecStructure spec = suite.getInnerSpecByName(testMethodName);
            if (spec != null) {
                return spec.getEnclosingCallExpression();
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JasmineSuiteStructure(com.intellij.javascript.testFramework.jasmine.JasmineSuiteStructure) JasmineFileStructureBuilder(com.intellij.javascript.testFramework.jasmine.JasmineFileStructureBuilder) PsiFile(com.intellij.psi.PsiFile) JasmineSpecStructure(com.intellij.javascript.testFramework.jasmine.JasmineSpecStructure) JSFile(com.intellij.lang.javascript.psi.JSFile) JasmineFileStructure(com.intellij.javascript.testFramework.jasmine.JasmineFileStructure) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with JasmineSuiteStructure

use of com.intellij.javascript.testFramework.jasmine.JasmineSuiteStructure in project intellij-plugins by JetBrains.

the class JstdTestLocationProvider method visitSuite.

private static void visitSuite(@NotNull String prefix, @NotNull Map<String, JasmineSuiteStructure> map, @NotNull JasmineSuiteStructure suite) {
    final String joinedSuitesName;
    if (prefix.isEmpty()) {
        joinedSuitesName = suite.getName();
    } else {
        joinedSuitesName = prefix + " " + suite.getName();
    }
    map.put(joinedSuitesName, suite);
    for (JasmineSuiteStructure child : suite.getSuites()) {
        visitSuite(joinedSuitesName, map, child);
    }
}
Also used : JasmineSuiteStructure(com.intellij.javascript.testFramework.jasmine.JasmineSuiteStructure)

Aggregations

JasmineSuiteStructure (com.intellij.javascript.testFramework.jasmine.JasmineSuiteStructure)2 JasmineFileStructure (com.intellij.javascript.testFramework.jasmine.JasmineFileStructure)1 JasmineFileStructureBuilder (com.intellij.javascript.testFramework.jasmine.JasmineFileStructureBuilder)1 JasmineSpecStructure (com.intellij.javascript.testFramework.jasmine.JasmineSpecStructure)1 JSFile (com.intellij.lang.javascript.psi.JSFile)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 Nullable (org.jetbrains.annotations.Nullable)1