Skip to content

Commit

Permalink
Bugfixs/3523 newpr (#3527)
Browse files Browse the repository at this point in the history
* 3522: fixing issues with report where scenario outlines contained quotes or lt/gt tags in the title. Titles like "Test access to "<color>"" caused strange effects on the report (data-order attribute got unbound by the quotes, <color> was interpreted as HTML tag.

* 3522: undoing Formatter changes to keep tests green and doing everything "inside" ftl

* 3523: small mods on test code to use assertThat on Files as it should be

---------

Co-authored-by: t.eitzenberger <thomas.eitzenberger@gematik.de>
  • Loading branch information
eitzenbe and t.eitzenberger authored Sep 8, 2024
1 parent a430f17 commit 1e51683
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@
<#list breadcrumbs as breadcrumb>
<#assign breadcrumbReport = absoluteReportName.forRequirement(breadcrumb) />
<#assign breadcrumbTitle = breadcrumb.displayName > <!-- inflection.of(breadcrumb.displayName).asATitle()-->
> <a href="${breadcrumbReport}">${formatter.htmlCompatibleStoryTitle(breadcrumbTitle)}</a>
> <a href="${breadcrumbReport}">
${formatter.escapeHtmlTags(formatter.htmlCompatibleStoryTitle(breadcrumbTitle))}
</a>
</#list>
<#-- > ${formatter.htmlCompatibleTestTitle(formatter.renderTitle(testOutcome.title))}-->
<#-- > ${formatter.htmlCompatibleTestTitle(testOutcome.title)}-->
> ${formatter.htmlCompatibleTestTitle(formatter.humanReadableFormOf(testOutcome.title))}
>
${formatter.escapeHtmlTags(formatter.htmlCompatibleTestTitle(formatter.humanReadableFormOf(testOutcome.title)))}
</span>
</div>
<div class="rightbg"></div>
Expand Down Expand Up @@ -346,7 +349,7 @@
<#assign roeResult = row.result/>
</#if>
<td class="test-${roeResult}"><a
href="#${rowIndex}">${formatter.plainHtmlCompatible(value)}</a>
href="#${rowIndex}"><#outputformat 'HTML'>${formatter.plainHtmlCompatible(value)}</#outputformat></a>
</td>
</#list>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,11 @@
<a href="${scenario.parentReport}">${scenario.parentName}</a>
</#if>
</td>
<td data-order="${scenario.title}">
<td data-order="<#outputformat 'HTML'>${scenario.title}</#outputformat>">
<#if (scenario.hasExamples() && scenario.getExampleOutcomes()?has_content)>
<i class="bi bi-table"
title="Data Driven Scenario"> <a
href="${scenario.scenarioReport}">${scenario.title}</a>
href="${scenario.scenarioReport}"><#outputformat 'HTML'>${scenario.title}</#outputformat></a>
<br/>
<#list scenario.getResultCounts() as resultCount>
<#assign outcome_icon = formatter.resultIcon().forResult(resultCount.result) />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@
<#assign roeResult = row.result/>
</#if>
<td class="test-${roeResult}"><a
href="#${rowIndex}">${formatter.plainHtmlCompatible(value)}</a>
href="#${rowIndex}"><#outputformat 'HTML'>${formatter.plainHtmlCompatible(value)}</#outputformat></a>
</td>
</#list>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@
</td>
<td>
<#if (scenario.hasExamples() && scenario.getExampleOutcomes()?has_content)>
<i class="bi bi-table" title="Data Driven Scenario"> <a href="${scenario.scenarioReport}">${scenario.title}</a>
<i class="bi bi-table" title="Data Driven Scenario"> <a href="${scenario.scenarioReport}"><#outputformat 'HTML'>${scenario.title}</#outputformat></a>
<br/>
<#list scenario.getResultCounts() as resultCount>
<#assign outcome_icon = formatter.resultIcon().forResult(resultCount.result) />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,10 @@ public String htmlCompatibleStoryTitle(Object fieldValue) {
(htmlCompatible(renderMarkdownWithoutTags(firstLine))) : htmlCompatible(firstLine);
}

public String escapeHtmlTags(String fieldValue) {
return fieldValue.replace("<", "&lt;").replace(">", "&gt;");
}

public String htmlCompatibleTestTitle(Object fieldValue) {
String firstLine = fieldValue.toString().split("\\n")[0];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.io.FileMatchers.anExistingFile;

public class WhenGeneratingAnHtmlReport extends AbstractReportGenerationTest {

@Mock
TestOutcomes allTestOutcomes;

@Before
public void setupWorkingDirectory() throws IOException {

MockitoAnnotations.initMocks(this);

File screenshotsSourceDirectory = FileSystemUtils.getResourceAsFile("screenshots");
File[] screenshots = screenshotsSourceDirectory.listFiles();

Expand All @@ -50,7 +51,7 @@ public void should_generate_an_HTML_report_for_an_acceptance_test_run() throws E

File htmlReport = reporter.generateReportFor(testOutcome);

assertThat(htmlReport.exists(), is(true));
assertThat(htmlReport, anExistingFile());
}

@Test
Expand All @@ -61,7 +62,7 @@ public void should_generate_an_HTML_report_for_an_acceptance_test_run_with_no_st
testOutcome.determineTestFailureCause(new AssertionError("test failed"));
File htmlReport = reporter.generateReportFor(testOutcome);

assertThat(htmlReport.exists(), is(true));
assertThat(htmlReport, anExistingFile());
}

@Test
Expand All @@ -73,7 +74,7 @@ public void should_generate_an_HTML_report_for_a_failing_manual_acceptance_test(
testOutcome.setAnnotatedResult(TestResult.FAILURE);
File htmlReport = reporter.generateReportFor(testOutcome);

assertThat(htmlReport.exists(), is(true));
assertThat(htmlReport, anExistingFile());
}


Expand All @@ -82,10 +83,10 @@ public void css_stylesheets_should_also_be_copied_to_the_output_directory() thro
TestOutcome testOutcome = new TestOutcome("a_simple_test_case");
testOutcome.recordStep(TestStepFactory.successfulTestStepCalled("step 1"));
reporter.generateReportFor(testOutcome);

File cssDir = new File(outputDirectory, "css");
File cssStylesheet = new File(cssDir, "core.css");
assertThat(cssStylesheet.exists(), is(true));
assertThat(cssStylesheet, anExistingFile());
}

@Test
Expand All @@ -99,7 +100,7 @@ public void css_stylesheets_should_be_copied_to_a_non_standard_output_directory(

File cssDir = new File(differentOutputDirectory, "css");
File cssStylesheet = new File(cssDir, "core.css");
assertThat(cssStylesheet.exists(), is(true));
assertThat(cssStylesheet, anExistingFile());
}

@Test
Expand All @@ -109,14 +110,14 @@ public void the_report_file_and_the_resources_should_be_together() throws Except
testOutcome.recordStep(TestStepFactory.successfulTestStepCalled("step 1"));

reporter.generateReportFor(testOutcome);

File report = new File(outputDirectory,Digest.ofTextValue("a_simple_test_case") + ".html");
File cssDir = new File(outputDirectory, "css");
File cssStylesheet = new File(cssDir, "core.css");
assertThat(cssStylesheet.exists(), is(true));
assertThat(report.exists(), is(true));
assertThat(cssStylesheet, anExistingFile());
assertThat(report, anExistingFile());
}

