@@ -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