]> git.proxmox.com Git - ceph.git/blame - 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
CommitLineData
11fdf7f2
TL
1import { ComponentFixture, TestBed } from '@angular/core/testing';
2import { FormsModule } from '@angular/forms';
e306af50 3import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
11fdf7f2
TL
4import { RouterTestingModule } from '@angular/router/testing';
5
6import { NgxDatatableModule } from '@swimlane/ngx-datatable';
7import { ChartsModule } from 'ng2-charts';
8import { AlertModule } from 'ngx-bootstrap/alert';
9f95a23c
TL
9import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
10import { PopoverModule } from 'ngx-bootstrap/popover';
11fdf7f2
TL
11
12import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
11fdf7f2 13import { TableComponent } from '../../../shared/datatable/table/table.component';
9f95a23c
TL
14
15import { ComponentsModule } from '../../../shared/components/components.module';
11fdf7f2
TL
16import { RbdConfigurationEntry } from '../../../shared/models/configuration';
17import { PipesModule } from '../../../shared/pipes/pipes.module';
18import { FormatterService } from '../../../shared/services/formatter.service';
19import { RbdConfigurationService } from '../../../shared/services/rbd-configuration.service';
20import { RbdConfigurationListComponent } from './rbd-configuration-list.component';
21
22describe('RbdConfigurationListComponent', () => {
23 let component: RbdConfigurationListComponent;
24 let fixture: ComponentFixture<RbdConfigurationListComponent>;
25
26 configureTestBed({
27 imports: [
e306af50 28 BrowserAnimationsModule,
11fdf7f2
TL
29 FormsModule,
30 NgxDatatableModule,
31 RouterTestingModule,
9f95a23c 32 ComponentsModule,
11fdf7f2 33 AlertModule,
9f95a23c 34 BsDropdownModule.forRoot(),
11fdf7f2 35 ChartsModule,
9f95a23c
TL
36 PipesModule,
37 PopoverModule
11fdf7f2 38 ],
9f95a23c 39 declarations: [RbdConfigurationListComponent, TableComponent],
11fdf7f2
TL
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 ];
9f95a23c 93 const filter = (keyword: string) => {
11fdf7f2
TL
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});