]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-trash-list/rbd-trash-list.component.spec.ts
import ceph 14.2.5
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / block / rbd-trash-list / rbd-trash-list.component.spec.ts
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 { ToastrModule } from 'ngx-toastr';
6 import { of } from 'rxjs';
7
8 import { By } from '@angular/platform-browser';
9 import {
10 configureTestBed,
11 expectItemTasks,
12 i18nProviders
13 } from '../../../../testing/unit-test-helper';
14 import { RbdService } from '../../../shared/api/rbd.service';
15 import { CdTableSelection } from '../../../shared/models/cd-table-selection';
16 import { ExecutingTask } from '../../../shared/models/executing-task';
17 import { SummaryService } from '../../../shared/services/summary.service';
18 import { TaskListService } from '../../../shared/services/task-list.service';
19 import { SharedModule } from '../../../shared/shared.module';
20 import { RbdTrashListComponent } from './rbd-trash-list.component';
21
22 describe('RbdTrashListComponent', () => {
23 let component: RbdTrashListComponent;
24 let fixture: ComponentFixture<RbdTrashListComponent>;
25 let summaryService: SummaryService;
26 let rbdService: RbdService;
27
28 configureTestBed({
29 declarations: [RbdTrashListComponent],
30 imports: [SharedModule, HttpClientTestingModule, RouterTestingModule, ToastrModule.forRoot()],
31 providers: [TaskListService, i18nProviders]
32 });
33
34 beforeEach(() => {
35 fixture = TestBed.createComponent(RbdTrashListComponent);
36 component = fixture.componentInstance;
37 summaryService = TestBed.get(SummaryService);
38 rbdService = TestBed.get(RbdService);
39 fixture.detectChanges();
40 });
41
42 it('should create', () => {
43 expect(component).toBeTruthy();
44 });
45
46 it('should load trash images when summary is trigged', () => {
47 spyOn(rbdService, 'listTrash').and.callThrough();
48
49 summaryService['summaryDataSource'].next({ executingTasks: null });
50 expect(rbdService.listTrash).toHaveBeenCalled();
51 });
52
53 it('should call updateSelection', () => {
54 const selection = new CdTableSelection();
55 selection.selected = ['foo'];
56 selection.update();
57
58 expect(component.selection.hasSelection).toBeFalsy();
59 component.updateSelection(selection);
60 expect(component.selection.hasSelection).toBeTruthy();
61 });
62
63 describe('handling of executing tasks', () => {
64 let images: any[];
65
66 const addImage = (id) => {
67 images.push({
68 id: id
69 });
70 };
71
72 const addTask = (name: string, image_id: string) => {
73 const task = new ExecutingTask();
74 task.name = name;
75 task.metadata = {
76 image_id: image_id
77 };
78 summaryService.addRunningTask(task);
79 };
80
81 beforeEach(() => {
82 images = [];
83 addImage('1');
84 addImage('2');
85 component.images = images;
86 summaryService['summaryDataSource'].next({ executingTasks: [] });
87 spyOn(rbdService, 'listTrash').and.callFake(() =>
88 of([{ poool_name: 'rbd', status: 1, value: images }])
89 );
90 fixture.detectChanges();
91 });
92
93 it('should gets all images without tasks', () => {
94 expect(component.images.length).toBe(2);
95 expect(component.images.every((image) => !image.cdExecuting)).toBeTruthy();
96 });
97
98 it('should show when an existing image is being modified', () => {
99 addTask('rbd/trash/remove', '1');
100 addTask('rbd/trash/restore', '2');
101 expect(component.images.length).toBe(2);
102 expectItemTasks(component.images[0], 'Deleting');
103 expectItemTasks(component.images[1], 'Restoring');
104 });
105 });
106
107 describe('display purge button', () => {
108 beforeEach(() => {});
109
110 it('should show button with delete permission', () => {
111 component.permission = {
112 read: true,
113 create: true,
114 delete: true,
115 update: true
116 };
117 fixture.detectChanges();
118
119 const purge = fixture.debugElement.query(By.css('.table-actions button .fa-times'));
120 expect(purge).not.toBeNull();
121 });
122
123 it('should remove button without delete permission', () => {
124 component.permission = {
125 read: true,
126 create: true,
127 delete: false,
128 update: true
129 };
130 fixture.detectChanges();
131
132 const purge = fixture.debugElement.query(By.css('.table-actions button .fa-times'));
133 expect(purge).toBeNull();
134 });
135 });
136 });