59
modules/angular2/test/common/pipes/i18n_plural_pipe_spec.ts
Normal file
59
modules/angular2/test/common/pipes/i18n_plural_pipe_spec.ts
Normal file
@ -0,0 +1,59 @@
|
||||
import {
|
||||
ddescribe,
|
||||
describe,
|
||||
it,
|
||||
iit,
|
||||
xit,
|
||||
expect,
|
||||
beforeEach,
|
||||
afterEach
|
||||
} from 'angular2/testing_internal';
|
||||
|
||||
import {I18nPluralPipe} from 'angular2/common';
|
||||
import {PipeResolver} from 'angular2/src/core/linker/pipe_resolver';
|
||||
|
||||
export function main() {
|
||||
describe("I18nPluralPipe", () => {
|
||||
var pipe;
|
||||
var mapping = {'=0': 'No messages.', '=1': 'One message.', 'other': 'There are some messages.'};
|
||||
var interpolatedMapping =
|
||||
{'=0': 'No messages.', '=1': 'One message.', 'other': 'There are # messages, that is #.'};
|
||||
|
||||
beforeEach(() => { pipe = new I18nPluralPipe(); });
|
||||
|
||||
it('should be marked as pure',
|
||||
() => { expect(new PipeResolver().resolve(I18nPluralPipe).pure).toEqual(true); });
|
||||
|
||||
describe("transform", () => {
|
||||
it("should return 0 text if value is 0", () => {
|
||||
var val = pipe.transform(0, [mapping]);
|
||||
expect(val).toEqual('No messages.');
|
||||
});
|
||||
|
||||
it("should return 1 text if value is 1", () => {
|
||||
var val = pipe.transform(1, [mapping]);
|
||||
expect(val).toEqual('One message.');
|
||||
});
|
||||
|
||||
it("should return other text if value is anything other than 0 or 1", () => {
|
||||
var val = pipe.transform(6, [mapping]);
|
||||
expect(val).toEqual('There are some messages.');
|
||||
});
|
||||
|
||||
it("should interpolate the value into the text where indicated", () => {
|
||||
var val = pipe.transform(6, [interpolatedMapping]);
|
||||
expect(val).toEqual('There are 6 messages, that is 6.');
|
||||
});
|
||||
|
||||
it("should use 'other' if value is undefined", () => {
|
||||
var messageLength;
|
||||
var val = pipe.transform(messageLength, [interpolatedMapping]);
|
||||
expect(val).toEqual('There are messages, that is .');
|
||||
});
|
||||
|
||||
it("should not support bad arguments",
|
||||
() => { expect(() => pipe.transform(0, ['hey'])).toThrowError(); });
|
||||
});
|
||||
|
||||
});
|
||||
}
|
52
modules/angular2/test/common/pipes/i18n_select_pipe_spec.ts
Normal file
52
modules/angular2/test/common/pipes/i18n_select_pipe_spec.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import {
|
||||
ddescribe,
|
||||
describe,
|
||||
it,
|
||||
iit,
|
||||
xit,
|
||||
expect,
|
||||
beforeEach,
|
||||
afterEach
|
||||
} from 'angular2/testing_internal';
|
||||
|
||||
import {I18nSelectPipe} from 'angular2/common';
|
||||
import {PipeResolver} from 'angular2/src/core/linker/pipe_resolver';
|
||||
|
||||
export function main() {
|
||||
describe("I18nSelectPipe", () => {
|
||||
var pipe;
|
||||
var mapping = {'male': 'Invite him.', 'female': 'Invite her.', 'other': 'Invite them.'};
|
||||
|
||||
beforeEach(() => { pipe = new I18nSelectPipe(); });
|
||||
|
||||
it('should be marked as pure',
|
||||
() => { expect(new PipeResolver().resolve(I18nSelectPipe).pure).toEqual(true); });
|
||||
|
||||
describe("transform", () => {
|
||||
it("should return male text if value is male", () => {
|
||||
var val = pipe.transform('male', [mapping]);
|
||||
expect(val).toEqual('Invite him.');
|
||||
});
|
||||
|
||||
it("should return female text if value is female", () => {
|
||||
var val = pipe.transform('female', [mapping]);
|
||||
expect(val).toEqual('Invite her.');
|
||||
});
|
||||
|
||||
it("should return other text if value is anything other than male or female", () => {
|
||||
var val = pipe.transform('Anything else', [mapping]);
|
||||
expect(val).toEqual('Invite them.');
|
||||
});
|
||||
|
||||
it("should use 'other' if value is undefined", () => {
|
||||
var gender;
|
||||
var val = pipe.transform(gender, [mapping]);
|
||||
expect(val).toEqual('Invite them.');
|
||||
});
|
||||
|
||||
it("should not support bad arguments",
|
||||
() => { expect(() => pipe.transform('male', ['hey'])).toThrowError(); });
|
||||
});
|
||||
|
||||
});
|
||||
}
|
@ -208,6 +208,10 @@ var NG_COMMON = [
|
||||
'FormBuilder.array()',
|
||||
'FormBuilder.control()',
|
||||
'FormBuilder.group()',
|
||||
'I18nPluralPipe',
|
||||
'I18nPluralPipe.transform()',
|
||||
'I18nSelectPipe',
|
||||
'I18nSelectPipe.transform()',
|
||||
'JsonPipe',
|
||||
'JsonPipe.transform()',
|
||||
'LowerCasePipe',
|
||||
|
Reference in New Issue
Block a user