JGiven
JGiven copied to clipboard
HTML5 Report: Introduce ordering of scenarios
We may have quite a few scenarios for a given tag. Currently, they are sorted using alphabetical ordering.
It could be useful to think about a mechanism allowing us to control the ordering used by report generation. The simplest solution probably is to annotate each scenario with its order but we could also think about other strategies.
Yes. That is a very good point. I already thought about that issue and didn't come up with a good solution yet, so I would be very happy about suggestions. I would like to avoid additional annotations if possible.
Issue #71 is somehow related to this one.
I agree that this feature is not trivial.
Main issue is that a scenario can be related to many tags and its position may depends on the selected tag. We would need an order by tag, indeed an order for each tag combination!
I confess that I do not have the solution. Maybe can we find inspiration from others similar tools?
I finished a first implementation for grouping, sorting, and filtering. It is tracked now by PR #81. There is a live demo here: http://jgiven.org/snapshot/jgiven-report/html5/#/all
If you want to test it on your project you can use v0.8.0-SNAPSHOT. You have to add the following snapshot repository to Maven/Gradle in order to get the SNAPSHOT version: https://oss.sonatype.org/content/repositories/snapshots
Alternatively you can just checkout the html5-app-sorting
branch and just copy the content of the jgiven-html5-report/src/app
folder into your generated html5 report folder:
cp -r jgiven-html5-report/src/app/* <your-html5-report-dir>
Thanks. It looks promising, especially the "tags" and "group by" parts.
So do you think that this is enough for your use case? What I could add in addition would an option to sort by a tag. Then you could put tag-annotations on scenarios to define a certain order.
This is a great improvement for the issue #80 use case. But it's not enough for the ordering one. Anyway, I don't think there is a trivial solution. One has to found a solution managing multi-tags combination.
Over a first phase, I'll see if the grouping capabilities are enough to deal with our scenarios. I'll let you know if we need to found another solution.
Thanks for your great job ;)
Ok. So I think a first easy solution would be to allow ordering by tags with values. For example, if you have a tag Issue
that takes a string as a value. It would be easy to implement something like Sort By Issue. The sorting would then just take the value of the tag and use this for sorting.
This, however, only works if the value itself can be used for sorting. This should be true for most cases that I can think of. In addition, it would allow you to define an annotation Priority
that takes a value that is then used for sorting.
That could be a first solution. Let's give it a try!
Ok :-)
I have implemented the sorting by tag. Its available with v0.8.0-SNAPSHOT. You can try it also out at http://jgiven.org/snapshot/jgiven-report/html5/#/all and 'Sort By -> Issue'.
Do you think I can close the issue?
I would keep it open as we only have a partial solution. ;)
By the way, the sort by tag option could probably be improved. Let's say I defined an Order tag with an Integer value. Then I can use the sort by tag option to sort my scenarios.
But these tags are displayed anyway and they are like boilerplate around my scenarios. Could we have an option to hide them?
Actually you can do that already by using the cssClass
attribute of the @IsTag
annotation. For example you can define:
.tag.hidden {
display: none;
}
in a custom.css
file and then write:
@IsTag( cssClass="hidden" )
@Retention( RetentionPolicy.RUNTIME )
public @interface Order {
}
Ok. That's nice!