});
it('should call refresh', fakeAsync(() => {
- authStorageService.set('foobar');
- let result = false;
- summaryService.refresh();
- summaryService.subscribe(() => {
- result = true;
+ authStorageService.set('foobar', undefined, undefined);
+ const calledWith = [];
+ summaryService.subscribe((data) => {
+ calledWith.push(data);
});
- tick(5000);
+ expect(calledWith).toEqual([summary]);
+ summaryService.refresh();
+ expect(calledWith).toEqual([summary, summary]);
+ tick(10000);
+ expect(calledWith.length).toEqual(4);
+ // In order to not trigger setTimeout again,
+ // which would raise 'Error: 1 timer(s) still in the queue.'
spyOn(summaryService, 'refresh').and.callFake(() => true);
tick(5000);
- expect(result).toEqual(true);
}));
describe('Should test methods after first refresh', () => {
beforeEach(() => {
- authStorageService.set('foobar');
+ authStorageService.set('foobar', undefined, undefined);
summaryService.refresh();
});
/**
* Returns the current value of summaryData
- *
- * @returns {object}
- * @memberof SummaryService
*/
- getCurrentSummary() {
+ getCurrentSummary(): { [key: string]: any; executing_tasks: object[] } {
return this.summaryDataSource.getValue();
}
/**
* Subscribes to the summaryData,
* which is updated once every 5 seconds or when a new task is created.
- *
- * @param {(summary: any) => void} call
- * @param {(error: any) => void} error
- * @returns {Subscription}
- * @memberof SummaryService
*/
- subscribe(call: (summary: any) => void, error?: (error: any) => void): Subscription {
- return this.summaryData$.subscribe(call, error);
+ subscribe(next: (summary: any) => void, error?: (error: any) => void): Subscription {
+ return this.summaryData$.subscribe(next, error);
}
/**
* Inserts a newly created task to the local list of executing tasks.
* After that, it will automatically push that new information
* to all subscribers.
- *
- * @param {ExecutingTask} task
- * @memberof SummaryService
*/
addRunningTask(task: ExecutingTask) {
const current = this.summaryDataSource.getValue();