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

Improved Tag Support: Tags in Excel and Tags for Examples Blocks in Json, Dhtml, Html, and Word formats #424

Merged
merged 9 commits into from
Feb 9, 2017
2 changes: 1 addition & 1 deletion src/Pickles/.vs/config/applicationhost.config
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
</site>
<site name="Pickles.BaseDhtmlFiles" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="Z:\pickles\src\Pickles\Pickles.BaseDhtmlFiles" /> </application>
<virtualDirectory path="/" physicalPath="D:\wps\kpi\pickles_plv\src\Pickles\Pickles.BaseDhtmlFiles" /> </application>
<bindings>
<binding protocol="http" bindingInformation="*:52000:localhost" />
</bindings>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ Scenario Outline: Add two positive numbers with many examples
When I perform add
Then the result should be <result>

@small @short_test
Examples: less than 100
| number 1 | number 2 | result |
| 10 | 20 | 30 |
| 20 | 20 | 40 |
| 20 | 30 | 50 |

@big
Examples: more than 100
| number 1 | number 2 | result |
| 100 | 20 | 120 |
Expand Down
472 changes: 241 additions & 231 deletions src/Pickles/Pickles.BaseDhtmlFiles/Index.html

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/Pickles/Pickles.BaseDhtmlFiles/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ li.step {
color: #0000FF;
}

.tags {
color: #44546a;
font-style: italic;
font-weight: normal;
}

.steps table {
margin-bottom: 0px;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Pickles/Pickles.BaseDhtmlFiles/js/featuresModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ function Examples(data) {
this.Name = data.Name || '';
this.Description = data.Description || '';
this.TableArgument = data.TableArgument == null ? null : new TableArgument(data.TableArgument.HeaderRow, data.TableArgument.DataRows);
}
this.Tags = data.Tags || null;
}

function Background(data) {
this.Name = data.Name || '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public void Then_feature_is_added_successfully()
{
Name = "Test Feature",
Description =
"In order to test this feature,\nAs a developer\nI want to test this feature"
"In order to test this feature,\nAs a developer\nI want to test this feature",
Tags = { "tag1", "tag2" }
};

using (var workbook = new XLWorkbook())
Expand All @@ -54,7 +55,8 @@ public void Then_feature_is_added_successfully()
excelFeatureFormatter.Format(worksheet, feature);

Check.That(worksheet.Cell("A1").Value).IsEqualTo(feature.Name);
Check.That(worksheet.Cell("B2").Value).IsEqualTo(feature.Description);
Check.That(worksheet.Cell("C2").Value).IsEqualTo("tag1, tag2");
Check.That(worksheet.Cell("B3").Value).IsEqualTo(feature.Description);
}
}

Expand All @@ -68,12 +70,14 @@ public void Then_feature_with_background_is_added_successfully()
Name = "Test Feature",
Description =
"In order to test this feature,\nAs a developer\nI want to test this feature",
Tags = { "tag1", "tag2" }
};
var background = new Scenario
{
Name = "Test Background Scenario",
Description =
"In order to test this background,\nAs a developer\nI want to test this background"
"In order to test this background,\nAs a developer\nI want to test this background",
Tags = { "tag1", "tag2" }
};
var given = new Step { NativeKeyword = "Given", Name = "a precondition" };
background.Steps = new List<Step>(new[] { given });
Expand All @@ -83,10 +87,10 @@ public void Then_feature_with_background_is_added_successfully()
{
IXLWorksheet worksheet = workbook.AddWorksheet("SHEET1");
excelFeatureFormatter.Format(worksheet, feature);

Check.That(worksheet.Cell("B4").Value).IsEqualTo(background.Name);
Check.That(worksheet.Cell("C5").Value).IsEqualTo(background.Description);
Check.That(worksheet.Cell("D6").Value).IsEqualTo(given.Name);
Check.That(worksheet.Cell("B5").Value).IsEqualTo(background.Name);
Check.That(worksheet.Cell("C6").Value).IsEqualTo("tag1, tag2");
Check.That(worksheet.Cell("C7").Value).IsEqualTo(background.Description);
Check.That(worksheet.Cell("D8").Value).IsEqualTo(given.Name);
}
}

Expand All @@ -100,12 +104,14 @@ public void Then_feature_without_background_adds_first_scenario_on_correct_row()
Name = "Test Feature",
Description =
"In order to test this feature,\nAs a developer\nI want to test this feature",
Tags = { "tag1", "tag2" }
};
var scenario = new Scenario
{
Name = "Test Scenario",
Description =
"In order to test this scenario,\nAs a developer\nI want to test this scenario"
"In order to test this scenario,\nAs a developer\nI want to test this scenario",
Tags = { "tag1", "tag2" }
};
var given = new Step { NativeKeyword = "Given", Name = "a precondition" };
scenario.Steps = new List<Step>(new[] { given });
Expand All @@ -116,9 +122,10 @@ public void Then_feature_without_background_adds_first_scenario_on_correct_row()
IXLWorksheet worksheet = workbook.AddWorksheet("SHEET1");
excelFeatureFormatter.Format(worksheet, feature);

