|
| 1 | +import { |
| 2 | + ddescribe, |
| 3 | + describe, |
| 4 | + it, |
| 5 | + iit, |
| 6 | + xit, |
| 7 | + expect, |
| 8 | + beforeEach, |
| 9 | + afterEach |
| 10 | +} from 'angular2/testing_internal'; |
| 11 | + |
| 12 | +import {I18nPluralPipe} from 'angular2/common'; |
| 13 | +import {PipeResolver} from 'angular2/src/core/linker/pipe_resolver'; |
| 14 | + |
| 15 | +export function main() { |
| 16 | + describe("I18nPluralPipe", () => { |
| 17 | + var pipe; |
| 18 | + var mapping = {'=0': 'No messages.', '=1': 'One message.', 'other': 'There are some messages.'}; |
| 19 | + var interpolatedMapping = |
| 20 | + {'=0': 'No messages.', '=1': 'One message.', 'other': 'There are # messages, that is #.'}; |
| 21 | + |
| 22 | + beforeEach(() => { pipe = new I18nPluralPipe(); }); |
| 23 | + |
| 24 | + it('should be marked as pure', |
| 25 | + () => { expect(new PipeResolver().resolve(I18nPluralPipe).pure).toEqual(true); }); |
| 26 | + |
| 27 | + describe("transform", () => { |
| 28 | + it("should return 0 text if value is 0", () => { |
| 29 | + var val = pipe.transform(0, [mapping]); |
| 30 | + expect(val).toEqual('No messages.'); |
| 31 | + }); |
| 32 | + |
| 33 | + it("should return 1 text if value is 1", () => { |
| 34 | + var val = pipe.transform(1, [mapping]); |
| 35 | + expect(val).toEqual('One message.'); |
| 36 | + }); |
| 37 | + |
| 38 | + it("should return other text if value is anything other than 0 or 1", () => { |
| 39 | + var val = pipe.transform(6, [mapping]); |
| 40 | + expect(val).toEqual('There are some messages.'); |
| 41 | + }); |
| 42 | + |
| 43 | + it("should interpolate the value into the text where indicated", () => { |
| 44 | + var val = pipe.transform(6, [interpolatedMapping]); |
| 45 | + expect(val).toEqual('There are 6 messages, that is 6.'); |
| 46 | + }); |
| 47 | + |
| 48 | + it("should use 'other' if value is undefined", () => { |
| 49 | + var messageLength; |
| 50 | + var val = pipe.transform(messageLength, [interpolatedMapping]); |
| 51 | + expect(val).toEqual('There are messages, that is .'); |
| 52 | + }); |
| 53 | + |
| 54 | + it("should not support bad arguments", |
| 55 | + () => { expect(() => pipe.transform(0, ['hey'])).toThrowError(); }); |
| 56 | + }); |
| 57 | + |
| 58 | + }); |
| 59 | +} |
0 commit comments