2015-11-17 15:24:36 -08:00
|
|
|
import {Map, MapWrapper, ListWrapper} from 'angular2/src/facade/collection';
|
|
|
|
import {CONST, CONST_EXPR, global, isPresent} from 'angular2/src/facade/lang';
|
|
|
|
import {BaseException, WrappedException} from 'angular2/src/facade/exceptions';
|
|
|
|
import {PromiseWrapper, ObservableWrapper} from 'angular2/src/facade/async';
|
|
|
|
|
|
|
|
import {DOM} from 'angular2/src/core/dom/dom_adapter';
|
|
|
|
|
2015-09-02 15:19:26 -07:00
|
|
|
import {
|
2015-11-17 15:24:36 -08:00
|
|
|
Injectable,
|
2015-09-02 15:19:26 -07:00
|
|
|
TestabilityRegistry,
|
|
|
|
Testability,
|
|
|
|
GetTestability,
|
|
|
|
setTestabilityGetter
|
2015-11-17 15:24:36 -08:00
|
|
|
} from 'angular2/core';
|
2015-03-23 16:46:18 -07:00
|
|
|
|
|
|
|
class PublicTestability {
|
2015-10-28 15:04:55 -07:00
|
|
|
/** @internal */
|
2015-05-20 09:48:15 -07:00
|
|
|
_testability: Testability;
|
2015-03-23 16:46:18 -07:00
|
|
|
|
2015-05-20 09:48:15 -07:00
|
|
|
constructor(testability: Testability) { this._testability = testability; }
|
2015-03-23 16:46:18 -07:00
|
|
|
|
2015-08-27 17:44:59 +02:00
|
|
|
isStable(): boolean { return this._testability.isStable(); }
|
|
|
|
|
2015-05-20 09:48:15 -07:00
|
|
|
whenStable(callback: Function) { this._testability.whenStable(callback); }
|
2015-03-23 16:46:18 -07:00
|
|
|
|
2015-10-10 22:11:13 -07:00
|
|
|
findBindings(using: any, provider: string, exactMatch: boolean): any[] {
|
|
|
|
return this.findProviders(using, provider, exactMatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
findProviders(using: any, provider: string, exactMatch: boolean): any[] {
|
|
|
|
return this._testability.findBindings(using, provider, exactMatch);
|
2015-03-23 16:46:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-02 15:19:26 -07:00
|
|
|
export class BrowserGetTestability implements GetTestability {
|
|
|
|
static init() { setTestabilityGetter(new BrowserGetTestability()); }
|
|
|
|
|
|
|
|
addToWindow(registry: TestabilityRegistry): void {
|
2015-11-17 15:24:36 -08:00
|
|
|
global.getAngularTestability = (elem: any, findInAncestors: boolean = true) => {
|
2015-10-28 08:59:19 +01:00
|
|
|
var testability = registry.findTestabilityInTree(elem, findInAncestors);
|
|
|
|
if (testability == null) {
|
|
|
|
throw new Error('Could not find testability for element.');
|
|
|
|
}
|
|
|
|
return new PublicTestability(testability);
|
|
|
|
};
|
2015-11-17 15:24:36 -08:00
|
|
|
|
|
|
|
global.getAllAngularTestabilities = () => {
|
2015-07-30 15:51:06 -07:00
|
|
|
var testabilities = registry.getAllTestabilities();
|
|
|
|
return testabilities.map((testability) => { return new PublicTestability(testability); });
|
|
|
|
};
|
2015-03-23 16:46:18 -07:00
|
|
|
}
|
2015-11-17 15:24:36 -08:00
|
|
|
|
|
|
|
findTestabilityInTree(registry: TestabilityRegistry, elem: any,
|
|
|
|
findInAncestors: boolean): Testability {
|
|
|
|
if (elem == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
var t = registry.getTestability(elem);
|
|
|
|
if (isPresent(t)) {
|
|
|
|
return t;
|
|
|
|
} else if (!findInAncestors) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (DOM.isShadowRoot(elem)) {
|
|
|
|
return this.findTestabilityInTree(registry, DOM.getHost(elem), true);
|
|
|
|
}
|
|
|
|
return this.findTestabilityInTree(registry, DOM.parentElement(elem), true);
|
|
|
|
}
|
2015-03-23 16:46:18 -07:00
|
|
|
}
|