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

Basic comments handling #311

Merged
merged 13 commits into from
Apr 10, 2016
16 changes: 16 additions & 0 deletions src/Pickles/Pickles.BaseDhtmlFiles/Index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,27 @@

<script type="text/html" id="steps-template">
<li class="step">
<!-- ko if: StepComments != null && StepComments.length > 0 -->
<span class="comment">
<!-- ko foreach: StepComments -->
<span data-bind="text: Text"></span>
<br data-bind="visible : $index() != ($parent.length-1)" />
<!-- /ko -->
</span>
<!-- /ko -->
<span class="keyword" data-bind="text: NativeKeyword"></span><span data-bind="text: Name"></span>
<div data-bind="if: DocStringArgument != ''">
<div data-bind="text: DocStringArgument" class="pre"></div>
</div>
<div data-bind="template: { name: 'table-template', data: $data.TableArgument }"></div>
<!-- ko if: AfterLastStepComments != null && AfterLastStepComments.length > 0 -->
<span class="comment">
<!-- ko foreach: AfterLastStepComments -->
<span data-bind="text: Text"></span>
<br data-bind="visible : $index() != ($parent.length-1)" />
<!-- /ko -->
</span>
<!-- /ko -->
</li>
</script>

Expand Down
5 changes: 5 additions & 0 deletions src/Pickles/Pickles.BaseDhtmlFiles/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ li.step {
padding: 0;
}

.comment {
font-weight: bold;
color: #0088CC;
}

.keyword {
font-weight: bold;
color: #0000FF;
Expand Down
6 changes: 6 additions & 0 deletions src/Pickles/Pickles.BaseDhtmlFiles/js/featuresModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ function Step(data) {
this.NativeKeyword = data.NativeKeyword || '';
this.DocStringArgument = data.DocStringArgument || '';
this.TableArgument = data.TableArgument == null ? null : new TableArgument(data.TableArgument.HeaderRow, data.TableArgument.DataRows);
this.StepComments = data.StepComments == null ? null : $.map(data.StepComments, function (c) { return new Comment(c); });
this.AfterLastStepComments = data.AfterLastStepComments == null ? null : $.map(data.AfterLastStepComments, function (c) { return new Comment(c); });
}

function Comment(data) {
this.Text = data.Text || '';
}

function TableArgument(headerRow, dataRows) {
Expand Down
48 changes: 48 additions & 0 deletions src/Pickles/Pickles.ObjectModel/ObjectModel/Comment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Table.cs" company="PicklesDoc">
// Copyright 2011 Jeffrey Cameron
// Copyright 2012-present PicklesDoc team and community contributors
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using System.Collections.Generic;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove the unused using


namespace PicklesDoc.Pickles.ObjectModel
{
public enum CommentType
{
Normal,
StepComment,
AfterLastStepComment
}

public class Comment
{
public Comment()
{
// Set default
this.Type = CommentType.Normal;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line contains whitespace, please remove it

public string Text { get; set; }

public Location Location { get; set; }

public CommentType Type { get; set; }

public Step Step { get; set; }
}
}
3 changes: 3 additions & 0 deletions src/Pickles/Pickles.ObjectModel/ObjectModel/Feature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class Feature
public Feature()
{
this.FeatureElements = new List<IFeatureElement>();
this.Comments = new List<Comment>();
this.Tags = new List<string>();
}

Expand All @@ -36,6 +37,8 @@ public Feature()

public List<IFeatureElement> FeatureElements { get; }

public List<Comment> Comments { get; }

public Scenario Background { get; private set; }

public TestResult Result { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ public interface IFeatureElement
List<string> Tags { get; set; }

TestResult Result { get; set; }

Location Location { get; set; }
}
}
31 changes: 31 additions & 0 deletions src/Pickles/Pickles.ObjectModel/ObjectModel/Location.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Table.cs" company="PicklesDoc">
// Copyright 2011 Jeffrey Cameron
// Copyright 2012-present PicklesDoc team and community contributors
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using System.Collections.Generic;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the unused using.


namespace PicklesDoc.Pickles.ObjectModel
{
public class Location
{
public int Column { get; set; }

public int Line { get; set; }
}
}
2 changes: 2 additions & 0 deletions src/Pickles/Pickles.ObjectModel/ObjectModel/Scenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public Scenario()

public Feature Feature { get; set; }

public Location Location { get; set; }

#endregion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not strictly your code, but do me a favour and remove the #region from the class. Thanks!

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@ public ScenarioOutline()
public TestResult Result { get; set; }

public Feature Feature { get; set; }

public Location Location { get; set; }
}
}
11 changes: 11 additions & 0 deletions src/Pickles/Pickles.ObjectModel/ObjectModel/Step.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using System.Collections.Generic;

