|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +describe('navbar', function () { |
| 4 | + var scope, $sandbox, $compile, $timeout, $location; |
| 5 | + |
| 6 | + beforeEach(module('$strap.directives')); |
| 7 | + |
| 8 | + beforeEach(inject(function ($injector, $rootScope, _$compile_, _$timeout_, _$location_) { |
| 9 | + scope = $rootScope; |
| 10 | + $compile = _$compile_; |
| 11 | + $timeout = _$timeout_; |
| 12 | + $location = _$location_; |
| 13 | + |
| 14 | + $sandbox = $('<div id="sandbox"></div>').appendTo($('body')); |
| 15 | + })); |
| 16 | + |
| 17 | + afterEach(function() { |
| 18 | + $sandbox.remove(); |
| 19 | + scope.$destroy(); |
| 20 | + }); |
| 21 | + |
| 22 | + var templates = { |
| 23 | + 'default': '<nav class="navbar" bs-navbar><ul class="nav"><li data-match-route="/network.*"><a href="#/network">Network</a></li><li data-match-route="/profile.*"><a href="#/profile">Profile</a></li></ul></nav>' |
| 24 | + }; |
| 25 | + |
| 26 | + function compileDirective(template) { |
| 27 | + template = template ? templates[template] : templates['default']; |
| 28 | + template = $(template).appendTo($sandbox); |
| 29 | + return $compile(template)(scope); |
| 30 | + } |
| 31 | + |
| 32 | + // Tests |
| 33 | + |
| 34 | + it('should toggle "active" class for you', function () { |
| 35 | + var elm = compileDirective(); |
| 36 | + $location.path('/network'); scope.$digest(); |
| 37 | + expect(elm.find('li:nth-child(1)').hasClass('active')).toBe(true); |
| 38 | + $location.path('/profile'); scope.$digest(); |
| 39 | + expect(elm.find('li:nth-child(1)').hasClass('active')).toBe(false); |
| 40 | + expect(elm.find('li:nth-child(2)').hasClass('active')).toBe(true); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should work with regular expressions', function () { |
| 44 | + var elm = compileDirective(); |
| 45 | + $location.path('/network'); scope.$digest(); |
| 46 | + expect(elm.find('li:first').hasClass('active')).toBe(true); |
| 47 | + $location.path('/network/config'); scope.$digest(); |
| 48 | + expect(elm.find('li:first').hasClass('active')).toBe(true); |
| 49 | + }); |
| 50 | + |
| 51 | +}); |
0 commit comments