1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2 import { FormsModule } from '@angular/forms';
3 import { RouterTestingModule } from '@angular/router/testing';
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';
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';
20 describe('RbdConfigurationListComponent', () => {
21 let component: RbdConfigurationListComponent;
22 let fixture: ComponentFixture<RbdConfigurationListComponent>;
30 BsDropdownModule.forRoot(),
35 RbdConfigurationListComponent,
40 providers: [FormatterService, RbdConfigurationService, i18nProviders]
44 fixture = TestBed.createComponent(RbdConfigurationListComponent);
45 component = fixture.componentInstance;
47 fixture.detectChanges();
50 it('should create', () => {
51 expect(component).toBeTruthy();
54 it('filters options out which are not defined in RbdConfigurationService', () => {
55 const fakeOption = { name: 'foo', source: 0, value: '50' } as RbdConfigurationEntry;
57 name: 'rbd_qos_read_iops_burst',
60 } as RbdConfigurationEntry;
62 component.data = [fakeOption, realOption];
63 component.ngOnChanges();
65 expect(component.data.length).toBe(1);
66 expect(component.data.pop()).toBe(realOption);
69 it('should filter the source column by its piped value', () => {
70 const poolConfTable = component.poolConfTable;
71 poolConfTable.data = [
73 name: 'rbd_qos_read_iops_burst',
78 name: 'rbd_qos_read_iops_limit',
83 name: 'rbd_qos_write_iops_limit',
88 name: 'rbd_qos_write_iops_burst',
93 const filter = (keyword) => {
94 poolConfTable.search = keyword;
95 poolConfTable.updateFilter();
96 return poolConfTable.rows;
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);