]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/task-manager/task-manager.component.spec.ts
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / core / navigation / task-manager / task-manager.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 { PopoverModule } from 'ngx-bootstrap/popover';
6
7 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
8 import { ExecutingTask } from '../../../shared/models/executing-task';
9 import { FinishedTask } from '../../../shared/models/finished-task';
10 import { SharedModule } from '../../../shared/shared.module';
11 import { TaskManagerComponent } from './task-manager.component';
12
13 describe('TaskManagerComponent', () => {
14 let component: TaskManagerComponent;
15 let fixture: ComponentFixture<TaskManagerComponent>;
16 const tasks = {
17 executing: [],
18 finished: []
19 };
20
21 configureTestBed({
22 imports: [SharedModule, PopoverModule.forRoot(), HttpClientTestingModule, RouterTestingModule],
23 declarations: [TaskManagerComponent],
24 providers: [i18nProviders]
25 });
26
27 beforeEach(() => {
28 fixture = TestBed.createComponent(TaskManagerComponent);
29 component = fixture.componentInstance;
30 fixture.detectChanges();
31 tasks.executing = [
32 new ExecutingTask('rbd/delete', {
33 pool_name: 'somePool',
34 image_name: 'someImage'
35 })
36 ];
37 tasks.finished = [
38 new FinishedTask('rbd/copy', {
39 dest_pool_name: 'somePool',
40 dest_image_name: 'someImage'
41 }),
42 new FinishedTask('rbd/clone', {
43 child_pool_name: 'somePool',
44 child_image_name: 'someImage'
45 })
46 ];
47 tasks.finished[1].success = false;
48 tasks.finished[1].exception = { code: 17 };
49 });
50
51 it('should create', () => {
52 expect(component).toBeTruthy();
53 });
54
55 it('should get executing message for task', () => {
56 component._handleTasks(tasks.executing, []);
57 expect(component.executingTasks.length).toBe(1);
58 expect(component.executingTasks[0].description).toBe(`Deleting RBD 'somePool/someImage'`);
59 });
60
61 it('should get finished message for successful task', () => {
62 component._handleTasks([], tasks.finished);
63 expect(component.finishedTasks.length).toBe(2);
64 expect(component.finishedTasks[0].description).toBe(`Copied RBD 'somePool/someImage'`);
65 expect(component.finishedTasks[0].errorMessage).toBe(undefined);
66 });
67
68 it('should get failed message for finished task', () => {
69 component._handleTasks([], tasks.finished);
70 expect(component.finishedTasks.length).toBe(2);
71 expect(component.finishedTasks[1].description).toBe(`Failed to clone RBD 'somePool/someImage'`);
72 expect(component.finishedTasks[1].errorMessage).toBe(
73 `Name is already used by RBD 'somePool/someImage'.`
74 );
75 });
76
77 it('should get an empty hour glass with only finished tasks', () => {
78 component._setIcon(0);
79 expect(component.icon).toBe('fa-hourglass-o');
80 });
81
82 it('should get a nearly empty hour glass with executing tasks', () => {
83 component._setIcon(10);
84 expect(component.icon).toBe('fa-hourglass-start');
85 });
86 });