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 keys when using literal map in bound attribute', () => { const contents = `
`; const keys = parser.extract(contents, templateFilename).keys(); expect(keys).to.deep.equal(['value1', 'value2']); }); it('should extract keys when using literal arrays in bound attribute', () => { const contents = ``; const keys = parser.extract(contents, templateFilename).keys(); expect(keys).to.deep.equal(['value1', 'value2']); }); it('should extract keys when using binding pipe in bound attribute', () => { const contents = ``; const keys = parser.extract(contents, templateFilename).keys(); expect(keys).to.deep.equal(['KEY1']); }); it('should extract keys when using binary expression in bound attribute', () => { const contents = ``; const keys = parser.extract(contents, templateFilename).keys(); expect(keys).to.deep.equal(['KEY1']); }); it('should extract keys when using literal primitive in bound attribute', () => { const contents = ``; const keys = parser.extract(contents, templateFilename).keys(); expect(keys).to.deep.equal(['KEY1']); }); it('should extract keys when using conditional in bound attribute', () => { const contents = ``; const keys = parser.extract(contents, templateFilename).keys(); expect(keys).to.deep.equal(['KEY1', 'KEY2']); }); it('should extract keys when using nested conditionals in bound attribute', () => { const contents = ``; const keys = parser.extract(contents, templateFilename).keys(); expect(keys).to.deep.equal(['Sunny and warm', 'Sunny but cold', 'Not sunny']); }); it('should extract keys when using interpolation', () => { const contents = ``; const keys = parser.extract(contents, templateFilename).keys(); expect(keys).to.deep.equal(['KEY1', 'KEY3']); }); it('should extract keys keeping proper whitespace', () => { const contents = `Hello World
' }) export class TestComponent { } `; const keys = parser.extract(contents, componentFilename).keys(); expect(keys).to.deep.equal(['Hello World']); }); it('should extract contents when no translate attribute value is provided', () => { const contents = '{{ 'Audiobooks for personal development' | translate }}
`; const collection = parser.extract(contents, templateFilename); expect(collection.values).to.deep.equal({}); }); it('should extract contents from custom elements', () => { const contents = `this is an example of another a long label
this is an example
'; const keys = parser.extract(contents, templateFilename).keys(); expect(keys).to.deep.equal(['this is an example']); }); });