]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
1bb18d2bdaecbddff71c6715988abeb5192a6810
[ceph.git] /
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { RouterTestingModule } from '@angular/router/testing';
4
5 import { ToastModule } from 'ng2-toastr';
6 import { of } from 'rxjs';
7
8 import { configureTestBed } from '../../../../testing/unit-test-helper';
9 import { RbdService } from '../../../shared/api/rbd.service';
10 import { CdTableSelection } from '../../../shared/models/cd-table-selection';
11 import { ExecutingTask } from '../../../shared/models/executing-task';
12 import { SummaryService } from '../../../shared/services/summary.service';
13 import { TaskListService } from '../../../shared/services/task-list.service';
14 import { SharedModule } from '../../../shared/shared.module';
15 import { RbdTrashListComponent } from './rbd-trash-list.component';
16
17 describe('RbdTrashListComponent', () => {
18   let component: RbdTrashListComponent;
19   let fixture: ComponentFixture<RbdTrashListComponent>;
20   let summaryService: SummaryService;
21   let rbdService: RbdService;
22
23   configureTestBed({
24     declarations: [RbdTrashListComponent],
25     imports: [SharedModule, HttpClientTestingModule, RouterTestingModule, ToastModule.forRoot()],
26     providers: [TaskListService, RbdService]
27   });
28
29   beforeEach(() => {
30     fixture = TestBed.createComponent(RbdTrashListComponent);
31     component = fixture.componentInstance;
32     summaryService = TestBed.get(SummaryService);
33     rbdService = TestBed.get(RbdService);
34     fixture.detectChanges();
35   });
36
37   it('should create', () => {
38     expect(component).toBeTruthy();
39   });
40
41   it('should load trash images when summary is trigged', () => {
42     spyOn(rbdService, 'listTrash').and.callThrough();
43
44     summaryService['summaryDataSource'].next({ executingTasks: null });
45     expect(rbdService.listTrash).toHaveBeenCalled();
46   });
47
48   it('should call updateSelection', () => {
49     const selection = new CdTableSelection();
50     selection.selected = ['foo'];
51     selection.update();
52
53     expect(component.selection.hasSelection).toBeFalsy();
54     component.updateSelection(selection);
55     expect(component.selection.hasSelection).toBeTruthy();
56   });
57
58   describe('handling of executing tasks', () => {
59     let images: any[];
60
61     const addImage = (id) => {
62       images.push({
63         id: id
64       });
65     };
66
67     const addTask = (name: string, image_id: string) => {
68       const task = new ExecutingTask();
69       task.name = name;
70       task.metadata = {
71         image_id: image_id
72       };
73       summaryService.addRunningTask(task);
74     };
75
76     const expectImageTasks = (image: any, executing: string) => {
77       expect(image.cdExecuting).toEqual(executing);
78     };
79
80     beforeEach(() => {
81       images = [];
82       addImage('1');
83       addImage('2');
84       component.images = images;
85       summaryService['summaryDataSource'].next({ executingTasks: [] });
86       spyOn(rbdService, 'listTrash').and.callFake(() =>
87         of([{ poool_name: 'rbd', status: 1, value: images }])
88       );
89       fixture.detectChanges();
90     });
91
92     it('should gets all images without tasks', () => {
93       expect(component.images.length).toBe(2);
94       expect(component.images.every((image) => !image.cdExecuting)).toBeTruthy();
95     });
96   });
97 });