Check.That(worksheet.Cell("B4").Value).IsEqualTo(scenario.Name);
Check.That(worksheet.Cell("C5").Value).IsEqualTo(scenario.Description);
Check.That(worksheet.Cell("D6").Value).IsEqualTo(given.Name);
Check.That(worksheet.Cell("B5").Value).IsEqualTo(scenario.Name);
Check.That(worksheet.Cell("C6").Value).IsEqualTo("tag1, tag2");
Check.That(worksheet.Cell("C7").Value).IsEqualTo(scenario.Description);
Check.That(worksheet.Cell("D8").Value).IsEqualTo(given.Name);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public void ThenSingleScenarioOutlineAddedSuccessfully()
Name = "Test Feature",
Description =
"In order to test this feature,\nAs a developer\nI want to test this feature",
Examples = examples
Examples = examples,
Tags = { "tag1", "tag2" }
};

using (var workbook = new XLWorkbook())
Expand All @@ -63,21 +64,22 @@ public void ThenSingleScenarioOutlineAddedSuccessfully()
excelScenarioFormatter.Format(worksheet, scenarioOutline, ref row);

Check.That(worksheet.Cell("B3").Value).IsEqualTo(scenarioOutline.Name);
Check.That(worksheet.Cell("C4").Value).IsEqualTo(scenarioOutline.Description);
Check.That(worksheet.Cell("B6").Value).IsEqualTo("Examples");
Check.That(worksheet.Cell("D7").Value).IsEqualTo("Var1");
Check.That(worksheet.Cell("E7").Value).IsEqualTo("Var2");
Check.That(worksheet.Cell("F7").Value).IsEqualTo("Var3");
Check.That(worksheet.Cell("G7").Value).IsEqualTo("Var4");
Check.That(worksheet.Cell("D8").Value).IsEqualTo(1.0);
Check.That(worksheet.Cell("E8").Value).IsEqualTo(2.0);
Check.That(worksheet.Cell("F8").Value).IsEqualTo(3.0);
Check.That(worksheet.Cell("G8").Value).IsEqualTo(4.0);
Check.That(worksheet.Cell("D9").Value).IsEqualTo(5.0);
Check.That(worksheet.Cell("E9").Value).IsEqualTo(6.0);
Check.That(worksheet.Cell("F9").Value).IsEqualTo(7.0);
Check.That(worksheet.Cell("G9").Value).IsEqualTo(8.0);
Check.That(row).IsEqualTo(10);
Check.That(worksheet.Cell("C4").Value).IsEqualTo("tag1, tag2");
Check.That(worksheet.Cell("C5").Value).IsEqualTo(scenarioOutline.Description);
Check.That(worksheet.Cell("B7").Value).IsEqualTo("Examples");
Check.That(worksheet.Cell("D8").Value).IsEqualTo("Var1");
Check.That(worksheet.Cell("E8").Value).IsEqualTo("Var2");
Check.That(worksheet.Cell("F8").Value).IsEqualTo("Var3");
Check.That(worksheet.Cell("G8").Value).IsEqualTo("Var4");
Check.That(worksheet.Cell("D9").Value).IsEqualTo(1.0);
Check.That(worksheet.Cell("E9").Value).IsEqualTo(2.0);
Check.That(worksheet.Cell("F9").Value).IsEqualTo(3.0);
Check.That(worksheet.Cell("G9").Value).IsEqualTo(4.0);
Check.That(worksheet.Cell("D10").Value).IsEqualTo(5.0);
Check.That(worksheet.Cell("E10").Value).IsEqualTo(6.0);
Check.That(worksheet.Cell("F10").Value).IsEqualTo(7.0);
Check.That(worksheet.Cell("G10").Value).IsEqualTo(8.0);
Check.That(row).IsEqualTo(11);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public void ThenSingleScenarioAddedSuccessfully()
{
Name = "Test Feature",
Description =
"In order to test this feature,\nAs a developer\nI want to test this feature"
"In order to test this feature,\nAs a developer\nI want to test this feature",
Tags = { "tag1", "tag2" }
};

using (var workbook = new XLWorkbook())
Expand All @@ -55,8 +56,9 @@ public void ThenSingleScenarioAddedSuccessfully()
excelScenarioFormatter.Format(worksheet, scenario, ref row);

