2016-08-03 15:32:26 -04:00
|
|
|
import {afterEach, AsyncTestCompleter, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2016-08-03 15:32:26 -04:00
|
|
|
import {isPresent, StringWrapper} from '@angular/facade/src/lang';
|
|
|
|
import {PromiseWrapper} from '@angular/facade/src/async';
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2016-06-02 20:30:40 -04:00
|
|
|
import {WebDriverExtension, ReflectiveInjector, Options} from 'benchpress/common';
|
2015-05-27 17:57:54 -04:00
|
|
|
|
|
|
|
export function main() {
|
2015-10-06 22:05:09 -04:00
|
|
|
function createExtension(ids: any[], caps) {
|
2015-06-26 18:59:18 -04:00
|
|
|
return PromiseWrapper.wrap(() => {
|
2016-04-14 15:35:24 -04:00
|
|
|
return ReflectiveInjector.resolveAndCreate([
|
2016-06-02 20:30:40 -04:00
|
|
|
ids.map((id) => { return {provide: id, useValue: new MockExtension(id)}}),
|
|
|
|
{provide: Options.CAPABILITIES, useValue: caps},
|
2016-04-14 15:35:24 -04:00
|
|
|
WebDriverExtension.bindTo(ids)
|
|
|
|
])
|
2015-06-26 18:59:18 -04:00
|
|
|
.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) => {
|
2016-04-12 12:40:37 -04:00
|
|
|
createExtension(['m1', 'm2', 'm3'], {'browser': 'm2'})
|
|
|
|
.then((m) => {
|
|
|
|
expect(m.id).toEqual('m2');
|
|
|
|
async.done();
|
|
|
|
});
|
2015-05-27 17:57:54 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|