JGiven icon indicating copy to clipboard operation
JGiven copied to clipboard

HTML5 Report: Introduce ordering of scenarios

Open clementheliou opened this issue 9 years ago • 15 comments

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.

clementheliou avatar Jun 19 '15 09:06 clementheliou

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.

janschaefer avatar Jun 19 '15 09:06 janschaefer

Issue #71 is somehow related to this one.

janschaefer avatar Jun 19 '15 10:06 janschaefer

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?

clementheliou avatar Jun 19 '15 11:06 clementheliou

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>

janschaefer avatar Jun 21 '15 10:06 janschaefer

Thanks. It looks promising, especially the "tags" and "group by" parts.

clementheliou avatar Jun 22 '15 07:06 clementheliou

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.

janschaefer avatar Jun 22 '15 10:06 janschaefer

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 ;)

clementheliou avatar Jun 22 '15 15:06 clementheliou

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.

janschaefer avatar Jun 22 '15 19:06 janschaefer

That could be a first solution. Let's give it a try!

clementheliou avatar Jun 23 '15 07:06 clementheliou

Ok :-)

janschaefer avatar Jun 23 '15 14:06 janschaefer

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'.

janschaefer avatar Jun 23 '15 20:06 janschaefer

Do you think I can close the issue?

janschaefer avatar Jun 26 '15 06:06 janschaefer

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?

clementheliou avatar Jun 26 '15 09:06 clementheliou

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 {
}

janschaefer avatar Jun 26 '15 11:06 janschaefer

Ok. That's nice!

clementheliou avatar Jun 26 '15 12:06 clementheliou