2015-05-27 17:57:54 -04:00
|
|
|
import {
|
|
|
|
afterEach,
|
|
|
|
AsyncTestCompleter,
|
|
|
|
beforeEach,
|
|
|
|
ddescribe,
|
|
|
|
describe,
|
|
|
|
expect,
|
|
|
|
iit,
|
|
|
|
inject,
|
|
|
|
it,
|
|
|
|
xit,
|
|
|
|
} from 'angular2/test_lib';
|
|
|
|
|
2015-10-02 19:47:54 -04:00
|
|
|
import {ListWrapper} from 'angular2/src/core/facade/collection';
|
2015-08-20 17:28:25 -04:00
|
|
|
import {isPresent, StringWrapper} from 'angular2/src/core/facade/lang';
|
|
|
|
import {PromiseWrapper} from 'angular2/src/core/facade/async';
|
2015-05-27 17:57:54 -04:00
|
|
|
|
|
|
|
import {WebDriverExtension, bind, Injector, Options} from 'benchpress/common';
|
|
|
|
|
|
|
|
export function main() {
|
|
|
|
function createExtension(ids, caps) {
|
2015-06-26 18:59:18 -04:00
|
|
|
return PromiseWrapper.wrap(() => {
|
|
|
|
return Injector.resolveAndCreate([
|
|
|
|
ListWrapper.map(ids, (id) => bind(id).toValue(new MockExtension(id))),
|
|
|
|
bind(Options.CAPABILITIES).toValue(caps),
|
|
|
|
WebDriverExtension.bindTo(ids)
|
|
|
|
])
|
|
|
|
.get(WebDriverExtension);
|
|
|
|
});
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('WebDriverExtension.bindTo', () => {
|
|
|
|
|
|
|
|
it('should bind the extension that matches the capabilities',
|
|
|
|
inject([AsyncTestCompleter], (async) => {
|
|
|
|
createExtension(['m1', 'm2', 'm3'], {'browser': 'm2'})
|
|
|
|
.then((m) => {
|
|
|
|
expect(m.id).toEqual('m2');
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should throw if there is no match', inject([AsyncTestCompleter], (async) => {
|
|
|
|
PromiseWrapper.catchError(createExtension(['m1'], {'browser': 'm2'}), (err) => {
|
|
|
|
expect(isPresent(err)).toBe(true);
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
class MockExtension extends WebDriverExtension {
|
|
|
|
id: string;
|
|
|
|
|
|
|
|
constructor(id) {
|
|
|
|
super();
|
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
|
2015-10-02 19:47:54 -04:00
|
|
|
supports(capabilities: {[key: string]: any}): boolean {
|
2015-05-27 17:57:54 -04:00
|
|
|
return StringWrapper.equals(capabilities['browser'], this.id);
|
|
|
|
}
|
|
|
|
}
|