Skip to content

Commit 1e36db6

Browse files
author
Mattia Dal Ben
committed
Added pfVerticalNavigation state change unit test
1 parent 13a9da9 commit 1e36db6

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

test/navigation/vertical-navigation.spec.js

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,26 @@ describe('Directive: pfVerticalNavigation', function () {
701701

702702

703703
describe('Directive: pfVerticalNavigation with ui.router', function () {
704+
// Setting up some dummy controllers and some dummy states
705+
angular.module('mockApp', ['ui.router'])
706+
.controller('Controller0', function() {
707+
this.message = 'Page 0';
708+
}).controller('Controller1', function() {
709+
this.message = 'Page 1';
710+
}).config(function($stateProvider, $urlRouterProvider) {
711+
$urlRouterProvider.otherwise("/state0");
712+
713+
$stateProvider.state('state0', {
714+
url: "/state0",
715+
controller: 'Controller0',
716+
controllerAs: 'vm'
717+
}).state('state1', {
718+
url: "/state1",
719+
controller: 'Controller1',
720+
controllerAs: 'vm'
721+
});
722+
});
723+
704724
var $state;
705725
var $scope;
706726
var $compile;
@@ -712,14 +732,14 @@ describe('Directive: pfVerticalNavigation with ui.router', function () {
712732
module('patternfly.navigation', 'patternfly.utils', 'navigation/vertical-navigation.html');
713733
});
714734

715-
beforeEach(module('ui.router'));
735+
beforeEach(module('mockApp'));
716736

717737
beforeEach(inject(function (_$compile_, _$rootScope_, _$state_) {
718738
$compile = _$compile_;
719739
$scope = _$rootScope_;
720740
$state = _$state_;
721741

722-
spyOn($state, 'go');
742+
spyOn($state, 'go').and.callThrough();
723743
}));
724744

725745
var compileHTML = function (markup, scope) {
@@ -735,14 +755,14 @@ describe('Directive: pfVerticalNavigation with ui.router', function () {
735755
{
736756
title: "Dashboard",
737757
iconClass: "fa fa-dashboard",
738-
uiSref: 'dashboard',
758+
uiSref: 'state1',
739759
uiSrefOptions: 'testing'
740760
},
741761
{
742762
title: "Dolor",
743763
iconClass : "fa fa-shield",
744-
href: "#/dolor",
745-
uiSref: 'dolor',
764+
href: "#/state2",
765+
uiSref: 'state2',
746766
badges: [
747767
{
748768
count: 1283,
@@ -781,10 +801,16 @@ describe('Directive: pfVerticalNavigation with ui.router', function () {
781801
it('should trigger the $state.go() function when an item with ui-sref defined is clicked', function () {
782802
var wellDefinedItem = element.find('.nav-pf-vertical > .list-group > .list-group-item:nth-child(1) > a');
783803

804+
expect($state.current.name).toBe("state0");
805+
784806
// Click dashboard item
785807
wellDefinedItem.click();
786-
787-
expect($state.go).toHaveBeenCalledWith('dashboard','testing');
808+
809+
expect($state.go).toHaveBeenCalledWith('state1','testing');
810+
811+
// Checking successful state transition
812+
expect($state.current.name).toBe("state1");
813+
expect($state.current.controller).toBe("Controller1");
788814
});
789815

790816
it('should throw and error if both uiSref and href are used on an item', function () {
@@ -794,4 +820,5 @@ describe('Directive: pfVerticalNavigation with ui.router', function () {
794820
badDefinedItem.click();
795821
}).toThrow(new Error('Using both uiSref and href on an item is not supported.'));
796822
});
797-
});
823+
});
824+

0 commit comments

Comments
 (0)