Skip to content

Commit 13a9da9

Browse files
author
Mattia Dal Ben
committed
Added ui.router dev dependency and pfVerticalNavigation with ui.router testing
1 parent dc335f3 commit 13a9da9

File tree

3 files changed

+111
-4
lines changed

3 files changed

+111
-4
lines changed

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"patternfly": "~3.14.0"
4646
},
4747
"devDependencies": {
48-
"angular-mocks": "1.3.0 - 1.5.*"
48+
"angular-mocks": "1.3.0 - 1.5.*",
49+
"angular-ui-router": "^0.3.2"
4950
}
5051
}

test/karma.conf.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ module.exports = function(config) {
2828
'test/utils/*.js',
2929
'test/wizard/script.js',
3030
'test/**/*.spec.js',
31-
'test/**/*.html'
31+
'test/**/*.html',
32+
'lib/angular-ui-router/release/angular-ui-router.min.js'
3233
],
3334

3435
// list of files to exclude
@@ -93,6 +94,8 @@ module.exports = function(config) {
9394

9495
// report which specs are slower than 500ms
9596
// CLI --report-slower-than 500
96-
reportSlowerThan: 500
97+
reportSlowerThan: 500,
98+
99+
transport: ['websocket', 'polling']
97100
});
98101
};

test/navigation/vertical-navigation.spec.js

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('Directive: pfVerticalNavigation', function () {
3232
{
3333
title: "Dolor",
3434
iconClass : "fa fa-shield",
35-
href: "#/dolor",
35+
uiSref: "dolor",
3636
badges: [
3737
{
3838
count: 1283,
@@ -691,4 +691,107 @@ describe('Directive: pfVerticalNavigation', function () {
691691
expect(badgesShown.length).toBe(0);
692692
});
693693

694+
it('should throw and error if uiSref is used when $state is undefined', function () {
695+
var wellDefinedItem = element.find('.nav-pf-vertical > .list-group > .list-group-item:nth-child(2) > a');
696+
expect(function() {
697+
wellDefinedItem.click();
698+
}).toThrow(new Error("uiSref is defined on item, but no $state has been injected. Did you declare a dependency on \"ui.router\" module in your app?"));
699+
});
694700
});
701+
702+
703+
describe('Directive: pfVerticalNavigation with ui.router', function () {
704+
var $state;
705+
var $scope;
706+
var $compile;
707+
var element;
708+
var isolateScope;
709+
710+
// load the controller's module
711+
beforeEach(function () {
712+
module('patternfly.navigation', 'patternfly.utils', 'navigation/vertical-navigation.html');
713+
});
714+
715+
beforeEach(module('ui.router'));
716+
717+
beforeEach(inject(function (_$compile_, _$rootScope_, _$state_) {
718+
$compile = _$compile_;
719+
$scope = _$rootScope_;
720+
$state = _$state_;
721+
722+
spyOn($state, 'go');
723+
}));
724+
725+
var compileHTML = function (markup, scope) {
726+
element = angular.element(markup);
727+
$compile(element)(scope);
728+
729+
scope.$digest();
730+
isolateScope = element.isolateScope();
731+
};
732+
733+
beforeEach(function () {
734+
$scope.navigationItems = [
735+
{
736+
title: "Dashboard",
737+
iconClass: "fa fa-dashboard",
738+
uiSref: 'dashboard',
739+
uiSrefOptions: 'testing'
740+
},
741+
{
742+
title: "Dolor",
743+
iconClass : "fa fa-shield",
744+
href: "#/dolor",
745+
uiSref: 'dolor',
746+
badges: [
747+
{
748+
count: 1283,
749+
tooltip: "Total number of items"
750+
}
751+
]
752+
}
753+
];
754+
755+
$scope.handleNavigateClick = function (item) {
756+
$scope.navigateItem = item.title;
757+
};
758+
759+
$scope.handleItemClick = function (item) {
760+
$scope.clickItem = item.title;
761+
};
762+
763+
var htmlTmp = '' +
764+
'<div id="verticalNavLayout" class="layout-pf layout-pf-fixed">' +
765+
' <div pf-vertical-navigation items="navigationItems" brand-src="images/test.svg" brand-alt="ANGULAR PATTERNFLY"' +
766+
' show-badges="true" pinnable-menus="true" update-active-items-on-click="true"' +
767+
' navigate-callback="handleNavigateClick" item-click-callback="handleItemClick"' +
768+
' ignore-mobile="true"' +
769+
' <div>' +
770+
' <div class="test-included-content"></div>' +
771+
' </div>' +
772+
' </div>' +
773+
' <div id="contentContainer" class="container-pf-nav-pf-vertical">' +
774+
' </div>' +
775+
' </div>' +
776+
'';
777+
778+
compileHTML(htmlTmp, $scope);
779+
});
780+
781+
it('should trigger the $state.go() function when an item with ui-sref defined is clicked', function () {
782+
var wellDefinedItem = element.find('.nav-pf-vertical > .list-group > .list-group-item:nth-child(1) > a');
783+
784+
// Click dashboard item
785+
wellDefinedItem.click();
786+
787+
expect($state.go).toHaveBeenCalledWith('dashboard','testing');
788+
});
789+
790+
it('should throw and error if both uiSref and href are used on an item', function () {
791+
var badDefinedItem = element.find('.nav-pf-vertical > .list-group > .list-group-item:nth-child(2) > a');
792+
793+
expect( function() {
794+
badDefinedItem.click();
795+
}).toThrow(new Error('Using both uiSref and href on an item is not supported.'));
796+
});
797+
});

0 commit comments

Comments
 (0)