refactor (test/services): Ts'ifying test/services
Translates AtScript files in test/services to TypeScript Closes #2193
This commit is contained in:
parent
c065fb1422
commit
8ce0a67c81
|
@ -1,68 +0,0 @@
|
|||
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 = 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 = new SpyElementRef();
|
||||
elRef.domElement = 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 {
|
||||
domElement;
|
||||
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)}
|
||||
}
|
|
@ -0,0 +1,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.domElement = 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 {
|
||||
domElement;
|
||||
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) }
|
||||
}
|
|
@ -4,18 +4,14 @@ import {DOM} from 'angular2/src/dom/dom_adapter';
|
|||
import {Title} from 'angular2/src/services/title';
|
||||
|
||||
export function main() {
|
||||
|
||||
describe('title service', () => {
|
||||
var initialTitle = DOM.getTitle();
|
||||
var titleService = new Title();
|
||||
|
||||
afterEach(() => {
|
||||
DOM.setTitle(initialTitle);
|
||||
});
|
||||
afterEach(() => { DOM.setTitle(initialTitle); });
|
||||
|
||||
it('should allow reading initial title', () => {
|
||||
expect(titleService.getTitle()).toEqual(initialTitle);
|
||||
});
|
||||
it('should allow reading initial title',
|
||||
() => { expect(titleService.getTitle()).toEqual(initialTitle); });
|
||||
|
||||
it('should set a title on the injected document', () => {
|
||||
titleService.setTitle('test title');
|
|
@ -18,25 +18,32 @@ export function main() {
|
|||
});
|
||||
|
||||
it('should append to the base path', () => {
|
||||
expect(resolver.resolve('http://www.foo.com/baz/', 'bar')).toEqual('http://www.foo.com/baz/bar');
|
||||
expect(resolver.resolve('http://www.foo.com/baz/', './bar')).toEqual('http://www.foo.com/baz/bar');
|
||||
expect(resolver.resolve('http://www.foo.com/baz/', 'bar'))
|
||||
.toEqual('http://www.foo.com/baz/bar');
|
||||
expect(resolver.resolve('http://www.foo.com/baz/', './bar'))
|
||||
.toEqual('http://www.foo.com/baz/bar');
|
||||
});
|
||||
|
||||
it('should support ".." in the path', () => {
|
||||
expect(resolver.resolve('http://www.foo.com/baz/', '../bar')).toEqual('http://www.foo.com/bar');
|
||||
expect(resolver.resolve('http://www.foo.com/1/2/3/', '../../bar')).toEqual('http://www.foo.com/1/bar');
|
||||
expect(resolver.resolve('http://www.foo.com/1/2/3/', '../biz/bar')).toEqual('http://www.foo.com/1/2/biz/bar');
|
||||
expect(resolver.resolve('http://www.foo.com/1/2/baz', '../../bar')).toEqual('http://www.foo.com/bar');
|
||||
expect(resolver.resolve('http://www.foo.com/baz/', '../bar'))
|
||||
.toEqual('http://www.foo.com/bar');
|
||||
expect(resolver.resolve('http://www.foo.com/1/2/3/', '../../bar'))
|
||||
.toEqual('http://www.foo.com/1/bar');
|
||||
expect(resolver.resolve('http://www.foo.com/1/2/3/', '../biz/bar'))
|
||||
.toEqual('http://www.foo.com/1/2/biz/bar');
|
||||
expect(resolver.resolve('http://www.foo.com/1/2/baz', '../../bar'))
|
||||
.toEqual('http://www.foo.com/bar');
|
||||
});
|
||||
|
||||
it('should ignore the base path when the url has a scheme', () => {
|
||||
expect(resolver.resolve('http://www.foo.com', 'http://www.bar.com')).toEqual('http://www.bar.com');
|
||||
})
|
||||
it('should ignore the base path when the url has a scheme',
|
||||
() =>
|
||||
{
|
||||
expect(resolver.resolve('http://www.foo.com', 'http://www.bar.com'))
|
||||
.toEqual('http://www.bar.com');
|
||||
})
|
||||
|
||||
it('should throw when the url start with "/"', () => {
|
||||
expect(() => {
|
||||
resolver.resolve('http://www.foo.com/1/2', '/test');
|
||||
}).toThrowError();
|
||||
});
|
||||
it('should throw when the url start with "/"', () => {
|
||||
expect(() => { resolver.resolve('http://www.foo.com/1/2', '/test'); }).toThrowError();
|
||||
});
|
||||
});
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
import {
|
||||
AsyncTestCompleter,
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
describe,
|
||||
expect,
|
||||
iit,
|
||||
inject,
|
||||
it,
|
||||
xit
|
||||
} from 'angular2/test_lib';
|
||||
|
||||
import {XHRImpl} from 'angular2/src/services/xhr_impl';
|
||||
import {PromiseWrapper} from 'angular2/src/facade/async';
|
||||
|
||||
export function main() {
|
||||
describe('XHRImpl', () => {
|
||||
var xhr;
|
||||
var url200 = '/base/modules/angular2/test/services/static_assets/200.html';
|
||||
var url404 = '/base/modules/angular2/test/services/static_assets/404.html';
|
||||
|
||||
beforeEach(() => {
|
||||
xhr = new XHRImpl();
|
||||
});
|
||||
|
||||
it('should resolve the Promise with the file content on success', inject([AsyncTestCompleter], (async) => {
|
||||
xhr.get(url200).then((text) => {
|
||||
expect(text.trim()).toEqual('<p>hey</p>');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should reject the Promise on failure', inject([AsyncTestCompleter], (async) => {
|
||||
PromiseWrapper.catchError(
|
||||
xhr.get(url404),
|
||||
(e) => {
|
||||
expect(e).toEqual(`Failed to load ${url404}`);
|
||||
async.done();
|
||||
}
|
||||
);
|
||||
}));
|
||||
});
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
import {
|
||||
AsyncTestCompleter,
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
describe,
|
||||
expect,
|
||||
iit,
|
||||
inject,
|
||||
it,
|
||||
xit
|
||||
} from 'angular2/test_lib';
|
||||
|
||||
import {XHRImpl} from 'angular2/src/services/xhr_impl';
|
||||
import {PromiseWrapper} from 'angular2/src/facade/async';
|
||||
|
||||
export function main() {
|
||||
describe('XHRImpl', () => {
|
||||
var xhr;
|
||||
var url200 = '/base/modules/angular2/test/services/static_assets/200.html';
|
||||
var url404 = '/base/modules/angular2/test/services/static_assets/404.html';
|
||||
|
||||
beforeEach(() => { xhr = new XHRImpl(); });
|
||||
|
||||
it('should resolve the Promise with the file content on success',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
xhr.get(url200).then((text) => {
|
||||
expect(text.trim()).toEqual('<p>hey</p>');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should reject the Promise on failure', inject([AsyncTestCompleter], (async) => {
|
||||
PromiseWrapper.catchError(xhr.get(url404), (e) => {
|
||||
expect(e).toEqual(`Failed to load ${url404}`);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
}
|
|
@ -23,7 +23,7 @@ module.exports = function makeNodeTree(destinationPath) {
|
|||
// the following code and tests are not compatible with CJS/node environment
|
||||
'angular2/test/core/zone/**',
|
||||
'angular2/test/test_lib/fake_async_spec.js',
|
||||
'angular2/test/services/xhr_impl_spec.js'
|
||||
'angular2/test/services/xhr_impl_spec.ts'
|
||||
]
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue