1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { RouterTestingModule } from '@angular/router/testing';
5 import { ToastModule } from 'ng2-toastr';
6 import { of } from 'rxjs';
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';
17 describe('RbdTrashListComponent', () => {
18 let component: RbdTrashListComponent;
19 let fixture: ComponentFixture<RbdTrashListComponent>;
20 let summaryService: SummaryService;
21 let rbdService: RbdService;
24 declarations: [RbdTrashListComponent],
25 imports: [SharedModule, HttpClientTestingModule, RouterTestingModule, ToastModule.forRoot()],
26 providers: [TaskListService, RbdService]
30 fixture = TestBed.createComponent(RbdTrashListComponent);
31 component = fixture.componentInstance;
32 summaryService = TestBed.get(SummaryService);
33 rbdService = TestBed.get(RbdService);
34 fixture.detectChanges();
37 it('should create', () => {
38 expect(component).toBeTruthy();
41 it('should load trash images when summary is trigged', () => {
42 spyOn(rbdService, 'listTrash').and.callThrough();
44 summaryService['summaryDataSource'].next({ executingTasks: null });
45 expect(rbdService.listTrash).toHaveBeenCalled();
48 it('should call updateSelection', () => {
49 const selection = new CdTableSelection();
50 selection.selected = ['foo'];
53 expect(component.selection.hasSelection).toBeFalsy();
54 component.updateSelection(selection);
55 expect(component.selection.hasSelection).toBeTruthy();
58 describe('handling of executing tasks', () => {
61 const addImage = (id) => {
67 const addTask = (name: string, image_id: string) => {
68 const task = new ExecutingTask();
73 summaryService.addRunningTask(task);
76 const expectImageTasks = (image: any, executing: string) => {
77 expect(image.cdExecuting).toEqual(executing);
84 component.images = images;
85 summaryService['summaryDataSource'].next({ executingTasks: [] });
86 spyOn(rbdService, 'listTrash').and.callFake(() =>
87 of([{ poool_name: 'rbd', status: 1, value: images }])
89 fixture.detectChanges();
92 it('should gets all images without tasks', () => {
93 expect(component.images.length).toBe(2);
94 expect(component.images.every((image) => !image.cdExecuting)).toBeTruthy();