@Test
public void screenshots_should_have_a_separate_html_report() throws Exception {
TestOutcome testOutcome = TestOutcome.forTest("should_do_this", SomeTestScenario.class);
Expand All @@ -130,7 +131,7 @@ public void screenshots_should_have_a_separate_html_report() throws Exception {
File report = reporter.generateReportFor(testOutcome);
File screenshotReport = withSuffix(report,"_screenshots");

assertThat(screenshotReport.exists(), is(true));
assertThat(screenshotReport, anExistingFile());

}

Expand Down Expand Up @@ -215,7 +216,7 @@ public void the_resources_can_come_from_a_different_location_in_a_jar_file() thr
final String alternativeResourceDirectory = "alt-report-resources";
reporter.setResourceDirectory(alternativeResourceDirectory);
reporter.generateReportFor(testOutcome);

File expectedCssStylesheet = new File(new File(outputDirectory,"css"), "alternative.css");
assertThat(expectedCssStylesheet.exists(), is(true));
}
Expand All @@ -242,7 +243,7 @@ public void a_different_resource_location_can_be_specified_by_using_a_system_pro

environmentVariables.setProperty("thucydides.report.resources", "alt-report-resources");
reporter.generateReportFor(testOutcome);

File expectedCssStylesheet = new File(new File(outputDirectory,"css"), "alternative.css");
assertThat(expectedCssStylesheet.exists(), is(true));
}
Expand All @@ -256,12 +257,12 @@ public void when_an_alternative_resource_directory_is_used_the_default_styleshee
final String alternativeResourceDirectory = "alt-report-resources";
reporter.setResourceDirectory(alternativeResourceDirectory);
reporter.generateReportFor(testOutcome);

File defaultCssStylesheet = new File(new File(outputDirectory,"css"), "core.css");
assertThat(defaultCssStylesheet.exists(), is(false));
}


@Test
public void a_sample_report_should_be_generated_in_the_target_directory() throws Exception {

Expand Down

0 comments on commit 1e51683

Please sign in to comment.