2016-12-08 13:53:13 +01:00
|
|
|
import { expect } from 'chai';
|
|
|
|
|
2019-06-12 11:50:23 +02:00
|
|
|
import { isPathAngularComponent, extractComponentInlineTemplate } from '../../src/utils/utils';
|
2016-12-08 13:53:13 +01:00
|
|
|
|
2019-06-12 11:50:23 +02:00
|
|
|
describe('Utils', () => {
|
2016-12-08 13:53:13 +01:00
|
|
|
it('should recognize js extension as angular component', () => {
|
2019-06-12 11:50:23 +02:00
|
|
|
const result = isPathAngularComponent('test.js');
|
2016-12-08 13:53:13 +01:00
|
|
|
expect(result).to.equal(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should recognize ts extension as angular component', () => {
|
2019-06-12 11:50:23 +02:00
|
|
|
const result = isPathAngularComponent('test.ts');
|
2016-12-08 13:53:13 +01:00
|
|
|
expect(result).to.equal(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not recognize html extension as angular component', () => {
|
2019-06-12 11:50:23 +02:00
|
|
|
const result = isPathAngularComponent('test.html');
|
2016-12-08 13:53:13 +01:00
|
|
|
expect(result).to.equal(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should extract inline template', () => {
|
|
|
|
const contents = `
|
|
|
|
@Component({
|
|
|
|
selector: 'test',
|
|
|
|
template: '<p translate>Hello World</p>'
|
|
|
|
})
|
|
|
|
export class TestComponent { }
|
|
|
|
`;
|
2019-06-12 11:50:23 +02:00
|
|
|
const template = extractComponentInlineTemplate(contents);
|
2016-12-08 13:53:13 +01:00
|
|
|
expect(template).to.equal('<p translate>Hello World</p>');
|
|
|
|
});
|
|
|
|
|
2019-06-13 11:59:36 +02:00
|
|
|
it('should extract inline template without html', () => {
|
|
|
|
const contents = `
|
|
|
|
@Component({
|
|
|
|
selector: 'test',
|
2019-06-13 12:17:04 +02:00
|
|
|
template: '{{ "Hello World" | translate }}'
|
2019-06-13 11:59:36 +02:00
|
|
|
})
|
|
|
|
export class TestComponent { }
|
|
|
|
`;
|
|
|
|
const template = extractComponentInlineTemplate(contents);
|
2019-06-13 12:17:04 +02:00
|
|
|
expect(template).to.equal('{{ "Hello World" | translate }}');
|
2019-06-13 11:59:36 +02:00
|
|
|
});
|
|
|
|
|
2016-12-13 15:17:03 +01:00
|
|
|
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 { }
|
|
|
|
`;
|
2019-06-12 11:50:23 +02:00
|
|
|
const template = extractComponentInlineTemplate(contents);
|
2016-12-13 15:17:03 +01:00
|
|
|
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');
|
2016-12-08 13:53:13 +01:00
|
|
|
});
|
|
|
|
});
|