forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruler_spec.ts
More file actions
74 lines (63 loc) · 2.12 KB
/
ruler_spec.ts
File metadata and controls
74 lines (63 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import {
AsyncTestCompleter,
inject,
ddescribe,
describe,
it,
iit,
xit,
expect,
SpyObject,
proxy
} from 'angular2/test_lib';
import {DOM, DomAdapter} from 'angular2/src/dom/dom_adapter';
import {ElementRef} from 'angular2/src/core/compiler/element_ref';
import {Ruler, Rectangle} from 'angular2/src/services/ruler';
import {createRectangle} from './rectangle_mock';
import {IMPLEMENTS} from 'angular2/src/facade/lang';
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', () => {
it('should allow measuring ElementRefs', inject([AsyncTestCompleter], (async) => {
var ruler = new Ruler(SpyObject.stub(
new SpyDomAdapter(), {'getBoundingClientRect': createRectangle(10, 20, 200, 100)}));
var elRef = <any>new SpyElementRef();
ruler.measure(elRef).then((rect) => {
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);
var elRef = <any>new SpyElementRef();
elRef.nativeElement = DOM.createElement('div');
ruler.measure(elRef).then((rect) => {
// 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();
});
}));
});
}
@proxy()
@IMPLEMENTS(ElementRef)
class SpyElementRef extends SpyObject {
nativeElement;
constructor() { super(ElementRef); }
noSuchMethod(m) { return super.noSuchMethod(m) }
}
@proxy()
@IMPLEMENTS(DomAdapter)
class SpyDomAdapter extends SpyObject {
constructor() { super(DomAdapter); }
noSuchMethod(m) { return super.noSuchMethod(m) }
}