Skip to content

Commit 5bc93a2

Browse files
committed
uiBreadcrumbs: Added tests for proxy state locals.
1 parent 7566372 commit 5bc93a2

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/directives/uiBreadcrumbs/uiBreadcrumbs.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@
8888
proxyStateName = getObjectValue(scope.abstractProxyProperty, currentState);
8989
if (proxyStateName) {
9090
workingState = angular.copy($state.get(proxyStateName));
91-
workingState.locals = currentState.locals;
91+
if (workingState) {
92+
workingState.locals = currentState.locals;
93+
}
9294
} else {
9395
workingState = false;
9496
}

src/directives/uiBreadcrumbs/uiBreadcrumbs.spec.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,30 @@ describe('uiBreadcrumbs directive', function() {
9696
data: {
9797
displayName: 'A Thing'
9898
}
99+
})
100+
.state( 'root.project', {
101+
abstract: true,
102+
url: 'abstract2/',
103+
data: {
104+
breadcrumbProxy: 'root.project.dashboard'
105+
},
106+
resolve: {
107+
resolvedName: function(){
108+
return "Project";
109+
}
110+
}
111+
})
112+
.state( 'root.project.dashboard', {
113+
url: 'dashboard/',
114+
data: {
115+
displayName: '{{ resolvedName }} Dashboard'
116+
}
117+
})
118+
.state( 'root.project.tasks', {
119+
url: 'list/',
120+
data: {
121+
displayName: '{{ resolvedName }} Tasks'
122+
}
99123
});
100124
});
101125
module('mockModule');
@@ -236,4 +260,16 @@ describe('uiBreadcrumbs directive', function() {
236260
expect(element2[0].querySelectorAll('li').length).toBe(2);
237261
});
238262

239-
});
263+
it('should use resolved variables for abstract state proxy', function() {
264+
var element2 = $compile('<ui-breadcrumbs displayname-property="data.displayName" abstract-proxy-property="data.breadcrumbProxy"></ui-breadcrumbs>')($scope);
265+
$state.go('root.project.tasks');
266+
$scope.$apply();
267+
268+
expect(element2[0].querySelectorAll('li')[0].innerHTML).toContain('Home');
269+
expect(element2[0].querySelectorAll('li')[1].innerHTML).toContain('Project Dashboard');
270+
expect(element2[0].querySelectorAll('li')[2].innerHTML).toContain('Project Tasks');
271+
expect(element2[0].querySelectorAll('li')[3]).not.toBeDefined();
272+
expect(element2[0].querySelectorAll('li').length).toBe(3);
273+
});
274+
275+
});

0 commit comments

Comments
 (0)