]> 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
import 15.2.4
[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 { NgxDatatableModule } from '@swimlane/ngx-datatable';
7 import { ChartsModule } from 'ng2-charts';
8 import { AlertModule } from 'ngx-bootstrap/alert';
9 import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
10 import { PopoverModule } from 'ngx-bootstrap/popover';
11
12 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
13 import { TableComponent } from '../../../shared/datatable/table/table.component';
14
15 import { ComponentsModule } from '../../../shared/components/components.module';
16 import { RbdConfigurationEntry } from '../../../shared/models/configuration';
17 import { PipesModule } from '../../../shared/pipes/pipes.module';
18 import { FormatterService } from '../../../shared/services/formatter.service';
19 import { RbdConfigurationService } from '../../../shared/services/rbd-configuration.service';
20 import { RbdConfigurationListComponent } from './rbd-configuration-list.component';
21
22 describe('RbdConfigurationListComponent', () => {
23 let component: RbdConfigurationListComponent;
24 let fixture: ComponentFixture<RbdConfigurationListComponent>;
25
26 configureTestBed({
27 imports: [
28 BrowserAnimationsModule,
29 FormsModule,
30 NgxDatatableModule,
31 RouterTestingModule,
32 ComponentsModule,
33 AlertModule,
34 BsDropdownModule.forRoot(),
35 ChartsModule,
36 PipesModule,
37 PopoverModule
38 ],
39 declarations: [RbdConfigurationListComponent, TableComponent],
40 providers: [FormatterService, RbdConfigurationService, i18nProviders]
41 });
42
43 beforeEach(() => {
44 fixture = TestBed.createComponent(RbdConfigurationListComponent);
45 component = fixture.componentInstance;
46 component.data = [];
47 fixture.detectChanges();
48 });
49
50 it('should create', () => {
51 expect(component).toBeTruthy();
52 });
53
54 it('filters options out which are not defined in RbdConfigurationService', () => {
55 const fakeOption = { name: 'foo', source: 0, value: '50' } as RbdConfigurationEntry;
56 const realOption = {
57 name: 'rbd_qos_read_iops_burst',
58 source: 0,
59 value: '50'
60 } as RbdConfigurationEntry;
61
62 component.data = [fakeOption, realOption];
63 component.ngOnChanges();
64
65 expect(component.data.length).toBe(1);
66 expect(component.data.pop()).toBe(realOption);
67 });
68
69 it('should filter the source column by its piped value', () => {
70 const poolConfTable = component.poolConfTable;
71 poolConfTable.data = [
72 {
73 name: 'rbd_qos_read_iops_burst',
74 source: 0,
75 value: '50'
76 },
77 {
78 name: 'rbd_qos_read_iops_limit',
79 source: 1,
80 value: '50'
81 },
82 {
83 name: 'rbd_qos_write_iops_limit',
84 source: 0,
85 value: '100'
86 },
87 {
88 name: 'rbd_qos_write_iops_burst',
89 source: 2,
90 value: '100'
91 }
92 ];
93 const filter = (keyword: string) => {
94 poolConfTable.search = keyword;
95 poolConfTable.updateFilter();
96 return poolConfTable.rows;
97 };
98 expect(filter('').length).toBe(4);
99 expect(filter('source:global').length).toBe(2);
100 expect(filter('source:pool').length).toBe(1);
101 expect(filter('source:image').length).toBe(1);
102 expect(filter('source:zero').length).toBe(0);
103 });
104 });