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 { NgbDropdownModule, NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';
7 import { NgxDatatableModule } from '@swimlane/ngx-datatable';
8 import { ChartsModule } from 'ng2-charts';
10 import { ComponentsModule } from '~/app/shared/components/components.module';
11 import { RbdConfigurationEntry } from '~/app/shared/models/configuration';
12 import { FormatterService } from '~/app/shared/services/formatter.service';
13 import { RbdConfigurationService } from '~/app/shared/services/rbd-configuration.service';
14 import { SharedModule } from '~/app/shared/shared.module';
15 import { configureTestBed } from '~/testing/unit-test-helper';
16 import { RbdConfigurationListComponent } from './rbd-configuration-list.component';
18 describe('RbdConfigurationListComponent', () => {
19 let component: RbdConfigurationListComponent;
20 let fixture: ComponentFixture<RbdConfigurationListComponent>;
24 BrowserAnimationsModule,
34 declarations: [RbdConfigurationListComponent],
35 providers: [FormatterService, RbdConfigurationService]
39 fixture = TestBed.createComponent(RbdConfigurationListComponent);
40 component = fixture.componentInstance;
42 fixture.detectChanges();
45 it('should create', () => {
46 expect(component).toBeTruthy();
49 it('filters options out which are not defined in RbdConfigurationService', () => {
50 const fakeOption = { name: 'foo', source: 0, value: '50' } as RbdConfigurationEntry;
52 name: 'rbd_qos_read_iops_burst',
55 } as RbdConfigurationEntry;
57 component.data = [fakeOption, realOption];
58 component.ngOnChanges();
60 expect(component.data.length).toBe(1);
61 expect(component.data.pop()).toBe(realOption);
64 it('should filter the source column by its piped value', () => {
65 const poolConfTable = component.poolConfTable;
66 poolConfTable.data = [
68 name: 'rbd_qos_read_iops_burst',
73 name: 'rbd_qos_read_iops_limit',
78 name: 'rbd_qos_write_iops_limit',
83 name: 'rbd_qos_write_iops_burst',
88 const filter = (keyword: string) => {
89 poolConfTable.search = keyword;
90 poolConfTable.updateFilter();
91 return poolConfTable.rows;
93 expect(filter('').length).toBe(4);
94 expect(filter('source:global').length).toBe(2);
95 expect(filter('source:pool').length).toBe(1);
96 expect(filter('source:image').length).toBe(1);
97 expect(filter('source:zero').length).toBe(0);