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 {PromiseWrapper, Promise} from 'angular2/src/core/facade/async';
|
|
|
|
import {DateWrapper} from 'angular2/src/core/facade/lang';
|
2015-05-27 17:57:54 -04:00
|
|
|
|
|
|
|
import {Reporter, MultiReporter, bind, Injector, MeasureValues} from 'benchpress/common';
|
|
|
|
|
|
|
|
export function main() {
|
|
|
|
function createReporters(ids) {
|
2015-06-26 18:59:18 -04:00
|
|
|
var r = Injector.resolveAndCreate([
|
|
|
|
ListWrapper.map(ids, (id) => bind(id).toValue(new MockReporter(id))),
|
|
|
|
MultiReporter.createBindings(ids)
|
|
|
|
])
|
|
|
|
.get(MultiReporter);
|
|
|
|
return PromiseWrapper.resolve(r);
|
2015-05-27 17:57:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('multi reporter', () => {
|
|
|
|
|
|
|
|
it('should reportMeasureValues to all', inject([AsyncTestCompleter], (async) => {
|
|
|
|
var mv = new MeasureValues(0, DateWrapper.now(), {});
|
|
|
|
createReporters(['m1', 'm2'])
|
|
|
|
.then((r) => r.reportMeasureValues(mv))
|
|
|
|
.then((values) => {
|
|
|
|
|
|
|
|
expect(values).toEqual([{'id': 'm1', 'values': mv}, {'id': 'm2', 'values': mv}]);
|
|
|
|
async.done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should reportSample to call', inject([AsyncTestCompleter], (async) => {
|
|
|
|
var completeSample = [
|
|
|
|
new MeasureValues(0, DateWrapper.now(), {}),
|
|
|
|
new MeasureValues(1, DateWrapper.now(), {})
|
|
|
|
];
|
|
|
|
var validSample = [completeSample[1]];
|
|
|
|
|
|
|
|
createReporters(['m1', 'm2'])
|
|
|
|
.then((r) => r.reportSample(completeSample, validSample))
|
|
|
|
.then((values) => {
|
|
|
|
|
|
|
|
expect(values).toEqual([
|
|
|
|
{'id': 'm1', 'completeSample': completeSample, 'validSample': validSample},
|
|
|
|
{'id': 'm2', 'completeSample': completeSample, 'validSample': validSample}
|
|
|
|
]);
|
|
|
|
async.done();
|
|
|
|
})
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
class MockReporter extends Reporter {
|
|
|
|
constructor(private _id: string) { super(); }
|
|
|
|
|
2015-10-02 19:47:54 -04:00
|
|
|
reportMeasureValues(values: MeasureValues): Promise<{[key: string]: any}> {
|
2015-05-27 17:57:54 -04:00
|
|
|
return PromiseWrapper.resolve({'id': this._id, 'values': values});
|
|
|
|
}
|
|
|
|
|
2015-08-28 14:29:19 -04:00
|
|
|
reportSample(completeSample: MeasureValues[],
|
2015-10-02 19:47:54 -04:00
|
|
|
validSample: MeasureValues[]): Promise<{[key: string]: any}> {
|
2015-05-27 17:57:54 -04:00
|
|
|
return PromiseWrapper.resolve(
|
|
|
|
{'id': this._id, 'completeSample': completeSample, 'validSample': validSample});
|
|
|
|
}
|
|
|
|
}
|