]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-configuration-list/rbd-configuration-list.component.spec.ts
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / block / rbd-configuration-list / rbd-configuration-list.component.spec.ts
1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2 import { FormsModule } from '@angular/forms';
3 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
4 import { RouterTestingModule } from '@angular/router/testing';
5
6 import { NgbDropdownModule, NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';
7 import { NgxDatatableModule } from '@swimlane/ngx-datatable';
8 import { ChartsModule } from 'ng2-charts';
9
10 import { ComponentsModule } from '~/app/shared/components/components.module';
11 import { RbdConfigurationEntry } from '~/app/shared/models/configuration';
12 import { FormatterService } from '~/app/shared/services/formatter.service';
13 import { RbdConfigurationService } from '~/app/shared/services/rbd-configuration.service';
14 import { SharedModule } from '~/app/shared/shared.module';
15 import { configureTestBed } from '~/testing/unit-test-helper';
16 import { RbdConfigurationListComponent } from './rbd-configuration-list.component';
17
18 describe('RbdConfigurationListComponent', () => {
19 let component: RbdConfigurationListComponent;
20 let fixture: ComponentFixture<RbdConfigurationListComponent>;
21
22 configureTestBed({
23 imports: [
24 BrowserAnimationsModule,
25 FormsModule,
26 NgxDatatableModule,
27 RouterTestingModule,
28 ComponentsModule,
29 NgbDropdownModule,
30 ChartsModule,
31 SharedModule,
32 NgbTooltipModule
33 ],
34 declarations: [RbdConfigurationListComponent],
35 providers: [FormatterService, RbdConfigurationService]
36 });
37
38 beforeEach(() => {
39 fixture = TestBed.createComponent(RbdConfigurationListComponent);
40 component = fixture.componentInstance;
41 component.data = [];
42 fixture.detectChanges();
43 });
44
45 it('should create', () => {
46 expect(component).toBeTruthy();
47 });
48
49 it('filters options out which are not defined in RbdConfigurationService', () => {
50 const fakeOption = { name: 'foo', source: 0, value: '50' } as RbdConfigurationEntry;
51 const realOption = {
52 name: 'rbd_qos_read_iops_burst',
53 source: 0,
54 value: '50'
55 } as RbdConfigurationEntry;
56
57 component.data = [fakeOption, realOption];
58 component.ngOnChanges();
59
60 expect(component.data.length).toBe(1);
61 expect(component.data.pop()).toBe(realOption);
62 });
63
64 it('should filter the source column by its piped value', () => {
65 const poolConfTable = component.poolConfTable;
66 poolConfTable.data = [
67 {
68 name: 'rbd_qos_read_iops_burst',
69 source: 0,
70 value: '50'
71 },
72 {
73 name: 'rbd_qos_read_iops_limit',
74 source: 1,
75 value: '50'
76 },
77 {
78 name: 'rbd_qos_write_iops_limit',
79 source: 0,
80 value: '100'
81 },
82 {
83 name: 'rbd_qos_write_iops_burst',
84 source: 2,
85 value: '100'
86 }
87 ];
88 const filter = (keyword: string) => {
89 poolConfTable.search = keyword;
90 poolConfTable.updateFilter();
91 return poolConfTable.rows;
92 };
93 expect(filter('').length).toBe(4);
94 expect(filter('source:global').length).toBe(2);
95 expect(filter('source:pool').length).toBe(1);
96 expect(filter('source:image').length).toBe(1);
97 expect(filter('source:zero').length).toBe(0);
98 });
99 });