|
| 1 | +import {AsyncTestCompleter, inject, ddescribe, describe, it, iit, xit, expect, SpyObject} from 'angular2/test_lib'; |
| 2 | + |
| 3 | +import {DOM, DomAdapter} from 'angular2/src/dom/dom_adapter'; |
| 4 | +import {NgElement} from 'angular2/src/core/dom/element'; |
| 5 | + |
| 6 | +import {Ruler, Rectangle} from 'angular2/src/services/ruler'; |
| 7 | +import {createRectangle} from './rectangle_mock'; |
| 8 | + |
| 9 | +class DomAdapterMock extends DomAdapter { |
| 10 | + rect; |
| 11 | + constructor(rect) { |
| 12 | + super(); |
| 13 | + this.rect = rect; |
| 14 | + } |
| 15 | + |
| 16 | + getBoundingClientRect(elm) { |
| 17 | + return this.rect; |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +function assertDimensions(rect: Rectangle, left, right, top, bottom, width, height) { |
| 22 | + expect(rect.left).toEqual(left); |
| 23 | + expect(rect.right).toEqual(right); |
| 24 | + expect(rect.top).toEqual(top); |
| 25 | + expect(rect.bottom).toEqual(bottom); |
| 26 | + expect(rect.width).toEqual(width); |
| 27 | + expect(rect.height).toEqual(height); |
| 28 | +} |
| 29 | + |
| 30 | +export function main() { |
| 31 | + |
| 32 | + describe('ruler service', () => { |
| 33 | + |
| 34 | + it('should allow measuring NgElements', |
| 35 | + inject([AsyncTestCompleter], (async) => { |
| 36 | + var ruler = new Ruler(new DomAdapterMock(createRectangle(10, 20, 200, 100))); |
| 37 | + |
| 38 | + ruler.measure(new NgElement(null)).then((rect) => { |
| 39 | + assertDimensions(rect, 10, 210, 20, 120, 200, 100); |
| 40 | + async.done(); |
| 41 | + }); |
| 42 | + })); |
| 43 | + |
| 44 | + |
| 45 | + it('should return 0 for all rectangle values while measuring elements in a document fragment', |
| 46 | + inject([AsyncTestCompleter], (async) => { |
| 47 | + var ruler = new Ruler(DOM); |
| 48 | + |
| 49 | + ruler.measure(new NgElement(DOM.createElement('div'))).then((rect) => { |
| 50 | + //here we are using an element created in a doc fragment so all the measures will come back as 0 |
| 51 | + assertDimensions(rect, 0, 0, 0, 0, 0, 0); |
| 52 | + async.done(); |
| 53 | + }); |
| 54 | + })); |
| 55 | + |
| 56 | + }); |
| 57 | +} |
0 commit comments