Skip to content

Commit

Permalink
feature: truncate long titles in HTML tip texts to save space (#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Jun 10, 2016
1 parent 6b0c905 commit 0a8d1cc
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.regex.Pattern;

import static ch.lambdaj.Lambda.join;
import static org.apache.commons.lang3.StringUtils.abbreviate;

/**
* Format text for HTML reports.
Expand Down Expand Up @@ -294,6 +295,9 @@ public static String htmlAttributeCompatible(Object fieldValue) {
.replaceAll("\"", "'")));
}

public static String htmlAttributeCompatible(Object fieldValue, int maxLength) {
return abbreviate(htmlAttributeCompatible(fieldValue), maxLength);
}

public ResultIconFormatter resultIcon() {
return new ResultIconFormatter();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.thucydides.core.reports.json.gson;

import com.google.common.base.Charsets;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.inject.Inject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ class WhenFormattingDataForTheHTMLReports extends Specification {
"<expected \"a\"\nGot \"b\">" | "(expected 'a' Got 'b')"

}

@Unroll
def "should abbreviate HTML messages if requested"() {
expect:
def formatter = new Formatter(issueTracking);
formatter.htmlAttributeCompatible(message, 15) == formattedMessage
where:
message | formattedMessage
"<expected \"a\">" | "(expected 'a')"
"<expected \"a\"\nGot \"b\">" | "(expected 'a..."

}

@Unroll
def "should display objects in string form"() {
expect:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<span style="display:none">${testOutcome.result}</span></td>
<td class="${testOutcome.result}-text">
<div class="ellipsis">
<a href="${relativeLink}${testOutcome.reportName}.html" class="ellipsis" title="${formatter.htmlAttributeCompatible(testOutcome.conciseErrorMessage)}">
<a href="${relativeLink}${testOutcome.reportName}.html" class="ellipsis" title="${formatter.htmlAttributeCompatible(testOutcome.conciseErrorMessage, 40)}">
${testOutcome.unqualified.titleWithLinks} ${testOutcome.formattedIssues}
</a></div>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@
</#if>
<td width="%" colspan="4" class="error-message-cell">
<div class="error-message ellipsis"
title='${formatter.htmlAttributeCompatible(errorMessageTitle)}'><pre>${formatter.htmlAttributeCompatible(errorMessageTitle)!''}</pre></div>
title='${formatter.htmlAttributeCompatible(errorMessageTitle,40)}'><pre>${formatter.htmlAttributeCompatible(errorMessageTitle,40)!''}</pre></div>
<#if step.nestedException?has_content>
<@stacktrace cause=step.nestedException />
</#if>
Expand Down Expand Up @@ -466,7 +466,7 @@
</#if>
<#if (testOutcome.errorMessage)??>
<span class="error-message"
title="${formatter.htmlAttributeCompatible(testOutcome.conciseErrorMessage)}">${testOutcome.conciseErrorMessage}</span>
title="${formatter.htmlAttributeCompatible(testOutcome.conciseErrorMessage,40)}">${testOutcome.conciseErrorMessage}</span>
<#if (testOutcome.nestedTestFailureCause)??>
<@stacktrace cause=testOutcome.nestedTestFailureCause />
</#if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
<div id="contenttilttle">
<#if (testOutcome.result == "FAILURE" || testOutcome.result == "ERROR")>
<div class="screenshotFailure panel panel-danger">
<div class="panel-heading"><span class='error-caption ellipsis'>${testOutcome.result}: ${formatter.htmlAttributeCompatible(testOutcome.failureDetails.conciseErrorMessage)}</span></div>
<div class="panel-heading"><span class='error-caption ellipsis'>${testOutcome.result}: ${formatter.htmlAttributeCompatible(testOutcome.failureDetails.conciseErrorMessage, 40)}</span></div>
<div class="panel-body">
<a href="${testOutcome.failureDetails.pageSourceLink}" target="_blank" class="btn btn-info">HTML Source</a>
</div>
Expand Down

0 comments on commit 0a8d1cc

Please sign in to comment.