@Nullable private static JstdTestCaseStructure createTestCaseStructure( @NotNull JstdTestFileStructure jsTestFileStructure, @NotNull JSCallExpression testCaseCallExpression) { JSReferenceExpression referenceExpression = ObjectUtils.tryCast( testCaseCallExpression.getMethodExpression(), JSReferenceExpression.class); if (referenceExpression != null) { String referenceName = referenceExpression.getReferencedName(); if (TEST_CASE_NAME.equals(referenceName) || ASYNC_TEST_CASE_NAME.equals(referenceName)) { JSExpression[] arguments = JsPsiUtils.getArguments(testCaseCallExpression); if (arguments.length >= 1) { String testCaseName = JsPsiUtils.extractStringValue(arguments[0]); if (testCaseName != null) { JSObjectLiteralExpression testsObjectLiteral = null; if (arguments.length >= 2) { testsObjectLiteral = JsPsiUtils.extractObjectLiteralExpression(arguments[1]); } JstdTestCaseStructure testCaseStructure = new JstdTestCaseStructure( jsTestFileStructure, testCaseName, testCaseCallExpression, testsObjectLiteral); jsTestFileStructure.addTestCaseStructure(testCaseStructure); if (testsObjectLiteral != null) { fillTestCaseStructureByObjectLiteral(testCaseStructure, testsObjectLiteral); } return testCaseStructure; } } } } return null; }
@Override protected boolean isSuitableElement( @NotNull JSFile jsFile, @NotNull JSCallExpression callExpression) { JstdTestFileStructure structure = JstdTestFileStructureBuilder.getInstance().fetchCachedTestFileStructure(jsFile); String name = structure.getNameByPsiElement(callExpression.getMethodExpression()); return name != null; }
@Override public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { JSCallExpression jsCallExpression = PsiTreeUtil.getParentOfType(element, JSCallExpression.class); if (jsCallExpression == null) { return false; } JSExpression methodExpression = jsCallExpression.getMethodExpression(); if (methodExpression instanceof JSReferenceExpression) { String referencedName = ((JSReferenceExpression) methodExpression).getReferencedName(); return "add".equals(referencedName); } return false; }