|
| 1 | +import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/test_lib'; |
| 2 | + |
| 3 | +import {LimitToPipe} from 'angular2/src/change_detection/pipes/limit_to_pipe'; |
| 4 | + |
| 5 | +export function main() { |
| 6 | + describe("LimitToPipe", () => { |
| 7 | + var list; |
| 8 | + var str; |
| 9 | + var pipe; |
| 10 | + |
| 11 | + beforeEach(() => { |
| 12 | + list = [1, 2, 3, 4, 5]; |
| 13 | + str = 'tuvwxyz'; |
| 14 | + pipe = new LimitToPipe(); |
| 15 | + }); |
| 16 | + |
| 17 | + describe("supports", () => { |
| 18 | + it("should support strings", () => { expect(pipe.supports(str)).toBe(true); }); |
| 19 | + it("should support lists", () => { expect(pipe.supports(list)).toBe(true); }); |
| 20 | + |
| 21 | + it("should not support other objects", () => { |
| 22 | + expect(pipe.supports(new Object())).toBe(false); |
| 23 | + expect(pipe.supports(null)).toBe(false); |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + describe("transform", () => { |
| 28 | + |
| 29 | + it('should return the first X items when X is positive', () => { |
| 30 | + expect(pipe.transform(list, [3])).toEqual([1, 2, 3]); |
| 31 | + expect(pipe.transform(str, [3])).toEqual('tuv'); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should return the last X items when X is negative', () => { |
| 35 | + expect(pipe.transform(list, [-3])).toEqual([3, 4, 5]); |
| 36 | + expect(pipe.transform(str, [-3])).toEqual('xyz'); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should return a copy of input array if X is exceeds array length', () => { |
| 40 | + expect(pipe.transform(list, [20])).toEqual(list); |
| 41 | + expect(pipe.transform(list, [-20])).toEqual(list); |
| 42 | + }); |
| 43 | + |
| 44 | + it('should return the entire string if X exceeds input length', () => { |
| 45 | + expect(pipe.transform(str, [20])).toEqual(str); |
| 46 | + expect(pipe.transform(str, [-20])).toEqual(str); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should not modify the input list', () => { |
| 50 | + expect(pipe.transform(list, [3])).toEqual([1, 2, 3]); |
| 51 | + expect(list).toEqual([1, 2, 3, 4, 5]); |
| 52 | + }); |
| 53 | + |
| 54 | + }); |
| 55 | + |
| 56 | + }); |
| 57 | +} |
0 commit comments