fix(directive-parser) add support for bound attributes
This commit is contained in:
		| @@ -12,6 +12,55 @@ describe('DirectiveParser', () => { | ||||
| 		parser = new DirectiveParser(); | ||||
| 	}); | ||||
|  | ||||
|  | ||||
| 	it('should extract keys when using literal map in bound attribute', () => { | ||||
| 		const contents = `<div [translate]="{ key1: 'value1' | translate, key2: 'value2' | translate }"></div>`; | ||||
| 		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 = `<div [translate]="[ 'value1' | translate, 'value2' | translate ]"></div>`; | ||||
| 		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 = `<div [translate]="'KEY1' | withPipe"></div>`; | ||||
| 		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 = `<div [translate]="keyVar || 'KEY1'"></div>`; | ||||
| 		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 = `<div [translate]="'KEY1'"></div>`; | ||||
| 		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 = `<div [translate]="condition ? 'KEY1' : 'KEY2'"></div>`; | ||||
| 		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 = `<div [translate]="isSunny ? (isWarm ? 'Sunny and warm' : 'Sunny but cold') : 'Not sunny'"></div>`; | ||||
| 		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 = `<div translate="{{ 'KEY1' + key2 + 'KEY3' }}"></div>`; | ||||
| 		const keys = parser.extract(contents, templateFilename).keys(); | ||||
| 		expect(keys).to.deep.equal(['KEY1', 'KEY3']); | ||||
| 	}); | ||||
|  | ||||
| 	it('should extract keys keeping proper whitespace', () => { | ||||
| 		const contents = ` | ||||
| 			<div translate> | ||||
| @@ -120,4 +169,5 @@ describe('DirectiveParser', () => { | ||||
| 		const keys = parser.extract(contents, templateFilename).keys(); | ||||
| 		expect(keys).to.deep.equal(['this is an example']); | ||||
| 	}); | ||||
|  | ||||
| }); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user