feat(upgrade): use ComponentFactory.inputs/outputs/ngContentSelectors
DEPRECATION: - the arguments `inputs` / `outputs` / `ngContentSelectors` of `downgradeComponent` are no longer used as Angular calculates these automatically now. - Compiler.getNgContentSelectors is deprecated. Use ComponentFactory.ngContentSelectors instead.
This commit is contained in:

committed by
Chuck Jazdzewski

parent
1171f91a80
commit
a3e32fb7e1
@ -11,8 +11,7 @@ import {PropertyBinding} from '@angular/upgrade/src/common/component_info';
|
||||
export function main() {
|
||||
describe('PropertyBinding', () => {
|
||||
it('should process a simple binding', () => {
|
||||
const binding = new PropertyBinding('someBinding');
|
||||
expect(binding.binding).toEqual('someBinding');
|
||||
const binding = new PropertyBinding('someBinding', 'someBinding');
|
||||
expect(binding.prop).toEqual('someBinding');
|
||||
expect(binding.attr).toEqual('someBinding');
|
||||
expect(binding.bracketAttr).toEqual('[someBinding]');
|
||||
@ -24,21 +23,7 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should process a two-part binding', () => {
|
||||
const binding = new PropertyBinding('someProp:someAttr');
|
||||
expect(binding.binding).toEqual('someProp:someAttr');
|
||||
expect(binding.prop).toEqual('someProp');
|
||||
expect(binding.attr).toEqual('someAttr');
|
||||
expect(binding.bracketAttr).toEqual('[someAttr]');
|
||||
expect(binding.bracketParenAttr).toEqual('[(someAttr)]');
|
||||
expect(binding.parenAttr).toEqual('(someAttr)');
|
||||
expect(binding.onAttr).toEqual('onSomeAttr');
|
||||
expect(binding.bindAttr).toEqual('bindSomeAttr');
|
||||
expect(binding.bindonAttr).toEqual('bindonSomeAttr');
|
||||
});
|
||||
|
||||
it('should cope with whitespace', () => {
|
||||
const binding = new PropertyBinding(' someProp : someAttr ');
|
||||
expect(binding.binding).toEqual(' someProp : someAttr ');
|
||||
const binding = new PropertyBinding('someProp', 'someAttr');
|
||||
expect(binding.prop).toEqual('someProp');
|
||||
expect(binding.attr).toEqual('someAttr');
|
||||
expect(binding.bracketAttr).toEqual('[someAttr]');
|
||||
|
@ -6,25 +6,13 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import * as angular from '@angular/upgrade/src/common/angular1';
|
||||
import {DowngradeComponentAdapter} from '@angular/upgrade/src/common/downgrade_component_adapter';
|
||||
import {NgContentSelectorHelper} from '@angular/upgrade/src/common/ng_content_selector_helper';
|
||||
import {groupNodesBySelector} from '@angular/upgrade/src/common/downgrade_component_adapter';
|
||||
import {nodes} from './test_helpers';
|
||||
|
||||
|
||||
export function main() {
|
||||
describe('DowngradeComponentAdapter', () => {
|
||||
describe('groupNodesBySelector', () => {
|
||||
function createAdapter(selectors: string[], contentNodes: Node[]): DowngradeComponentAdapter {
|
||||
const selectorHelper = new NgContentSelectorHelper();
|
||||
const fakeInjector = {get: function() { return selectorHelper; }};
|
||||
const fakeScope = { $new: function() {} } as any;
|
||||
const element = angular.element('<div></div>');
|
||||
element.append(contentNodes);
|
||||
return new DowngradeComponentAdapter(
|
||||
'id', {component: null, selectors}, element, null, fakeScope, null, fakeInjector, null,
|
||||
null, null, null);
|
||||
}
|
||||
|
||||
it('should return an array of node collections for each selector', () => {
|
||||
const contentNodes = nodes(
|
||||
'<div class="x"><span>div-1 content</span></div>' +
|
||||
@ -34,8 +22,7 @@ export function main() {
|
||||
'<div class="x"><span>div-2 content</span></div>');
|
||||
|
||||
const selectors = ['input[type=date]', 'span', '.x'];
|
||||
const adapter = createAdapter(selectors, contentNodes);
|
||||
const projectableNodes = adapter.groupProjectableNodes();
|
||||
const projectableNodes = groupNodesBySelector(selectors, contentNodes);
|
||||
|
||||
expect(projectableNodes[0]).toEqual(nodes('<input type="date" name="myDate">'));
|
||||
expect(projectableNodes[1]).toEqual(nodes('<span>span content</span>'));
|
||||
@ -54,8 +41,7 @@ export function main() {
|
||||
'<div class="x"><span>div-2 content</span></div>');
|
||||
|
||||
const selectors = ['.x', '*', 'input[type=date]'];
|
||||
const adapter = createAdapter(selectors, contentNodes);
|
||||
const projectableNodes = adapter.groupProjectableNodes();
|
||||
const projectableNodes = groupNodesBySelector(selectors, contentNodes);
|
||||
|
||||
expect(projectableNodes[0])
|
||||
.toEqual(nodes(
|
||||
@ -70,8 +56,7 @@ export function main() {
|
||||
|
||||
it('should return an array of empty arrays if there are no nodes passed in', () => {
|
||||
const selectors = ['.x', '*', 'input[type=date]'];
|
||||
const adapter = createAdapter(selectors, []);
|
||||
const projectableNodes = adapter.groupProjectableNodes();
|
||||
const projectableNodes = groupNodesBySelector(selectors, []);
|
||||
expect(projectableNodes).toEqual([[], [], []]);
|
||||
});
|
||||
|
||||
@ -83,12 +68,10 @@ export function main() {
|
||||
'<span>span content</span>' +
|
||||
'<div class="x"><span>div-2 content</span></div>');
|
||||
|
||||
const adapter1 = createAdapter([], contentNodes);
|
||||
const projectableNodes = adapter1.groupProjectableNodes();
|
||||
const projectableNodes = groupNodesBySelector([], contentNodes);
|
||||
expect(projectableNodes).toEqual([]);
|
||||
|
||||
const adapter2 = createAdapter(['.not-there'], contentNodes);
|
||||
const noMatchSelectorNodes = adapter2.groupProjectableNodes();
|
||||
const noMatchSelectorNodes = groupNodesBySelector(['.not-there'], contentNodes);
|
||||
expect(noMatchSelectorNodes).toEqual([[]]);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user