Check.That(worksheet.Cell("B3").Value).IsEqualTo(scenario.Name);
Check.That(worksheet.Cell("C4").Value).IsEqualTo(scenario.Description);
Check.That(row).IsEqualTo(5);
Check.That(worksheet.Cell("C4").Value).IsEqualTo("tag1, tag2");
Check.That(worksheet.Cell("C5").Value).IsEqualTo(scenario.Description);
Check.That(row).IsEqualTo(6);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Reflection;
using ClosedXML.Excel;
Expand Down Expand Up @@ -52,18 +53,26 @@ public void Format(IXLWorksheet worksheet, Feature feature)
worksheet.Cell("A1").Style.Font.SetBold();
worksheet.Cell("A1").Value = feature.Name;

if (feature.Tags != null && feature.Tags.Count != 0)
{
worksheet.Cell("B2").Value = "Tags:";
worksheet.Cell("C2").Value = String.Join(", ", feature.Tags);
worksheet.Range("B2:C2").Style.Font.Italic = true;
worksheet.Range("B2:C2").Style.Font.FontColor = XLColor.DavysGrey;
}

if (feature.Description.Length <= short.MaxValue)
{
worksheet.Cell("B2").Value = feature.Description;
worksheet.Cell("B3").Value = feature.Description;
}
else
{
var description = feature.Description.Substring(0, short.MaxValue);
Log.Warn("The description of feature {0} was truncated because of cell size limitations in Excel.", feature.Name);
worksheet.Cell("B2").Value = description;
worksheet.Cell("B3").Value = description;
}

worksheet.Cell("B2").Style.Alignment.WrapText = false;
worksheet.Cell("B3").Style.Alignment.WrapText = false;

var results = this.testResults.GetFeatureResult(feature);

Expand All @@ -82,7 +91,7 @@ public void Format(IXLWorksheet worksheet, Feature feature)

featureElementsToRender.AddRange(feature.FeatureElements);

