Skip to content

Commit

Permalink
fixed after hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
bischoffdev committed Nov 27, 2020
1 parent 1c2aaa1 commit b8c24d8
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

Back to [Readme](README.md).

## [2.6.1] - 2020-11-27

### Fixed
* After hooks with content were not displayed anymore

## [2.6.0] - 2020-11-27

### Fixed
Expand Down Expand Up @@ -603,6 +608,7 @@ steps with status `pending` or `undefined` (default value is `false`) (#74)

Initial project version on GitHub and Maven Central.

[2.6.1]: https://github.com/trivago/cluecumber-report-plugin/tree/2.6.1
[2.6.0]: https://github.com/trivago/cluecumber-report-plugin/tree/2.6.0
[2.5.0]: https://github.com/trivago/cluecumber-report-plugin/tree/2.5.0
[2.4.0]: https://github.com/trivago/cluecumber-report-plugin/tree/2.4.0
Expand Down
6 changes: 3 additions & 3 deletions example-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>de.benjamin-bischoff</groupId>
<artifactId>cluecumber-test-project</artifactId>
<version>2.6.0</version>
<version>2.6.1</version>
<packaging>pom</packaging>

<properties>
Expand Down Expand Up @@ -69,8 +69,8 @@

<!-- Optional properties to expand scenario hooks, step hooks and doc strings when scenario details are shown (default: false) -->
<expandBeforeAfterHooks>true</expandBeforeAfterHooks>
<!--<expandStepHooks>true</expandStepHooks>-->
<!--<expandDocStrings>true</expandDocStrings>-->
<expandStepHooks>true</expandStepHooks>
<expandDocStrings>true</expandDocStrings>

<!-- optional: Cluecumber log level -->
<!--<logLevel>default</logLevel>-->
Expand Down
2 changes: 1 addition & 1 deletion plugin-code/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.trivago.rta</groupId>
<artifactId>cluecumber-report-plugin</artifactId>
<version>2.6.0</version>
<version>2.6.1</version>
<url>https://github.com/trivago/cluecumber-report-plugin</url>

<name>Cluecumber Maven Plugin for Cucumber Reports</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void setAfter(final List<ResultMatch> after) {
}

public boolean anyAfterHookHasContent() {
for (ResultMatch resultMatch : before) {
for (ResultMatch resultMatch : after) {
if (resultMatch.hasContent()) {
return true;
}
Expand Down Expand Up @@ -319,6 +319,10 @@ public boolean hasHooks() {
return getBefore().size() > 0 || getAfter().size() > 0;
}

public boolean hasHooksWithContent() {
return anyBeforeHookHasContent() || anyAfterHookHasContent();
}

public boolean hasDocStrings() {
for (Step step : backgroundSteps) {
if (step.getDocString() != null) {
Expand Down Expand Up @@ -353,6 +357,22 @@ public boolean hasStepHooks() {
return false;
}

public boolean hasStepHooksWithContent() {
for (Step step : backgroundSteps) {
if (step.hasHooksWithContent())
{
return true;
}
}
for (Step step : steps) {
if (step.hasHooksWithContent())
{
return true;
}
}
return false;
}

public List<ResultMatch> getAllResultMatches() {
List<ResultMatch> resultMatches = new ArrayList<>(getBefore());
resultMatches.addAll(getBackgroundSteps());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ public class Step extends ResultMatch {
@SerializedName("doc_string")
private DocString docString;

public boolean hasHooksWithContent() {
for (ResultMatch resultMatch : before) {
if (resultMatch.hasContent()) {
return true;
}
}
for (ResultMatch resultMatch : after) {
if (resultMatch.hasContent()) {
return true;
}
}
return false;
}

public List<ResultMatch> getBefore() {
return before;
}
Expand Down Expand Up @@ -65,7 +79,10 @@ public String returnNameWithArguments() {
for (int i = arguments.size() - 1; i >= 0; i--) {
String argument = arguments.get(i).getVal();
if (argument != null) {
tmpName = tmpName.replaceFirst(Pattern.quote(argument), Matcher.quoteReplacement("<span class=\"parameter\">" + argument + "</span>"));
tmpName = tmpName.replaceFirst(
Pattern.quote(argument),
Matcher.quoteReplacement("<span class=\"parameter\">" + argument + "</span>")
);
}
}
return tmpName;
Expand Down Expand Up @@ -116,7 +133,8 @@ public void setDocString(final DocString docString) {
}

public long getTotalDuration() {
long totalDurationNanoseconds = before.stream().mapToLong(beforeStep -> beforeStep.getResult().getDuration()).sum();
long totalDurationNanoseconds =
before.stream().mapToLong(beforeStep -> beforeStep.getResult().getDuration()).sum();
totalDurationNanoseconds += getResult().getDuration();
totalDurationNanoseconds += after.stream().mapToLong(afterStep -> afterStep.getResult().getDuration()).sum();
return totalDurationNanoseconds;
Expand All @@ -132,8 +150,12 @@ public String getUrlFriendlyName() {

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Step step = (Step) o;
return Objects.equals(getGlueMethodName(), step.getGlueMethodName());
}
Expand Down
4 changes: 2 additions & 2 deletions plugin-code/src/main/resources/template/scenario-detail.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ preheadlineLink="pages/feature-scenarios/feature_${element.featureIndex?c}.html"
${element.totalNumberOfSkippedSteps} skipped <@common.status status="skipped"/>
</li>
</ul>
<#if element.hasHooks() && (element.anyBeforeHookHasContent() || element.anyAfterHookHasContent())>
<#if element.hasHooks() && element.hasHooksWithContent()>
<button class="btn btn-outline-secondary btn-block collapsed" type="button" data-toggle="collapse"
aria-expanded="true" data-cluecumber-item="before-after-hooks-button"
data-target=".scenarioHook">Scenario Hooks with content
</button>
</#if>
<#if element.hasStepHooks()>
<#if element.hasStepHooks() && element.hasStepHooksWithContent()>
<button class="btn btn-outline-secondary btn-block collapsed" type="button" data-toggle="collapse"
aria-expanded="true" data-cluecumber-item="step-hooks-button"
data-target=".stepHook">Step Hooks with content
Expand Down

0 comments on commit b8c24d8

Please sign in to comment.