2016-08-03 18:00:07 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2016-08-03 18:00:07 -04:00
|
|
|
import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
|
2016-08-03 15:32:26 -04:00
|
|
|
import {PromiseWrapper} from '@angular/facade/src/async';
|
|
|
|
import {DateWrapper} from '@angular/facade/src/lang';
|
2016-08-03 18:00:07 -04:00
|
|
|
import {MeasureValues, MultiReporter, ReflectiveInjector, Reporter} from 'benchpress/common';
|
2015-05-27 17:57:54 -04:00
|
|
|
|
|
|
|
export function main() {
|
2015-10-06 22:05:09 -04:00
|
|
|
function createReporters(ids: any[]) {
|
2016-08-03 18:00:07 -04:00
|
|
|
var r = ReflectiveInjector
|
|
|
|
.resolveAndCreate([
|
|
|
|
ids.map(id => { return {provide: id, useValue: new MockReporter(id)}; }),
|
|
|
|
MultiReporter.createBindings(ids)
|
|
|
|
])
|
2015-06-26 18:59:18 -04:00
|
|
|
.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(), {});
|
2016-08-03 18:00:07 -04:00
|
|
|
createReporters(['m1', 'm2']).then((r) => r.reportMeasureValues(mv)).then((values) => {
|
2015-05-27 17:57:54 -04:00
|
|
|
|
2016-08-03 18:00:07 -04:00
|
|
|
expect(values).toEqual([{'id': 'm1', 'values': mv}, {'id': 'm2', 'values': mv}]);
|
|
|
|
async.done();
|
|
|
|
});
|
2015-05-27 17:57:54 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
it('should reportSample to call', inject([AsyncTestCompleter], (async) => {
|
|
|
|
var completeSample = [
|
2016-08-03 18:00:07 -04:00
|
|
|
new MeasureValues(0, DateWrapper.now(), {}), new MeasureValues(1, DateWrapper.now(), {})
|
2015-05-27 17:57:54 -04:00
|
|
|
];
|
|
|
|
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();
|
2016-08-03 18:00:07 -04:00
|
|
|
});
|
2015-05-27 17:57:54 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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});
|
|
|
|
}
|
|
|
|
|
2016-08-03 18:00:07 -04:00
|
|
|
reportSample(completeSample: MeasureValues[], validSample: MeasureValues[]):
|
|
|
|
Promise<{[key: string]: any}> {
|
2015-05-27 17:57:54 -04:00
|
|
|
return PromiseWrapper.resolve(
|
|
|
|
{'id': this._id, 'completeSample': completeSample, 'validSample': validSample});
|
|
|
|
}
|
|
|
|
}
|