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';
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 import { PopoverModule } from 'ngx-bootstrap/popover';
12 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
13 import { TableComponent } from '../../../shared/datatable/table/table.component';
15 import { ComponentsModule } from '../../../shared/components/components.module';
16 import { RbdConfigurationEntry } from '../../../shared/models/configuration';
17 import { PipesModule } from '../../../shared/pipes/pipes.module';
18 import { FormatterService } from '../../../shared/services/formatter.service';
19 import { RbdConfigurationService } from '../../../shared/services/rbd-configuration.service';
20 import { RbdConfigurationListComponent } from './rbd-configuration-list.component';
22 describe('RbdConfigurationListComponent', () => {
23 let component: RbdConfigurationListComponent;
24 let fixture: ComponentFixture<RbdConfigurationListComponent>;
28 BrowserAnimationsModule,
34 BsDropdownModule.forRoot(),
39 declarations: [RbdConfigurationListComponent, TableComponent],
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: string) => {
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);