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

HTML5 Report: package navigation tree #91

Merged
merged 4 commits into from
Jul 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

* Introduced the `@As` annotation that replaces the `@Description` annotation when used on step methods and test methods. The `@Description` annotation should only be used for descriptions of test classes.

## New Features

### HTML5 Report

* Classes are shown now in hierarchical navigation tree and scenarios can be listed by package [#91](https://github.com/TNG/JGiven/pull/91)

# v0.7.3

## Fixed Issues
Expand Down
108 changes: 83 additions & 25 deletions jgiven-html5-report/src/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ jgivenReportApp.filter('encodeUri', function ($window) {
jgivenReportApp.controller('JGivenReportCtrl', function ($scope, $rootScope, $timeout, $sanitize, $location, $window, localStorageService) {
$scope.scenarios = [];
$scope.classNameScenarioMap = {};
$scope.classNames;
$scope.rootPackage = { packages: [] };
$scope.packageMap = {};
$scope.tagScenarioMap = {}; // lazy calculated by getTags()
$scope.allTags;
$scope.tags;
Expand All @@ -25,7 +26,7 @@ jgivenReportApp.controller('JGivenReportCtrl', function ($scope, $rootScope, $ti
$scope.bookmarks = [];

$scope.init = function() {
$scope.classNames = getClassNames();
$scope.rootPackage = getRootPackage();
$scope.allTags = groupTagsByType(getTags());
$scope.tags = $scope.allTags;

Expand Down Expand Up @@ -69,6 +70,8 @@ jgivenReportApp.controller('JGivenReportCtrl', function ($scope, $rootScope, $ti
$scope.updateCurrentPageToTag( tag, selectedOptions );
} else if (part[1] === 'class') {
$scope.updateCurrentPageToClassName(part[2], selectedOptions);
} else if (part[1] === 'package') {
$scope.updateCurrentPageToPackage( part[2], selectedOptions);
} else if (part[1] === 'scenario') {
$scope.showScenario(part[2],part[3], selectedOptions);
} else if (part[1] === 'all') {
Expand Down Expand Up @@ -135,6 +138,15 @@ jgivenReportApp.controller('JGivenReportCtrl', function ($scope, $rootScope, $ti
return -1;
}

$scope.togglePackage = function togglePackage( packageObj ) {
packageObj.expanded = !packageObj.expanded

// recursively open all packages that only have a single subpackage
if (packageObj.classes.length === 0 && packageObj.packages.length === 1) {
togglePackage( packageObj.packages[0]);
}
}

$scope.currentPath = function() {
return $location.path();
}
Expand All @@ -143,6 +155,35 @@ jgivenReportApp.controller('JGivenReportCtrl', function ($scope, $rootScope, $ti
$scope.updateCurrentPageToTestCase( $scope.classNameScenarioMap[className], options );
}

$scope.updateCurrentPageToPackage = function(packageName, options) {
$scope.currentPage = {
scenarios: [],
subtitle: "Package",
title: packageName,
breadcrumbs: packageName.split("."),
loading: true
};
$timeout(function() {
var packageObj = $scope.packageMap[ packageName ];
var scenarios = [];
collectScenariosFromPackage( packageObj, scenarios );
$scope.currentPage.scenarios = scenarios;
$scope.currentPage.loading = false;
$scope.currentPage.options = getOptions($scope.currentPage.scenarios, options);
$scope.applyOptions();
}, 0);
}

function collectScenariosFromPackage( packageObj, scenarios ) {
_.forEach( packageObj.classes, function( clazz ) {
scenarios.pushArray( $scope.classNameScenarioMap[clazz.packageName + "." + clazz.className].scenarios );
});

_.forEach( packageObj.packages, function ( subpackage ) {
collectScenariosFromPackage( subpackage, scenarios );
});
}

$scope.updateCurrentPageToTestCase = function (testCase, options) {
var className = splitClassName(testCase.className);
var scenarios = sortByDescription(testCase.scenarios);
Expand Down Expand Up @@ -341,22 +382,6 @@ jgivenReportApp.controller('JGivenReportCtrl', function ($scope, $rootScope, $ti
} ));
}

$scope.updateNav = function() {
$scope.classNames = _.filter(getClassNames(), function(x) {
if ($scope.nav.search) {
return x.className.match( new RegExp($scope.nav.search, "i"));
}
return true;
});

$scope.tags = _.filter($scope.allTags, function(x) {
if ($scope.nav.search) {
return (x.name + '-' + x.value).match( new RegExp($scope.nav.search, "i") );
}
return true;
});
};

$scope.printCurrentPage = function printCurrentPage() {
$location.search("print",true);
$timeout(printPage,0);
Expand Down Expand Up @@ -572,16 +597,46 @@ jgivenReportApp.controller('JGivenReportCtrl', function ($scope, $rootScope, $ti
return scenarios;
}

function getClassNames() {
var res = new Array();
function getRootPackage() {
var allScenarios = jgivenReport.scenarios;
var packageMap = {}; // maps full qualified package name to package object
var rootPackage = getPackage("");
var classObj;

for (var i = 0; i < allScenarios.length; i++ ) {
var className = splitClassName( allScenarios[i].className );
className.index = i;
res.push(className);
classObj = splitClassName( allScenarios[i].className );
classObj.index = i;
$scope.classNameScenarioMap[allScenarios[i].className] = allScenarios[i];

getPackage( classObj.packageName).classes.push(classObj);

}
$scope.packageMap = packageMap;

return rootPackage;

function getPackage( packageName ) {
var parentPackage, index, simpleName;
var packageObj = packageMap[ packageName ];
if (packageObj === undefined) {
index = packageName.lastIndexOf('.');
simpleName = packageName.substr(index + 1);

packageObj = {
qualifiedName: packageName,
name: simpleName,
classes: [],
packages: []
}
packageMap[ packageName ] = packageObj;

if (simpleName !== "") {
parentPackage = getPackage(packageName.substring(0, index));
parentPackage.packages.push(packageObj);
}
}
return packageObj;
}
return _.sortBy( res, function(x) { return x.className; });
}

function getTagKey(tag) {
Expand Down Expand Up @@ -1027,8 +1082,11 @@ jgivenReportApp.controller('SummaryCtrl', function ($scope) {

String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
}
};

Array.prototype.pushArray = function(arr) {
this.push.apply(this, arr);
};

function splitClassName( fullQualifiedClassName ) {
var index = fullQualifiedClassName.lastIndexOf('.');
Expand Down
56 changes: 47 additions & 9 deletions jgiven-html5-report/src/app/css/jgivenreport.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ h5 {
}


ul.tags {
list-style: none;
}

.tag.hidden {
display: none;
}
Expand Down Expand Up @@ -445,17 +441,20 @@ body, .footer-bottom {
width: 25rem;
}

ul.tags {
list-style: none;
margin-left: 0.8rem;
}

.side-nav li a:not(.button){
padding: 0.5rem 1.8rem;
}

.side-nav li li a:not(.button){
padding: 0.1rem 1.9rem;
padding-top: 0.1rem;
padding-bottom: 0.1rem;
}

.side-nav li li li a:not(.button){
padding: 0.1rem 3.3rem;
}

.side-nav, .side-nav ul {
line-height: 1.2;
Expand All @@ -466,6 +465,11 @@ body, .footer-bottom {
margin-left: 0;
}

.side-nav ul ul {
margin-left: 0.8rem;
margin-top: 0.3rem;
}

li.heading {
margin-top: 0.5rem;
}
Expand All @@ -487,7 +491,41 @@ li.subheading {
li.subheading > ul {
padding-top: 0.5rem;
padding-left: 0rem;
margin-left: 0;
margin-left: 1.3rem;
margin-top: 0;
}

.open-package-icon {
color: #eee;
}

div.package-node {
position: relative;
}

div.package-node:hover .open-package-icon {
color: inherit;
}

div.package-node:hover {
background-color: #eee;
}


a.show-package-link {
display: inline !important;
position: absolute;
right: 1.8rem;
top: 0;
padding: 0 !important;
}

div.package-node:hover a {
background: none !important;
}

a.show-package-link:hover {
background: none !important;
}

.footer-bottom {
Expand Down
26 changes: 23 additions & 3 deletions jgiven-html5-report/src/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,28 @@
</head>
<body ng-controller="JGivenReportCtrl as appCtrl">


<!-- Package Tree Template -->

<script type="text/ng-template" id="package_tree.html">
<div class="package-node" >
<a ng-click="togglePackage(package)" >
<i class="fa fa-caret-right toggle {{package.expanded ? 'fa-rotate-90' : ''}}"></i>
&nbsp;{{package.name}}
</a>
<a href="#package/{{package.qualifiedName}}" class="show-package-link">
<i class="fa fa-chevron-circle-right open-package-icon"></i>
</a>
</div>
<ul ng-if="package.expanded">
<li ng-repeat="clazz in package.classes"><a href="#class/{{clazz.packageName + '.' + clazz.className}}">
&nbsp;{{clazz.className}}
</a></li>
<li ng-repeat="package in package.packages" ng-include="'package_tree.html'"></li>
</ul>
</script>


<div class="off-canvas-wrap" data-offcanvas>

<div class="inner-wrap">
Expand Down Expand Up @@ -144,9 +166,7 @@ <h1 class="title">JGiven Report</h1>
<li class="heading" >
<a class="toggle" ng-click="classNames.expanded = !classNames.expanded">Classes</a>
<ul ng-if="classNames.expanded" >
<li ng-repeat="className in classNames"><a href="#class/{{className.packageName + '.' + className.className}}">
{{className.className}}
</a></li>
<li ng-repeat="package in rootPackage.packages" ng-include="'package_tree.html'"></li>
</ul>
</li>

Expand Down