Skip to content

Commit

Permalink
Fix issue that inline attachments are shown multiple times (fixes #145)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Schäfer committed Oct 15, 2015
1 parent 36587fb commit 04de066
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.tngtech.jgiven.report.analysis;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -13,12 +9,7 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.tngtech.jgiven.report.model.ReportModel;
import com.tngtech.jgiven.report.model.ReportModelVisitor;
import com.tngtech.jgiven.report.model.ScenarioCaseModel;
import com.tngtech.jgiven.report.model.ScenarioModel;
import com.tngtech.jgiven.report.model.StepModel;
import com.tngtech.jgiven.report.model.Word;
import com.tngtech.jgiven.report.model.*;

/**
* Analyzes a report model and tries to infer which step method arguments match to which case argument.
Expand All @@ -45,6 +36,11 @@ public void analyze( ScenarioModel scenarioModel ) {
CollectPhase collectPhase = new CollectPhase( scenarioModel );
scenarioModel.accept( collectPhase );

if( collectPhase.noDataTablePossible ) {
scenarioModel.setCasesAsTable( false );
return;
}

try {
reduceMatrix( scenarioModel, collectPhase.argumentMatrix );
scenarioModel.setCasesAsTable( allStepsEqual( collectPhase.allWords ) );
Expand Down Expand Up @@ -238,6 +234,7 @@ static class CollectPhase extends ReportModelVisitor {
List<Word> allWordsOfCurrentCase;
ScenarioCaseModel currentCase;
final ScenarioModel scenarioModel;
boolean noDataTablePossible;

public CollectPhase( ScenarioModel model ) {
this.scenarioModel = model;
Expand All @@ -254,6 +251,10 @@ public void visit( ScenarioCaseModel scenarioCase ) {

@Override
public void visit( StepModel stepModel ) {
if( stepModel.getAttachment() != null && stepModel.getAttachment().isShowDirectly() ) {
this.noDataTablePossible = true;
}

for( Word word : stepModel.words ) {
if( word.isArg() ) {
ArgumentHolder holder = new ArgumentHolder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ public boolean isBinary() {
return binary;
}

public void setShowDirectly(boolean showDirectly) {
public void setShowDirectly( boolean showDirectly ) {
this.showDirectly = showDirectly ? true : null;
}

public boolean isShowDirectly() {
return showDirectly != null && showDirectly == true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,11 @@ public void attachments_can_be_directly_shown() throws IOException {
public void large_attachments_can_be_zoomed() throws IOException {
given().a_large_oval_circle();
}

@Test
@DataProvider( { "blue", "red" } )
public void inline_attachments_can_be_used_when_having_multiple_cases( String color ) throws IOException {
given().a_$_oval_circle( color );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,33 @@ public void it_can_be_added_as_an_attachment_to_the_step_with_title( String titl
}

public void a_large_oval_circle() throws IOException {
drawOval( 800, 600 );
drawOval( 800, 600, Color.BLUE );
}

public void an_oval_circle() throws IOException {
drawOval( 300, 200 );
drawOval( 300, 200, Color.BLUE );
}

private void drawOval( int width, int height ) throws IOException {
public void a_$_oval_circle( String color ) throws IOException {
drawOval( 300, 200, getColor( color ) );
}

private Color getColor( String color ) {
if( color.equals( "red" ) ) {
return Color.RED;
}
return Color.BLUE;
}

private void drawOval( int width, int height, Color color ) throws IOException {
BufferedImage image = new BufferedImage( width, height, BufferedImage.TYPE_INT_ARGB );

Graphics2D g = image.createGraphics();
g.setRenderingHint( RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON );

g.setStroke( new BasicStroke( 10 ) );
g.setPaint( Color.BLUE );
g.setPaint( color );
g.drawOval( 10, 10, width - 20, height - 20 );

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Expand Down
8 changes: 4 additions & 4 deletions jgiven-html5-report/src/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -478,12 +478,12 @@ <h4 ng-hide="!currentPage.loading">Loading <i class="fa fa-circle-o-notch fa-spi
</tr>
</table>

<div ng-if="step.attachment && step.attachment.showDirectly">
<img class="direct-image" ng-src="data/{{ step.attachment.value }}"
alt="{{ step.attachment.title }}"/>
</div>
</span>
<span ng-repeat-end></span>
<div ng-if="step.attachment && step.attachment.showDirectly">
<img class="direct-image" ng-src="data/{{ step.attachment.value }}"
alt="{{ step.attachment.title }}"/>
</div>
</span>
<span bindonce ng-repeat="scenarioCase in scenario.scenarioCases"
ng-init="step = scenarioCase.steps[$parent.$index]">
Expand Down

0 comments on commit 04de066

Please sign in to comment.