2015-04-28 14:20:01 -04:00
|
|
|
import {
|
|
|
|
AsyncTestCompleter, inject, ddescribe, describe, it, iit, xit, expect, SpyObject,
|
|
|
|
proxy
|
|
|
|
} from 'angular2/test_lib';
|
2015-04-06 15:45:54 -04:00
|
|
|
|
|
|
|
import {DOM, DomAdapter} from 'angular2/src/dom/dom_adapter';
|
2015-04-28 14:20:01 -04:00
|
|
|
import {ElementRef} from 'angular2/src/core/compiler/element_ref';
|
2015-04-06 15:45:54 -04:00
|
|
|
|
|
|
|
import {Ruler, Rectangle} from 'angular2/src/services/ruler';
|
|
|
|
import {createRectangle} from './rectangle_mock';
|
2015-04-28 14:20:01 -04:00
|
|
|
import {IMPLEMENTS} from 'angular2/src/facade/lang';
|
2015-04-06 15:45:54 -04:00
|
|
|
|
|
|
|
function assertDimensions(rect: Rectangle, left, right, top, bottom, width, height) {
|
|
|
|
expect(rect.left).toEqual(left);
|
|
|
|
expect(rect.right).toEqual(right);
|
|
|
|
expect(rect.top).toEqual(top);
|
|
|
|
expect(rect.bottom).toEqual(bottom);
|
|
|
|
expect(rect.width).toEqual(width);
|
|
|
|
expect(rect.height).toEqual(height);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function main() {
|
|
|
|
|
|
|
|
describe('ruler service', () => {
|
|
|
|
|
2015-04-28 14:20:01 -04:00
|
|
|
it('should allow measuring ElementRefs',
|
2015-04-06 15:45:54 -04:00
|
|
|
inject([AsyncTestCompleter], (async) => {
|
2015-04-28 14:20:01 -04:00
|
|
|
var ruler = new Ruler(SpyObject.stub(new SpyDomAdapter(), {
|
|
|
|
'getBoundingClientRect': createRectangle(10, 20, 200, 100)
|
|
|
|
}));
|
2015-04-06 15:45:54 -04:00
|
|
|
|
2015-04-28 14:20:01 -04:00
|
|
|
var elRef = new SpyElementRef();
|
|
|
|
ruler.measure(elRef).then((rect) => {
|
2015-04-06 15:45:54 -04:00
|
|
|
assertDimensions(rect, 10, 210, 20, 120, 200, 100);
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should return 0 for all rectangle values while measuring elements in a document fragment',
|
|
|
|
inject([AsyncTestCompleter], (async) => {
|
|
|
|
var ruler = new Ruler(DOM);
|
2015-04-28 14:20:01 -04:00
|
|
|
var elRef = new SpyElementRef();
|
|
|
|
elRef.domElement = DOM.createElement('div');
|
|
|
|
ruler.measure(elRef).then((rect) => {
|
2015-04-06 15:45:54 -04:00
|
|
|
//here we are using an element created in a doc fragment so all the measures will come back as 0
|
|
|
|
assertDimensions(rect, 0, 0, 0, 0, 0, 0);
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
2015-04-07 23:54:20 -04:00
|
|
|
|
2015-04-28 14:20:01 -04:00
|
|
|
@proxy
|
|
|
|
@IMPLEMENTS(ElementRef)
|
|
|
|
class SpyElementRef extends SpyObject {
|
|
|
|
domElement;
|
|
|
|
constructor(){super(ElementRef);}
|
|
|
|
noSuchMethod(m){return super.noSuchMethod(m)}
|
|
|
|
}
|
2015-04-07 23:54:20 -04:00
|
|
|
|
2015-04-28 14:20:01 -04:00
|
|
|
@proxy
|
|
|
|
@IMPLEMENTS(DomAdapter)
|
|
|
|
class SpyDomAdapter extends SpyObject {
|
|
|
|
constructor(){super(DomAdapter);}
|
|
|
|
noSuchMethod(m){return super.noSuchMethod(m)}
|
|
|
|
}
|