feat(test): find testabilities across dart js applications
Find angular testability objects across different dart js contexts by registering each application in a global array and interrogating each for testabilities. Closes #3611
This commit is contained in:
parent
64ebf278c0
commit
1d65b38b28
|
@ -10,17 +10,8 @@ import 'dart:js' as js;
|
||||||
// Proxies a Dart function that accepts up to 10 parameters.
|
// Proxies a Dart function that accepts up to 10 parameters.
|
||||||
js.JsFunction _jsFunction(Function fn) {
|
js.JsFunction _jsFunction(Function fn) {
|
||||||
const Object X = __varargSentinel;
|
const Object X = __varargSentinel;
|
||||||
return new js.JsFunction.withThis((thisArg,
|
return new js.JsFunction.withThis((thisArg, [o1 = X, o2 = X, o3 = X, o4 = X,
|
||||||
[o1 = X,
|
o5 = X, o6 = X, o7 = X, o8 = X, o9 = X, o10 = X]) {
|
||||||
o2 = X,
|
|
||||||
o3 = X,
|
|
||||||
o4 = X,
|
|
||||||
o5 = X,
|
|
||||||
o6 = X,
|
|
||||||
o7 = X,
|
|
||||||
o8 = X,
|
|
||||||
o9 = X,
|
|
||||||
o10 = X]) {
|
|
||||||
return __invokeFn(fn, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10);
|
return __invokeFn(fn, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -91,19 +82,46 @@ class PublicTestability implements _JsObjectProxyable {
|
||||||
|
|
||||||
class GetTestability {
|
class GetTestability {
|
||||||
static addToWindow(TestabilityRegistry registry) {
|
static addToWindow(TestabilityRegistry registry) {
|
||||||
|
var jsRegistry = js.context['ngTestabilityRegistries'];
|
||||||
|
if (jsRegistry == null) {
|
||||||
|
js.context['ngTestabilityRegistries'] = jsRegistry = new js.JsArray();
|
||||||
js.context['getAngularTestability'] = _jsify((Element elem,
|
js.context['getAngularTestability'] = _jsify((Element elem,
|
||||||
[bool findInAncestors = true]) {
|
[bool findInAncestors = true]) {
|
||||||
Testability testability = registry.findTestabilityInTree(elem, findInAncestors);
|
var registry = js.context['ngTestabilityRegistries'];
|
||||||
if (testability == null) {
|
for (int i = 0; i < registry.length; i++) {
|
||||||
throw 'Could not find testability for element.';
|
var result = registry[i].callMethod(
|
||||||
|
'getAngularTestability', [elem, findInAncestors]);
|
||||||
|
if (result != null) return result;
|
||||||
}
|
}
|
||||||
return _jsify(new PublicTestability(testability));
|
throw 'Could not find testability for element.';
|
||||||
});
|
});
|
||||||
js.context['getAllAngularTestabilities'] = _jsify(() {
|
js.context['getAllAngularTestabilities'] = _jsify(() {
|
||||||
List<Testability> testabilities = registry.getAllTestabilities();
|
var registry = js.context['ngTestabilityRegistries'];
|
||||||
var publicTestabilities = testabilities
|
var result = [];
|
||||||
|
for (int i = 0; i < registry.length; i++) {
|
||||||
|
var testabilities =
|
||||||
|
registry[i].callMethod('getAllAngularTestabilities');
|
||||||
|
if (testabilities != null) result.addAll(testabilities);
|
||||||
|
}
|
||||||
|
return _jsify(result);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
jsRegistry.add(_createRegistry(registry));
|
||||||
|
}
|
||||||
|
|
||||||
|
static js.JsObject _createRegistry(TestabilityRegistry registry) {
|
||||||
|
var object = new js.JsObject(js.context['Object']);
|
||||||
|
object['getAngularTestability'] = _jsify((Element elem,
|
||||||
|
bool findInAncestors) {
|
||||||
|
var testability = registry.findTestabilityInTree(elem, findInAncestors);
|
||||||
|
return _jsify(new PublicTestability(testability));
|
||||||
|
});
|
||||||
|
object['getAllAngularTestabilities'] = _jsify(() {
|
||||||
|
var publicTestabilities = registry
|
||||||
|
.getAllTestabilities()
|
||||||
.map((testability) => new PublicTestability(testability));
|
.map((testability) => new PublicTestability(testability));
|
||||||
return _jsify(publicTestabilities);
|
return _jsify(publicTestabilities);
|
||||||
});
|
});
|
||||||
|
return object;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue