2016-12-08 16:12:43 +03:00
|
|
|
|
import { expect } from 'chai';
|
|
|
|
|
|
2016-12-08 16:28:59 +03:00
|
|
|
|
import { PipeParser } from '../../src/parsers/pipe.parser';
|
2016-12-08 16:12:43 +03:00
|
|
|
|
|
|
|
|
|
describe('PipeParser', () => {
|
|
|
|
|
|
|
|
|
|
const templateFilename: string = 'test.template.html';
|
|
|
|
|
|
|
|
|
|
let parser: PipeParser;
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
parser = new PipeParser();
|
|
|
|
|
});
|
|
|
|
|
|
2017-01-13 11:34:34 +03:00
|
|
|
|
it('should only extract string using pipe', () => {
|
|
|
|
|
const contents = `<button [style.background]="'lime'">{{ 'SomeKey_NotWorking' | translate }}</button>`;
|
|
|
|
|
const keys = parser.extract(contents, templateFilename).keys();
|
|
|
|
|
expect(keys).to.deep.equal(['SomeKey_NotWorking']);
|
|
|
|
|
});
|
|
|
|
|
|
2016-12-08 16:12:43 +03:00
|
|
|
|
it('should extract interpolated strings using translate pipe', () => {
|
|
|
|
|
const contents = `Hello {{ 'World' | translate }}`;
|
2016-12-09 07:18:04 +03:00
|
|
|
|
const keys = parser.extract(contents, templateFilename).keys();
|
|
|
|
|
expect(keys).to.deep.equal(['World']);
|
2016-12-08 16:12:43 +03:00
|
|
|
|
});
|
|
|
|
|
|
2016-12-13 17:17:03 +03:00
|
|
|
|
it('should extract strings with escaped quotes', () => {
|
|
|
|
|
const contents = `Hello {{ 'World\'s largest potato' | translate }}`;
|
|
|
|
|
const keys = parser.extract(contents, templateFilename).keys();
|
|
|
|
|
expect(keys).to.deep.equal([`World's largest potato`]);
|
|
|
|
|
});
|
|
|
|
|
|
2016-12-08 16:12:43 +03:00
|
|
|
|
it('should extract interpolated strings using translate pipe in attributes', () => {
|
|
|
|
|
const contents = `<span attr="{{ 'Hello World' | translate }}"></span>`;
|
2016-12-09 07:18:04 +03:00
|
|
|
|
const keys = parser.extract(contents, templateFilename).keys();
|
|
|
|
|
expect(keys).to.deep.equal(['Hello World']);
|
2016-12-08 16:12:43 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should extract bound strings using translate pipe in attributes', () => {
|
|
|
|
|
const contents = `<span [attr]="'Hello World' | translate"></span>`;
|
2016-12-09 07:18:04 +03:00
|
|
|
|
const keys = parser.extract(contents, templateFilename).keys();
|
|
|
|
|
expect(keys).to.deep.equal(['Hello World']);
|
2016-12-08 16:12:43 +03:00
|
|
|
|
});
|
|
|
|
|
|
2016-12-20 18:18:40 +03:00
|
|
|
|
it('should not use a greedy regular expression', () => {
|
|
|
|
|
const contents = `
|
|
|
|
|
<ion-header>
|
|
|
|
|
<ion-navbar color="brand">
|
|
|
|
|
<ion-title>{{ 'Info' | translate }}</ion-title>
|
|
|
|
|
</ion-navbar>
|
|
|
|
|
</ion-header>
|
|
|
|
|
|
|
|
|
|
<ion-content>
|
|
|
|
|
|
|
|
|
|
<content-loading *ngIf="isLoading">
|
|
|
|
|
{{ 'Loading...' | translate }}
|
|
|
|
|
</content-loading>
|
|
|
|
|
|
|
|
|
|
</ion-content>
|
|
|
|
|
`;
|
|
|
|
|
const keys = parser.extract(contents, templateFilename).keys();
|
|
|
|
|
expect(keys).to.deep.equal(['Info', 'Loading...']);
|
|
|
|
|
});
|
|
|
|
|
|
2016-12-20 18:42:05 +03:00
|
|
|
|
it('should extract strings on same line', () => {
|
|
|
|
|
const contents = `<span [attr]="'Hello' | translate"></span><span [attr]="'World' | translate"></span>`;
|
|
|
|
|
const keys = parser.extract(contents, templateFilename).keys();
|
|
|
|
|
expect(keys).to.deep.equal(['Hello', 'World']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should extract strings from this template', () => {
|
|
|
|
|
const contents = `
|
|
|
|
|
<ion-list inset>
|
|
|
|
|
<ion-item>
|
|
|
|
|
<ion-icon item-left name="person" color="dark"></ion-icon>
|
|
|
|
|
<ion-input formControlName="name" type="text" [placeholder]="'Name' | translate"></ion-input>
|
|
|
|
|
</ion-item>
|
|
|
|
|
<ion-item>
|
|
|
|
|
<p color="danger" danger *ngFor="let error of form.get('name').getError('remote')">
|
|
|
|
|
{{ error }}
|
|
|
|
|
</p>
|
|
|
|
|
</ion-item>
|
|
|
|
|
</ion-list>
|
|
|
|
|
<div class="form-actions">
|
|
|
|
|
<button ion-button (click)="onSubmit()" color="secondary" block>{{ 'Create account' | translate }}</button>
|
|
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
const keys = parser.extract(contents, templateFilename).keys();
|
|
|
|
|
expect(keys).to.deep.equal(['Name', 'Create account']);
|
|
|
|
|
});
|
|
|
|
|
|
2016-12-08 16:12:43 +03:00
|
|
|
|
});
|