]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
d784ed12e4c4eb708f2d401ee7ec0ba928af165c
[ceph.git] /
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
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       BrowserAnimationsModule,
28       FormsModule,
29       NgxDatatableModule,
30       RouterTestingModule,
31       ComponentsModule,
32       AlertModule,
33       BsDropdownModule.forRoot(),
34       ChartsModule,
35       PipesModule
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 });