Add tests and allow more liberal spacing with get/instant calls

This commit is contained in:
Kim Biesbjerg
2016-12-13 15:17:03 +01:00
parent ca8b122295
commit 8093370e94
9 changed files with 64 additions and 20 deletions

View File

@@ -41,6 +41,12 @@ describe('AbstractTemplateParser', () => {
expect(result).to.equal(false);
});
it('should normalize bound attributes', () => {
const contents = `<p [translate]="'KEY'">Hello World</p>`;
const template = parser.normalizeTemplateAttributes(contents);
expect(template).to.equal('<p translate="KEY">Hello World</p>');
});
it('should extract inline template', () => {
const contents = `
@Component({
@@ -53,10 +59,25 @@ describe('AbstractTemplateParser', () => {
expect(template).to.equal('<p translate>Hello World</p>');
});
it('should normalize bound attributes', () => {
const contents = `<p [translate]="'KEY'">Hello World</p>`;
const template = parser.normalizeTemplateAttributes(contents);
expect(template).to.equal('<p translate="KEY">Hello World</p>');
it('should extract inline template spanning multiple lines', () => {
const contents = `
@Component({
selector: 'test',
template: '
<p>
Hello World
</p>
',
styles: ['
p {
color: red;
}
']
})
export class TestComponent { }
`;
const template = parser.extractInlineTemplate(contents);
expect(template).to.equal('\n\t\t\t\t\t<p>\n\t\t\t\t\t\tHello World\n\t\t\t\t\t</p>\n\t\t\t\t');
});
});

View File

@@ -18,6 +18,12 @@ describe('PipeParser', () => {
expect(keys).to.deep.equal(['World']);
});
it('should extract strings with escaped quotes', () => {
const contents = `Hello {{ 'World\'s largest potato' | translate }}`;
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal([`World's largest potato`]);
});
it('should extract interpolated strings using translate pipe in attributes', () => {
const contents = `<span attr="{{ 'Hello World' | translate }}"></span>`;
const keys = parser.extract(contents, templateFilename).keys();

View File

@@ -103,4 +103,24 @@ describe('ServiceParser', () => {
expect(keys).to.deep.equal([]);
});
it('should extract strings with liberal spacing', () => {
const contents = `
@Component({ })
export class AppComponent {
public constructor(
protected _translateService: TranslateService,
protected _otherService: OtherService
) { }
public test() {
this._translateService.instant('Hello');
this._translateService.get ( 'World' );
this._translateService.instant ( ['How'] );
this._translateService.get([ 'Are' ]);
this._translateService.get([ 'You' , 'Today' ]);
}
`;
const keys = parser.extract(contents, componentFilename).keys();
expect(keys).to.deep.equal(['Hello', 'World', 'How', 'Are', 'You', 'Today']);
});
});