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