2016-04-12 12:40:37 -04:00
|
|
|
import {
|
|
|
|
ddescribe,
|
|
|
|
describe,
|
|
|
|
it,
|
|
|
|
iit,
|
|
|
|
xit,
|
|
|
|
expect,
|
|
|
|
beforeEach,
|
|
|
|
afterEach
|
2016-04-28 20:50:03 -04:00
|
|
|
} from '@angular/core/testing/testing_internal';
|
2016-02-26 13:02:52 -05:00
|
|
|
|
2016-04-28 20:50:03 -04:00
|
|
|
import {I18nSelectPipe} from '@angular/common';
|
|
|
|
import {PipeResolver} from '@angular/compiler/src/pipe_resolver';
|
2016-02-26 13:02:52 -05:00
|
|
|
|
|
|
|
export function main() {
|
2016-04-12 12:40:37 -04:00
|
|
|
describe("I18nSelectPipe", () => {
|
2016-02-26 13:02:52 -05:00
|
|
|
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); });
|
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
describe("transform", () => {
|
|
|
|
it("should return male text if value is male", () => {
|
2016-04-22 18:33:32 -04:00
|
|
|
var val = pipe.transform('male', mapping);
|
2016-02-26 13:02:52 -05:00
|
|
|
expect(val).toEqual('Invite him.');
|
|
|
|
});
|
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
it("should return female text if value is female", () => {
|
2016-04-22 18:33:32 -04:00
|
|
|
var val = pipe.transform('female', mapping);
|
2016-02-26 13:02:52 -05:00
|
|
|
expect(val).toEqual('Invite her.');
|
|
|
|
});
|
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
it("should return other text if value is anything other than male or female", () => {
|
2016-04-22 18:33:32 -04:00
|
|
|
var val = pipe.transform('Anything else', mapping);
|
2016-02-26 13:02:52 -05:00
|
|
|
expect(val).toEqual('Invite them.');
|
|
|
|
});
|
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
it("should use 'other' if value is undefined", () => {
|
2016-02-26 13:02:52 -05:00
|
|
|
var gender;
|
2016-04-22 18:33:32 -04:00
|
|
|
var val = pipe.transform(gender, mapping);
|
2016-02-26 13:02:52 -05:00
|
|
|
expect(val).toEqual('Invite them.');
|
|
|
|
});
|
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
it("should not support bad arguments",
|
2016-04-22 18:33:32 -04:00
|
|
|
() => { expect(() => pipe.transform('male', 'hey')).toThrowError(); });
|
2016-02-26 13:02:52 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|