|
| 1 | +describe('uiStateRef', function() { |
| 2 | + |
| 3 | + beforeEach(module('ui.state')); |
| 4 | + |
| 5 | + beforeEach(module(function($stateProvider) { |
| 6 | + $stateProvider.state('index', { |
| 7 | + url: '/' |
| 8 | + }).state('contacts', { |
| 9 | + url: '/contacts' |
| 10 | + }).state('contacts.item', { |
| 11 | + url: '/:id' |
| 12 | + }).state('contacts.item.detail', {}); |
| 13 | + })); |
| 14 | + |
| 15 | + describe('links', function() { |
| 16 | + var el, scope; |
| 17 | + |
| 18 | + beforeEach(inject(function($rootScope, $compile) { |
| 19 | + el = angular.element('<a ui-sref="contacts.item.detail({ id: contact.id })">Details</a>'); |
| 20 | + scope = $rootScope; |
| 21 | + scope.contact = { id: 5 }; |
| 22 | + scope.$apply(); |
| 23 | + |
| 24 | + $compile(el)(scope); |
| 25 | + scope.$digest(); |
| 26 | + })); |
| 27 | + |
| 28 | + |
| 29 | + it('should generate the correct href', function() { |
| 30 | + expect(el.attr('href')).toBe('/contacts/5'); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should update the href when parameters change', function() { |
| 34 | + expect(el.attr('href')).toBe('/contacts/5'); |
| 35 | + scope.contact.id = 6; |
| 36 | + scope.$apply(); |
| 37 | + expect(el.attr('href')).toBe('/contacts/6'); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should transition states when clicked', inject(function($state, $stateParams, $document, $q) { |
| 41 | + expect($state.$current.name).toEqual(''); |
| 42 | + |
| 43 | + var e = $document[0].createEvent("MouseEvents"); |
| 44 | + e.initMouseEvent("click"); |
| 45 | + el[0].dispatchEvent(e); |
| 46 | + |
| 47 | + $q.flush(); |
| 48 | + expect($state.current.name).toEqual('contacts.item.detail'); |
| 49 | + expect($stateParams).toEqual({ id: "5" }); |
| 50 | + })); |
| 51 | + }); |
| 52 | + |
| 53 | + describe('forms', function() { |
| 54 | + var el, scope; |
| 55 | + |
| 56 | + beforeEach(inject(function($rootScope, $compile) { |
| 57 | + el = angular.element('<form ui-sref="contacts.item.detail({ id: contact.id })"></form>'); |
| 58 | + scope = $rootScope; |
| 59 | + scope.contact = { id: 5 }; |
| 60 | + scope.$apply(); |
| 61 | + |
| 62 | + $compile(el)(scope); |
| 63 | + scope.$digest(); |
| 64 | + })); |
| 65 | + |
| 66 | + it('should generate the correct action', function() { |
| 67 | + expect(el.attr('action')).toBe('/contacts/5'); |
| 68 | + }); |
| 69 | + }); |
| 70 | +}); |
0 commit comments