From d0f5e656627ad2c2adf3768cf09038a647e12691 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stephan=20M=C3=BCller?= Date: Wed, 12 Dec 2018 12:07:14 +0100 Subject: [PATCH] mgr/dashboard: Cleanup of summary refresh test MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- .../shared/services/summary.service.spec.ts | 20 +++++++++++-------- .../app/shared/services/summary.service.ts | 17 +++------------- 2 files changed, 15 insertions(+), 22 deletions(-) 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 75bfdb0ed8734..86ea4e108976d 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 d90c16f74c742..a4397f85cba18 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(); -- 2.39.5