summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-configuration-list/rbd-configuration-list.component.spec.ts
blob: f54ad02720c5276d19956d62195a8b12f1c72085 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';

import { NgbDropdownModule, NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';
import { NgxDatatableModule } from '@swimlane/ngx-datatable';
import { ChartsModule } from 'ng2-charts';

import { ComponentsModule } from '~/app/shared/components/components.module';
import { RbdConfigurationEntry } from '~/app/shared/models/configuration';
import { FormatterService } from '~/app/shared/services/formatter.service';
import { RbdConfigurationService } from '~/app/shared/services/rbd-configuration.service';
import { SharedModule } from '~/app/shared/shared.module';
import { configureTestBed } from '~/testing/unit-test-helper';
import { RbdConfigurationListComponent } from './rbd-configuration-list.component';

describe('RbdConfigurationListComponent', () => {
  let component: RbdConfigurationListComponent;
  let fixture: ComponentFixture<RbdConfigurationListComponent>;

  configureTestBed({
    imports: [
      BrowserAnimationsModule,
      FormsModule,
      NgxDatatableModule,
      RouterTestingModule,
      ComponentsModule,
      NgbDropdownModule,
      ChartsModule,
      SharedModule,
      NgbTooltipModule
    ],
    declarations: [RbdConfigurationListComponent],
    providers: [FormatterService, RbdConfigurationService]
  });

  beforeEach(() => {
    fixture = TestBed.createComponent(RbdConfigurationListComponent);
    component = fixture.componentInstance;
    component.data = [];
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  it('filters options out which are not defined in RbdConfigurationService', () => {
    const fakeOption = { name: 'foo', source: 0, value: '50' } as RbdConfigurationEntry;
    const realOption = {
      name: 'rbd_qos_read_iops_burst',
      source: 0,
      value: '50'
    } as RbdConfigurationEntry;

    component.data = [fakeOption, realOption];
    component.ngOnChanges();

    expect(component.data.length).toBe(1);
    expect(component.data.pop()).toBe(realOption);
  });

  it('should filter the source column by its piped value', () => {
    const poolConfTable = component.poolConfTable;
    poolConfTable.data = [
      {
        name: 'rbd_qos_read_iops_burst',
        source: 0,
        value: '50'
      },
      {
        name: 'rbd_qos_read_iops_limit',
        source: 1,
        value: '50'
      },
      {
        name: 'rbd_qos_write_iops_limit',
        source: 0,
        value: '100'
      },
      {
        name: 'rbd_qos_write_iops_burst',
        source: 2,
        value: '100'
      }
    ];
    const filter = (keyword: string) => {
      poolConfTable.search = keyword;
      poolConfTable.updateFilter();
      return poolConfTable.rows;
    };
    expect(filter('').length).toBe(4);
    expect(filter('source:global').length).toBe(2);
    expect(filter('source:pool').length).toBe(1);
    expect(filter('source:image').length).toBe(1);
    expect(filter('source:zero').length).toBe(0);
  });
});