Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WINDUP-822: Overview page should list projects with collapsable div #763

Merged
merged 1 commit into from Nov 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -64,10 +64,10 @@ body {
border-bottom-right-radius: 8pt;
}

.panel.panel-primary {
.panel.panel-primary.panel-boarding {
border-radius: 8pt;
}
.panel.panel-primary > .panel-heading {
.panel.panel-primary.panel-boarding > .panel-heading {
border-radius: 8px 8px 0 0 !important;
border-color: #00255D;
}
Expand All @@ -93,6 +93,7 @@ h3.panel-title span.s {
.projectBox .points { width: 49%; }
.projectBox .points .number { font-size: 70pt; }
.panel .panel-body .points .number { font-size: 50pt; width: 1.5em; }
.panel .panel-body .points .mainNumber { font-size: 50pt;}

.panel .panel-body .info h4 { font-weight: bold; font-size: 11pt; margin: 6pt 0 4pt 0; }
.panel .panel-body .info h4:first-child { margin-top: 0; }
Expand Down Expand Up @@ -281,4 +282,4 @@ p.windup-contributors {
/** General rules */
.floatRight {
float: right;
}
}
Expand Up @@ -14,6 +14,19 @@
width: 14px;
}

.panel .panel-body .points .number {
width:100%;
font-size: 50pt;
}

.arrowIcon {
padding-right:30px;
}

.clickable {
cursor: pointer;
}

.totalLoe {
font-size: 100px;
display: block;
Expand Down
@@ -0,0 +1,14 @@
$(document).on('click', '.panel-heading', function(e){
var $this = $(this);
if(!$this.hasClass('panel-collapsed')) {
$this.parents('.panel').find('.panel-body').slideUp();
$this.parents('.panel').removeClass('panel-boarding');
$this.addClass('panel-collapsed');
$this.find('i').removeClass('glyphicon-chevron-down').addClass('glyphicon-chevron-up');
} else {
$this.parents('.panel').find('.panel-body').slideDown();
$this.parents('.panel').addClass('panel-boarding');
$this.removeClass('panel-collapsed');
$this.find('i').removeClass('glyphicon-chevron-up').addClass('glyphicon-chevron-down');
}
})
Expand Up @@ -105,14 +105,17 @@

<#macro projectModelRenderer projectModel>
<div class="panel panel-primary projectBox">
<div class="panel-heading">
<h3 class="panel-title">${projectModel.rootFileModel.prettyPath?html}</h3>
<#assign panelStoryPoints = getMigrationEffortPoints(projectModel, false, reportModel.includeTags, reportModel.excludeTags)>
<div class="panel-heading panel-collapsed clickable">
<span class="pull-left"><i class="glyphicon glyphicon-chevron-up arrowIcon"></i></span>
<h3 class="panel-title">${projectModel.rootFileModel.prettyPath?html} (${panelStoryPoints} story points)</h3>
</div>
<div class="panel-body" style="display:none">
<div class="container-fluid summaryMargin">

<!-- Points -->
<div class="points" style="text-align: center; color: #00254b; padding-bottom: 1ex;">
<div class="number">${getMigrationEffortPoints(projectModel, false, reportModel.includeTags, reportModel.excludeTags)}</div>
<div class="number">${panelStoryPoints}</div>
<div>Story Points</div>
</div>

Expand Down Expand Up @@ -175,6 +178,7 @@
</#list>
</table>
</#if>
</div>
</div>
<#list sortProjectsByPathAscending(projectModel.childProjects) as childProject>
<@projectModelRenderer childProject/>
Expand Down Expand Up @@ -283,10 +287,9 @@


<script src="resources/js/jquery-1.10.1.min.js"></script>

<script src="resources/libraries/flot/jquery.flot.min.js"></script>
<script src="resources/libraries/flot/jquery.flot.pie.min.js"></script>

<script src="resources/js/windup-overview.js"/>
<script src="resources/js/bootstrap.min.js"></script>

<@render_pie project=reportModel.projectModel recursive=true elementID="application_pie" includeTags=reportModel.includeTags excludeTags=reportModel.excludeTags />
Expand Down
@@ -1,18 +1,21 @@
package org.jboss.windup.testutil.html;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

import java.util.List;

/**
* Contains methods for testing the Java Application Overview report.
*
*
* @author <a href="mailto:jesse.sightler@gmail.com">Jesse Sightler</a>
*
*/
public class TestJavaApplicationOverviewUtil extends TestReportUtil
{

public void checkMainEffort(int expectedEffort)
{
WebElement effortElement = getDriver()
Expand Down Expand Up @@ -41,9 +44,9 @@ public void checkAppSectionEffort(String appSection, int expectedEffort)
throw new CheckFailedException("Unable to find app section with name: " + appSection);
}

WebElement effortElement = appSectionEl.findElement(By.xpath(
"../..//div[@class = 'points']/div[text() = 'Story Points']/../div[@class = 'number']"));
String effortString = effortElement.getText().trim();
String xpath = getElementXPath(getDriver(),appSectionEl) + "/" + "../..//div[@class = \\'points\\']/div[text() = \\'Story Points\\']/../div[@class = \\'number\\']";

String effortString = getStringValueForXpathElement(getDriver(),xpath).trim();
effortString = effortString.replace(",", "");

try
Expand All @@ -60,7 +63,7 @@ public void checkAppSectionEffort(String appSection, int expectedEffort)

/**
* Checks if the given App section, filepath, and effort level can be seen in the report.
*
* <p>
* For example checkFilePathEffort("src_example", "src/main/resources/test.properties", 13) will ensure that an
* application called "src_example" is in the report, with a line referencing "src/main/resources/test.properties"
* and that this line contains the effort level 13).
Expand All @@ -86,7 +89,7 @@ public void checkFilePathEffort(String appSection, String filePath, int effort)
{
try
{
int number = Integer.parseInt(element.getText());
int number = Integer.parseInt(getTextForElement(element));
if (number == effort)
{
return;
Expand All @@ -111,7 +114,7 @@ public void checkFilePathEffort(String appSection, String filePath, int effort)

/**
* Checks if the given App section, filepath, and tag can be found in the report.
*
* <p>
* For example calling checkFilePathAndIssues("src_example", "src/main/resources/test.properties",
* "Web Servlet again") will ensure that an application called "src_example" is in the report, with a line
* referencing "src/main/resources/test.properties" and that this line contains text in the issues section saying
Expand All @@ -134,7 +137,8 @@ public void checkFilePathAndIssues(String appSection, String filePath, String te
List<WebElement> elements = fileRowElement.findElements(By.xpath("./td[position() = 3]"));
for (WebElement element : elements)
{
if (element.getText() != null && element.getText().contains(text))
String elementText = getTextForElement(element);
if (elementText != null && elementText.contains(text))
{
return;
}
Expand All @@ -146,7 +150,7 @@ public void checkFilePathAndIssues(String appSection, String filePath, String te

/**
* Checks if the given App section, filepath, and tag can be found in the report.
*
* <p>
* For example calling checkFilePathAndTag("src_example", "src/main/resources/test.properties", "Properties") will
* ensure that an application called "src_example" is in the report, with a line referencing
* "src/main/resources/test.properties" and that this file is tagged "Properties"
Expand All @@ -168,19 +172,47 @@ public void checkFilePathAndTag(String appSection, String filePath, String tag)
List<WebElement> elements = fileRowElement.findElements(By.xpath("./td[position() = 2]/span"));
for (WebElement element : elements)
{
if (element.getText() != null && element.getText().equals(tag))
{
return;
}
String spanValue = getTextForElement(element);
if (spanValue.equals(tag))
{
return;
}
}

throw new CheckFailedException("Unable to find app: " + appSection + " file: " + filePath + " with tag: "
+ tag);
}

/**
* In case the element's css is display:none, selenium does not see it using getText().
* Therefore this methods uses javascript to query the value
* @param element
* @return
*/
private String getTextForElement(WebElement element) {
HtmlUnitDriver driver=(HtmlUnitDriver) getDriver();
String xpath = getElementXPath(driver,element);
String result = getStringValueForXpathElement(driver,xpath);
return result.trim();
}

/**
* Returns the xpath full path of the given element. E.g something like /html/body/div[2]/p
* @param driver
* @param element
* @return
*/
private String getElementXPath(WebDriver driver, WebElement element) {
return "/html/" + (String)((JavascriptExecutor)driver).executeScript("gPt=function(c){if(c.id!==''){return'id(\"'+c.id+'\")'}if(c===document.body){return c.tagName}var a=0;var e=c.parentNode.childNodes;for(var b=0;b<e.length;b++){var d=e[b];if(d===c){return gPt(c.parentNode)+'/'+c.tagName+'['+(a+1)+']'}if(d.nodeType===1&&d.tagName===c.tagName){a++}}};return gPt(arguments[0]).toLowerCase();", element);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol, figuring that out had to be painful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most of it is copied from stackoverflow answer :)

}

private String getStringValueForXpathElement(WebDriver driver, String xpathToElement) {
return (String)((JavascriptExecutor)driver).executeScript("var foundDocument=document.evaluate( '" +xpathToElement + "', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue; if(foundDocument !=null) {return foundDocument.textContent;} else {return null} ");
}

/**
* Checks if the given App section, filepath, and tag can be found in the report.
*
* <p>
* For example calling checkFilePathAndTag("src_example", "src/main/resources/test.properties") will ensure that an
* application called "src_example" is in the report, with a line referencing "src/main/resources/test.properties"
*/
Expand All @@ -203,7 +235,7 @@ public void checkFilePath(String appSection, String filePath)

private WebElement getFileRowElement(String appSection, String filePath)
{
WebElement fileTable = getAppSectionElement(appSection).findElement(By.xpath("../../table"));
WebElement fileTable = getAppSectionElement(appSection).findElement(By.xpath("../../div[contains(@class,'panel-body')]/table"));

WebElement fileRow = fileTable.findElement(By
.xpath("./tbody/tr/td/a[normalize-space(text()) = '" + filePath + "']/../.."));
Expand All @@ -215,11 +247,23 @@ private WebElement getAppSectionElement(String appSection)
List<WebElement> titleElements = getDriver().findElements(By.className("panel-title"));
for (WebElement el : titleElements)
{
if (el.getText() != null && appSection.equals(el.getText().trim()))
String panelTitleText = el.getText();
if (panelTitleText != null)
{
return el;
panelTitleText = parseOutAppTitle(panelTitleText);
if (appSection.equals(panelTitleText.trim()))
{
return el;
}
}

}
return null;
}

private String parseOutAppTitle(String input)
{
//remove story points information
return input.replaceAll("\\(.*\\)", "");
}
}
Expand Up @@ -7,6 +7,7 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

/**
* Contains utility methods for assisting tests in interacting with the generated reports.
Expand All @@ -19,7 +20,10 @@ public class TestReportUtil

public TestReportUtil()
{
this.driver = new HtmlUnitDriver(false);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("firefox");
capabilities.setJavascriptEnabled(true);
this.driver = new HtmlUnitDriver(capabilities);
}

/**
Expand Down