]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/services/task-manager.service.spec.ts
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / services / task-manager.service.spec.ts
CommitLineData
11fdf7f2
TL
1import { fakeAsync, TestBed, tick } from '@angular/core/testing';
2
f67539c2 3import _ from 'lodash';
11fdf7f2
TL
4import { BehaviorSubject } from 'rxjs';
5
f67539c2 6import { configureTestBed } from '~/testing/unit-test-helper';
11fdf7f2
TL
7import { SummaryService } from './summary.service';
8import { TaskManagerService } from './task-manager.service';
9
9f95a23c 10const summary: Record<string, any> = {
11fdf7f2
TL
11 executing_tasks: [],
12 health_status: 'HEALTH_OK',
13 mgr_id: 'x',
14 rbd_mirroring: { errors: 0, warnings: 0 },
15 rbd_pools: [],
16 have_mon_connection: true,
17 finished_tasks: [{ name: 'foo', metadata: {} }],
18 filesystems: [{ id: 1, name: 'cephfs_a' }]
19};
20
21export class SummaryServiceMock {
22 summaryDataSource = new BehaviorSubject(summary);
23 summaryData$ = this.summaryDataSource.asObservable();
24
25 refresh() {
26 this.summaryDataSource.next(summary);
27 }
9f95a23c 28 subscribe(call: any) {
11fdf7f2
TL
29 return this.summaryData$.subscribe(call);
30 }
31}
32
33describe('TaskManagerService', () => {
34 let taskManagerService: TaskManagerService;
35 let summaryService: any;
36 let called: boolean;
37
f6b5b4d7
TL
38 configureTestBed({
39 providers: [TaskManagerService, { provide: SummaryService, useClass: SummaryServiceMock }]
40 });
11fdf7f2
TL
41
42 beforeEach(() => {
f67539c2
TL
43 taskManagerService = TestBed.inject(TaskManagerService);
44 summaryService = TestBed.inject(SummaryService);
11fdf7f2
TL
45 called = false;
46 taskManagerService.subscribe('foo', {}, () => (called = true));
47 });
48
49 it('should be created', () => {
50 expect(taskManagerService).toBeTruthy();
51 });
52
53 it('should subscribe and be notified when task is finished', fakeAsync(() => {
54 expect(taskManagerService.subscriptions.length).toBe(1);
55 summaryService.refresh();
56 tick();
1911f103 57 taskManagerService.init(summaryService);
11fdf7f2
TL
58 expect(called).toEqual(true);
59 expect(taskManagerService.subscriptions).toEqual([]);
60 }));
61
62 it('should subscribe and process executing taks', fakeAsync(() => {
63 const original_subscriptions = _.cloneDeep(taskManagerService.subscriptions);
64 _.assign(summary, {
65 executing_tasks: [{ name: 'foo', metadata: {} }],
66 finished_tasks: []
67 });
68 summaryService.refresh();
69 tick();
70 expect(taskManagerService.subscriptions).toEqual(original_subscriptions);
71 }));
72});