Skip to content

Commit 19dfd9c

Browse files
test(uiview): add failing test for uiOnParamsChanged + componentProvider
1 parent 2b388cd commit 19dfd9c

File tree

1 file changed

+61
-3
lines changed

1 file changed

+61
-3
lines changed

test/viewDirectiveSpec.ts

+61-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as angular from 'angular';
2-
import './util/matchers';
2+
import { ICompileService, IRootScopeService } from 'angular';
33
import { extend } from '@uirouter/core';
4+
import './util/matchers';
45

56
declare let inject, jasmine;
67

@@ -1061,7 +1062,12 @@ describe('angular 1.5+ style .component()', function() {
10611062
});
10621063

10631064
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+
},
10651071
});
10661072
}
10671073
});
@@ -1796,8 +1802,60 @@ describe('angular 1.5+ style .component()', function() {
17961802
const directiveEl = el[0].querySelector('div ui-view dynamic-component');
17971803
expect(directiveEl).toBeDefined();
17981804
expect($state.current.name).toBe('dynamicComponent');
1799-
expect(el.text()).toBe('dynamicComponent');
1805+
expect(el.text().trim()).toBe('dynamicComponent');
18001806
});
18011807
}
18021808
});
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+
}
18031861
});

0 commit comments

Comments
 (0)