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