refactor(browser): merge static & dynamic platforms
This commit is contained in:
@ -1,16 +0,0 @@
|
||||
import 'dart:js' as js;
|
||||
|
||||
void setTemplateCache(Map cache) {
|
||||
if (cache == null) {
|
||||
if (js.context.hasProperty(r'$templateCache')) {
|
||||
js.context.deleteProperty(r'$templateCache');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
js.JsObject jsMap = new js.JsObject(js.context['Object']);
|
||||
for (String key in cache.keys) {
|
||||
jsMap[key] = cache[key];
|
||||
}
|
||||
js.context[r'$templateCache'] = jsMap;
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
export function setTemplateCache(cache): void {
|
||||
(<any>window).$templateCache = cache;
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
import {Component, provide} from '@angular/core';
|
||||
import {UrlResolver, XHR} from '@angular/compiler';
|
||||
import {
|
||||
beforeEach,
|
||||
beforeEachProviders,
|
||||
ddescribe,
|
||||
describe,
|
||||
iit,
|
||||
inject,
|
||||
it,
|
||||
xit
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
import {expect} from '@angular/platform-browser/testing';
|
||||
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
|
||||
import {
|
||||
fakeAsync,
|
||||
flushMicrotasks,
|
||||
Log,
|
||||
tick,
|
||||
} from '@angular/core/testing';
|
||||
import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing';
|
||||
import {BaseException} from '../../src/facade/exceptions';
|
||||
import {CachedXHR} from '../../src/xhr/xhr_cache';
|
||||
import {setTemplateCache} from './xhr_cache_setter';
|
||||
|
||||
export function main() {
|
||||
describe('CachedXHR', () => {
|
||||
var xhr: CachedXHR;
|
||||
|
||||
function createCachedXHR(): CachedXHR {
|
||||
setTemplateCache({'test.html': '<div>Hello</div>'});
|
||||
return new CachedXHR();
|
||||
}
|
||||
beforeEachProviders(() => [
|
||||
provide(UrlResolver, {useClass: TestUrlResolver}),
|
||||
provide(XHR, {useFactory: createCachedXHR})
|
||||
]);
|
||||
|
||||
it('should throw exception if $templateCache is not found', () => {
|
||||
setTemplateCache(null);
|
||||
expect(() => { xhr = new CachedXHR(); })
|
||||
.toThrowErrorWith('CachedXHR: Template cache was not found in $templateCache.');
|
||||
});
|
||||
|
||||
it('should resolve the Promise with the cached file content on success',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
setTemplateCache({'test.html': '<div>Hello</div>'});
|
||||
xhr = new CachedXHR();
|
||||
xhr.get('test.html')
|
||||
.then((text) => {
|
||||
expect(text).toEqual('<div>Hello</div>');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should reject the Promise on failure', inject([AsyncTestCompleter], (async) => {
|
||||
xhr = new CachedXHR();
|
||||
xhr.get('unknown.html')
|
||||
.then((text) => { throw new BaseException('Not expected to succeed.'); })
|
||||
.catch((error) => { async.done(); });
|
||||
}));
|
||||
|
||||
it('should allow fakeAsync Tests to load components with templateUrl synchronously',
|
||||
fakeAsync(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||
let fixture = tcb.createFakeAsync(TestComponent);
|
||||
|
||||
// This should initialize the fixture.
|
||||
tick();
|
||||
|
||||
expect(fixture.debugElement.children[0].nativeElement).toHaveText('Hello');
|
||||
})));
|
||||
});
|
||||
}
|
||||
|
||||
@Component({selector: 'test-cmp', templateUrl: 'test.html'})
|
||||
class TestComponent {
|
||||
}
|
||||
|
||||
class TestUrlResolver extends UrlResolver {
|
||||
resolve(baseUrl: string, url: string): string {
|
||||
// Don't use baseUrl to get the same URL as templateUrl.
|
||||
// This is to remove any difference between Dart and TS tests.
|
||||
return url;
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
import {
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
describe,
|
||||
expect,
|
||||
iit,
|
||||
inject,
|
||||
it,
|
||||
xit
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
|
||||
import {XHRImpl} from '../../src/xhr/xhr_impl';
|
||||
import {PromiseWrapper} from '../../src/facade/async';
|
||||
import {IS_DART} from '../../src/facade/lang';
|
||||
|
||||
export function main() {
|
||||
describe('XHRImpl', () => {
|
||||
var xhr: XHRImpl;
|
||||
|
||||
// TODO(juliemr): This file currently won't work with dart unit tests run using
|
||||
// exclusive it or describe (iit or ddescribe). This is because when
|
||||
// pub run test is executed against this specific file the relative paths
|
||||
// will be relative to here, so url200 should look like
|
||||
// static_assets/200.html.
|
||||
// We currently have no way of detecting this.
|
||||
var urlBase = IS_DART ? '' : '/base/modules/@angular/';
|
||||
var url200 = urlBase + 'platform-browser-dynamic/test/browser/static_assets/200.html';
|
||||
var url404 = '/bad/path/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();
|
||||
});
|
||||
}), 10000);
|
||||
|
||||
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();
|
||||
return null;
|
||||
});
|
||||
}), 10000);
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user