namespace PicklesDoc.Pickles.ObjectModel
{
public class Step
{
public Step()
{
this.Comments = new List<Comment>();
}

public Keyword Keyword { get; set; }

public string NativeKeyword { get; set; }
Expand All @@ -31,5 +38,9 @@ public class Step
public Table TableArgument { get; set; }

public string DocStringArgument { get; set; }

public Location Location { get; set; }

public List<Comment> Comments { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the extra whitespace at the end of the Comments { get; set; } line

}
}
2 changes: 2 additions & 0 deletions src/Pickles/Pickles.ObjectModel/Pickles.ObjectModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<ItemGroup>
<Compile Include="DocumentationFormat.cs" />
<Compile Include="IConfiguration.cs" />
<Compile Include="ObjectModel\Location.cs" />
<Compile Include="ObjectModel\Example.cs" />
<Compile Include="ObjectModel\Feature.cs" />
<Compile Include="ObjectModel\IFeatureElement.cs" />
Expand All @@ -54,6 +55,7 @@
<Compile Include="ObjectModel\Scenario.cs" />
<Compile Include="ObjectModel\ScenarioOutline.cs" />
<Compile Include="ObjectModel\Step.cs" />
<Compile Include="ObjectModel\Comment.cs" />
<Compile Include="ObjectModel\Table.cs" />
<Compile Include="ObjectModel\TableRow.cs" />
<Compile Include="ObjectModel\TestResult.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// --------------------------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using Autofac;
using ClosedXML.Excel;
using NFluent;
Expand Down Expand Up @@ -47,5 +49,107 @@ public void ThenStepAddedSuccessfully()
Check.That(worksheet.Cell("D5").Value).IsEqualTo(step.Name);
}
}

[Test]
public void ThenStepCommentsAreAddedSuccesfully()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully is spelled with three s in total :-)

{
var excelStepFormatter = Container.Resolve<ExcelStepFormatter>();
var step = new Step
{
NativeKeyword = "Given",
Name = "I have some precondition",
Comments = new List<Comment>()
{
new Comment()
{
Text = "# A comment",
Type = CommentType.StepComment
}
}
};

using (var workbook = new XLWorkbook())
{
IXLWorksheet worksheet = workbook.AddWorksheet("SHEET1");
int row = 5;
excelStepFormatter.Format(worksheet, step, ref row);

Check.That(worksheet.Cell("C5").Value).IsEqualTo(step.Comments.First().Text);
Check.That(worksheet.Cell("C6").Value).IsEqualTo(step.NativeKeyword);
Check.That(worksheet.Cell("D6").Value).IsEqualTo(step.Name);
}
}

[Test]
public void ThenMultilineStepCommentsAreAddedSuccesfully()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully is spelled with three s in total :-)

{
var excelStepFormatter = Container.Resolve<ExcelStepFormatter>();
var step = new Step
{
NativeKeyword = "Given",
Name = "I have some precondition",
Comments = new List<Comment>()
{
new Comment()
{
Text = "# A comment - line 1",
Type = CommentType.StepComment
},
new Comment()
{
Text = "# A comment - line 2",
Type = CommentType.StepComment
}
}
};

using (var workbook = new XLWorkbook())
{
IXLWorksheet worksheet = workbook.AddWorksheet("SHEET1");
int row = 5;
excelStepFormatter.Format(worksheet, step, ref row);

Check.That(worksheet.Cell("C5").Value).IsEqualTo(step.Comments[0].Text);
Check.That(worksheet.Cell("C6").Value).IsEqualTo(step.Comments[1].Text);
Check.That(worksheet.Cell("C7").Value).IsEqualTo(step.NativeKeyword);
Check.That(worksheet.Cell("D7").Value).IsEqualTo(step.Name);
}
}

[Test]
public void ThenCommentsAfterTheLastStepAreAddedSuccesfully()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully is spelled with three s in total :-)

{
var excelStepFormatter = Container.Resolve<ExcelStepFormatter>();
var step = new Step
{
NativeKeyword = "Given",
Name = "I have some precondition",
Comments = new List<Comment>()
{
new Comment()
{
Text = "# A comment",
Type = CommentType.StepComment
},
new Comment()
{
Text = "# A comment the last step",
Type = CommentType.AfterLastStepComment
}
}
};

using (var workbook = new XLWorkbook())
{
IXLWorksheet worksheet = workbook.AddWorksheet("SHEET1");
int row = 5;
excelStepFormatter.Format(worksheet, step, ref row);

Check.That(worksheet.Cell("C5").Value).IsEqualTo(step.Comments.First(o => o.Type == CommentType.StepComment).Text);
Check.That(worksheet.Cell("C6").Value).IsEqualTo(step.NativeKeyword);
Check.That(worksheet.Cell("D6").Value).IsEqualTo(step.Name);
Check.That(worksheet.Cell("C7").Value).IsEqualTo(step.Comments.First(o => o.Type == CommentType.AfterLastStepComment).Text);
}
}
}
}
Loading