var row = 4;
var row = 5;
foreach (var featureElement in featureElementsToRender)
{
var scenario = featureElement as Scenario;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ public void Format(IXLWorksheet worksheet, Scenario scenario, ref int row)
int originalRow = row;
worksheet.Cell(row, "B").Style.Font.SetBold();
worksheet.Cell(row++, "B").Value = scenario.Name;

if (scenario.Tags != null && scenario.Tags.Count != 0)
{
worksheet.Cell(row, "B").Value = "Tags:";
worksheet.Cell(row, "C").Value = String.Join(", ", scenario.Tags);
worksheet.Cell(row, "B").Style.Font.Italic = true;
worksheet.Cell(row, "B").Style.Font.FontColor = XLColor.DavysGrey;
worksheet.Cell(row, "C").Style.Font.Italic = true;
worksheet.Cell(row, "C").Style.Font.FontColor = XLColor.DavysGrey;
row++;
}

worksheet.Cell(row++, "C").Value = scenario.Description;

var results = this.testResults.GetScenarioResult(scenario);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,22 @@ public ExcelScenarioOutlineFormatter(
public void Format(IXLWorksheet worksheet, ScenarioOutline scenarioOutline, ref int row)
{
int originalRow = row;
worksheet.Cell(row, "B").Style.Font.SetBold();
worksheet.Cell(row++, "B").Value = scenarioOutline.Name;
worksheet.Cell(row++, "C").Value = scenarioOutline.Description;

if (scenarioOutline.Tags != null && scenarioOutline.Tags.Count != 0)
{
worksheet.Cell(row, "B").Value = "Tags:";
worksheet.Cell(row, "C").Value = String.Join(", ", scenarioOutline.Tags);
worksheet.Cell(row, "B").Style.Font.Italic = true;
worksheet.Cell(row, "B").Style.Font.FontColor = XLColor.DavysGrey;
worksheet.Cell(row, "C").Style.Font.Italic = true;
worksheet.Cell(row, "C").Style.Font.FontColor = XLColor.DavysGrey;
row++;
}

if (! string.IsNullOrWhiteSpace(scenarioOutline.Description))
worksheet.Cell(row++, "C").Value = scenarioOutline.Description;

var results = this.testResults.GetScenarioOutlineResult(scenarioOutline);
if (this.configuration.HasTestResults && (results != TestResult.Inconclusive))
Expand All @@ -68,7 +82,21 @@ public void Format(IXLWorksheet worksheet, ScenarioOutline scenarioOutline, ref
foreach (var example in scenarioOutline.Examples)
{
worksheet.Cell(row++, "B").Value = "Examples";
worksheet.Cell(row, "C").Value = example.Description;

if (example.Tags != null && example.Tags.Count != 0)
{
worksheet.Cell(row, "C").Value = "Tags:";
worksheet.Cell(row, "D").Value = String.Join(", ", example.Tags);
worksheet.Cell(row, "C").Style.Font.Italic = true;
worksheet.Cell(row, "C").Style.Font.FontColor = XLColor.DavysGrey;
worksheet.Cell(row, "D").Style.Font.Italic = true;
worksheet.Cell(row, "D").Style.Font.FontColor = XLColor.DavysGrey;
row++;
}

if (! string.IsNullOrWhiteSpace(example.Description))
worksheet.Cell(row++, "C").Value = example.Description;

this.excelTableFormatter.Format(worksheet, example.TableArgument, ref row);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public void ThenCanRenderTags()
Check.That(header).HasAttribute("class", "scenario-heading");
Check.That(header.Elements().Count()).IsEqualTo(3);

Check.That(header.Elements().ElementAt(0)).IsNamed("h2");
Check.That(header.Elements().ElementAt(1)).IsNamed("p");
Check.That(header.Elements().ElementAt(0)).IsNamed("p");
Check.That(header.Elements().ElementAt(1)).IsNamed("h2");
Check.That(header.Elements().ElementAt(2)).IsNamed("div");

var tagsParagraph = header.Elements().ElementAt(1);
var tagsParagraph = header.Elements().ElementAt(0);

Check.That(tagsParagraph.ToString()).IsEqualTo(
@"<p class=""tags"" xmlns=""http://www.w3.org/1999/xhtml"">Tags: <span>tag1</span>, <span>tag2</span></p>");
Expand Down Expand Up @@ -121,11 +121,11 @@ public void FeatureTagsAreAddedToScenarioTags()

Check.That(header.Elements().Count()).IsEqualTo(3);

Check.That(header.Elements().ElementAt(0)).IsNamed("h2");
Check.That(header.Elements().ElementAt(1)).IsNamed("p");
Check.That(header.Elements().ElementAt(2)).IsNamed("div");
Check.That(header.Elements().ElementAt(0)).IsNamed("p"); // tags
Check.That(header.Elements().ElementAt(1)).IsNamed("h2"); // title
Check.That(header.Elements().ElementAt(2)).IsNamed("div");// description

var tagsParagraph = header.Elements().ElementAt(1);
var tagsParagraph = header.Elements().ElementAt(0);

Check.That(tagsParagraph.ToString()).IsEqualTo(@"<p class=""tags"" xmlns=""http://www.w3.org/1999/xhtml"">Tags: <span>featureTag1</span>, <span>featureTag2</span>, <span>scenarioTag1</span>, <span>scenarioTag2</span></p>");
}
Expand Down Expand Up @@ -157,11 +157,11 @@ public void TagsAreRenderedAlphabetically()

Check.That(header.Elements().Count()).IsEqualTo(3);

Check.That(header.Elements().ElementAt(0)).IsNamed("h2");
Check.That(header.Elements().ElementAt(1)).IsNamed("p");
Check.That(header.Elements().ElementAt(0)).IsNamed("p");
Check.That(header.Elements().ElementAt(1)).IsNamed("h2");
Check.That(header.Elements().ElementAt(2)).IsNamed("div");

var tagsParagraph = header.Elements().ElementAt(1);
var tagsParagraph = header.Elements().ElementAt(0);

Check.That(tagsParagraph.ToString()).IsEqualTo(@"<p class=""tags"" xmlns=""http://www.w3.org/1999/xhtml"">Tags: <span>a</span>, <span>b</span>, <span>c</span>, <span>d</span></p>");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public XElement Format(Feature feature)
var div = new XElement(
this.xmlns + "div",
new XAttribute("id", "feature"),
this.htmlImageResultFormatter.Format(feature),
new XElement(this.xmlns + "h1", feature.Name));
this.htmlImageResultFormatter.Format(feature));

var tags = RetrieveTags(feature);
if (tags.Length > 0)
Expand All @@ -65,6 +64,8 @@ public XElement Format(Feature feature)
div.Add(paragraph);
}

div.Add(new XElement(this.xmlns + "h1", feature.Name));

div.Add(this.htmlDescriptionFormatter.Format(feature.Description));

var scenarios = new XElement(this.xmlns + "ul", new XAttribute("id", "scenarios"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public XElement Format(Scenario scenario, int id)
var header = new XElement(
this.xmlns + "div",
new XAttribute("class", "scenario-heading"),
string.IsNullOrEmpty(scenario.Slug) ? null : new XAttribute("id", scenario.Slug),
new XElement(this.xmlns + "h2", scenario.Name));
string.IsNullOrEmpty(scenario.Slug) ? null : new XAttribute("id", scenario.Slug));

var tags = RetrieveTags(scenario);
if (tags.Length > 0)
Expand All @@ -61,6 +60,8 @@ public XElement Format(Scenario scenario, int id)
header.Add(paragraph);
}

header.Add(new XElement(this.xmlns + "h2", scenario.Name));

header.Add(this.htmlDescriptionFormatter.Format(scenario.Description));

return new XElement(
Expand Down
Loading