]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
8743cf3580938cbcb28c498584f34b7102caf898
[ceph-ci.git] /
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
10 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
11 import { ErrorPanelComponent } from '../../../shared/components/error-panel/error-panel.component';
12 import { SparklineComponent } from '../../../shared/components/sparkline/sparkline.component';
13 import { TableComponent } from '../../../shared/datatable/table/table.component';
14 import { RbdConfigurationEntry } from '../../../shared/models/configuration';
15 import { PipesModule } from '../../../shared/pipes/pipes.module';
16 import { FormatterService } from '../../../shared/services/formatter.service';
17 import { RbdConfigurationService } from '../../../shared/services/rbd-configuration.service';
18 import { RbdConfigurationListComponent } from './rbd-configuration-list.component';
19
20 describe('RbdConfigurationListComponent', () => {
21   let component: RbdConfigurationListComponent;
22   let fixture: ComponentFixture<RbdConfigurationListComponent>;
23
24   configureTestBed({
25     imports: [
26       FormsModule,
27       NgxDatatableModule,
28       RouterTestingModule,
29       AlertModule,
30       BsDropdownModule.forRoot(),
31       ChartsModule,
32       PipesModule
33     ],
34     declarations: [
35       RbdConfigurationListComponent,
36       TableComponent,
37       ErrorPanelComponent,
38       SparklineComponent
39     ],
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) => {
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 });