import { expect } from 'chai'; import { DirectiveParser } from '../src/parsers/directive.parser'; describe('DirectiveParser', () => { const templateFilename: string = 'test.template.html'; const componentFilename: string = 'test.component.ts'; let parser: DirectiveParser; beforeEach(() => { parser = new DirectiveParser(); }); it('should extract contents when no translate attribute value is provided', () => { const contents = '
Hello World
'; const messages = parser.process(templateFilename, contents); expect(messages).to.deep.equal(['Hello World']); }); it('should extract translate attribute if provided', () => { const contents = '
Hello World
'; const messages = parser.process(templateFilename, contents); expect(messages).to.deep.equal(['KEY']); }); it('should extract bound translate attribute as key if provided', () => { const contents = '
Hello World
'; const messages = parser.process(templateFilename, contents); expect(messages).to.deep.equal(['KEY']); }); it('should extract direct text nodes when no translate attribute value is provided', () => { const contents = `
Hello World Hi there
`; const messages = parser.process(templateFilename, contents); expect(messages).to.deep.equal(['Hello', 'Hi']); }); it('should extract direct text nodes of tags with a translate attribute', () => { const contents = `
Hello World
Hi there
`; const messages = parser.process(templateFilename, contents); expect(messages).to.deep.equal(['Hello World', 'Hi there']); }); it('should extract translate attribute if provided or direct text nodes if not', () => { const contents = `
Hello World

Hi there

Lorem Ipsum

`; const messages = parser.process(templateFilename, contents); expect(messages).to.deep.equal(['KEY', 'Hi there', 'OTHER_KEY']); }); it('should extract and parse inline template', () => { const contents = ` @Component({ selector: 'test', template: '

Hello World

' }) export class TestComponent { } `; const messages = parser.process(componentFilename, contents); expect(messages).to.deep.equal(['Hello World']); }); });