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