2016-06-23 12:47:54 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2016-09-27 20:12:25 -04:00
|
|
|
import {Component} from '@angular/core';
|
|
|
|
import {describe, expect, it} from '@angular/core/testing/testing_internal';
|
2016-04-28 20:50:03 -04:00
|
|
|
import {getComponentInfo, parseFields} from '@angular/upgrade/src/metadata';
|
2015-08-06 16:19:29 -04:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('upgrade metadata', () => {
|
2015-10-01 16:14:59 -04:00
|
|
|
it('should extract component selector', () => {
|
|
|
|
expect(getComponentInfo(ElementNameComponent).selector).toEqual('elementNameDashed');
|
|
|
|
});
|
2015-08-06 16:19:29 -04:00
|
|
|
|
|
|
|
|
|
|
|
describe('errors', () => {
|
|
|
|
it('should throw on missing selector', () => {
|
2015-10-01 16:14:59 -04:00
|
|
|
expect(() => getComponentInfo(AttributeNameComponent))
|
2016-06-22 17:58:57 -04:00
|
|
|
.toThrowError('Only selectors matching element names are supported, got: [attr-name]');
|
2015-08-06 16:19:29 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw on non element names', () => {
|
2015-10-01 16:14:59 -04:00
|
|
|
expect(() => getComponentInfo(NoAnnotationComponent))
|
2016-06-22 17:58:57 -04:00
|
|
|
.toThrowError('No Directive annotation found on NoAnnotationComponent');
|
2015-08-06 16:19:29 -04:00
|
|
|
});
|
|
|
|
});
|
2015-10-01 16:14:59 -04:00
|
|
|
|
|
|
|
describe('parseFields', () => {
|
|
|
|
it('should process nulls', () => { expect(parseFields(null)).toEqual([]); });
|
|
|
|
|
|
|
|
it('should process values', () => {
|
2016-06-08 19:38:52 -04:00
|
|
|
expect(parseFields([' name ', ' prop : attr '])).toEqual([
|
|
|
|
{
|
|
|
|
prop: 'name',
|
|
|
|
attr: 'name',
|
|
|
|
bracketAttr: '[name]',
|
|
|
|
parenAttr: '(name)',
|
|
|
|
bracketParenAttr: '[(name)]',
|
|
|
|
onAttr: 'onName',
|
|
|
|
bindAttr: 'bindName',
|
|
|
|
bindonAttr: 'bindonName'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
prop: 'prop',
|
|
|
|
attr: 'attr',
|
|
|
|
bracketAttr: '[attr]',
|
|
|
|
parenAttr: '(attr)',
|
|
|
|
bracketParenAttr: '[(attr)]',
|
|
|
|
onAttr: 'onAttr',
|
|
|
|
bindAttr: 'bindAttr',
|
|
|
|
bindonAttr: 'bindonAttr'
|
|
|
|
}
|
|
|
|
]);
|
2015-10-01 16:14:59 -04:00
|
|
|
});
|
2016-07-21 20:12:00 -04:00
|
|
|
});
|
2015-08-06 16:19:29 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-03-08 16:36:48 -05:00
|
|
|
@Component({selector: 'element-name-dashed', template: ``})
|
2015-08-06 16:19:29 -04:00
|
|
|
class ElementNameComponent {
|
|
|
|
}
|
|
|
|
|
2016-03-08 16:36:48 -05:00
|
|
|
@Component({selector: '[attr-name]', template: ``})
|
2015-08-06 16:19:29 -04:00
|
|
|
class AttributeNameComponent {
|
|
|
|
}
|
|
|
|
|
|
|
|
class NoAnnotationComponent {}
|