|
1 | 1 | import * as angular from 'angular';
|
2 |
| -import './util/matchers'; |
| 2 | +import { ICompileService, IRootScopeService } from 'angular'; |
3 | 3 | import { extend } from '@uirouter/core';
|
| 4 | +import './util/matchers'; |
4 | 5 |
|
5 | 6 | declare let inject, jasmine;
|
6 | 7 |
|
@@ -1061,7 +1062,12 @@ describe('angular 1.5+ style .component()', function() {
|
1061 | 1062 | });
|
1062 | 1063 |
|
1063 | 1064 | app.component('dynamicComponent', {
|
1064 |
| - template: 'dynamicComponent', |
| 1065 | + template: 'dynamicComponent {{ $ctrl.param }}', |
| 1066 | + controller: function() { |
| 1067 | + this.uiOnParamsChanged = function(params) { |
| 1068 | + this.param = params.param; |
| 1069 | + }; |
| 1070 | + }, |
1065 | 1071 | });
|
1066 | 1072 | }
|
1067 | 1073 | });
|
@@ -1796,8 +1802,60 @@ describe('angular 1.5+ style .component()', function() {
|
1796 | 1802 | const directiveEl = el[0].querySelector('div ui-view dynamic-component');
|
1797 | 1803 | expect(directiveEl).toBeDefined();
|
1798 | 1804 | expect($state.current.name).toBe('dynamicComponent');
|
1799 |
| - expect(el.text()).toBe('dynamicComponent'); |
| 1805 | + expect(el.text().trim()).toBe('dynamicComponent'); |
1800 | 1806 | });
|
1801 | 1807 | }
|
1802 | 1808 | });
|
| 1809 | + |
| 1810 | + if (angular.version.minor >= 5) { |
| 1811 | + describe('uiOnParamsChanged()', () => { |
| 1812 | + let param; |
| 1813 | + |
| 1814 | + beforeEach(inject(($rootScope: IRootScopeService, $compile: ICompileService) => { |
| 1815 | + param = null; |
| 1816 | + |
| 1817 | + $stateProvider.state('dynamic', { |
| 1818 | + url: '/dynamic/:param', |
| 1819 | + component: 'dynamicComponent', |
| 1820 | + params: { param: { dynamic: true } }, |
| 1821 | + }); |
| 1822 | + |
| 1823 | + $stateProvider.state('dynamic2', { |
| 1824 | + url: '/dynamic2/:param', |
| 1825 | + componentProvider: () => 'dynamicComponent', |
| 1826 | + params: { param: { dynamic: true } }, |
| 1827 | + }); |
| 1828 | + })); |
| 1829 | + |
| 1830 | + it('should not be called on the initial transition', () => { |
| 1831 | + const $state = svcs.$state, |
| 1832 | + $q = svcs.$q; |
| 1833 | + $state.go('dynamic', { param: 'abc' }); |
| 1834 | + $q.flush(); |
| 1835 | + expect(el.text().trim()).toBe('dynamicComponent'); |
| 1836 | + }); |
| 1837 | + |
| 1838 | + it('should be called when dynamic parameters change', () => { |
| 1839 | + const $state = svcs.$state, |
| 1840 | + $q = svcs.$q; |
| 1841 | + $state.go('dynamic', { param: 'abc' }); |
| 1842 | + $q.flush(); |
| 1843 | + $state.go('dynamic', { param: 'def' }); |
| 1844 | + $q.flush(); |
| 1845 | + |
| 1846 | + expect(el.text().trim()).toBe('dynamicComponent def'); |
| 1847 | + }); |
| 1848 | + |
| 1849 | + it('should work with componentProvider', () => { |
| 1850 | + const $state = svcs.$state, |
| 1851 | + $q = svcs.$q; |
| 1852 | + $state.go('dynamic2', { param: 'abc' }); |
| 1853 | + $q.flush(); |
| 1854 | + $state.go('dynamic2', { param: 'def' }); |
| 1855 | + $q.flush(); |
| 1856 | + |
| 1857 | + expect(el.text().trim()).toBe('dynamicComponent def'); |
| 1858 | + }); |
| 1859 | + }); |
| 1860 | + } |
1803 | 1861 | });
|
0 commit comments