From: Stephan Müller Date: Wed, 12 Dec 2018 11:07:14 +0000 (+0100) Subject: mgr/dashboard: Cleanup of summary refresh test X-Git-Tag: v14.1.0~625^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F25504%2Fhead;p=ceph.git mgr/dashboard: Cleanup of summary refresh test Now the test is testing what it says. Additionally resolved typescript compiler issues in the file and removed not needed doc types in the corresponding service. Fixes: https://tracker.ceph.com/issues/37619 Signed-off-by: Stephan Müller --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/summary.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/summary.service.spec.ts index 75bfdb0ed873..86ea4e108976 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/summary.service.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/summary.service.spec.ts @@ -47,21 +47,25 @@ describe('SummaryService', () => { }); 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(); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/summary.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/summary.service.ts index d90c16f74c74..a4397f85cba1 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/summary.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/summary.service.ts @@ -40,34 +40,23 @@ export class SummaryService { /** * 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();