]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi/iscsi.component.spec.ts
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / block / iscsi / iscsi.component.spec.ts
1 import { NO_ERRORS_SCHEMA } from '@angular/core';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3
4 import { of } from 'rxjs';
5
6 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
7 import { IscsiService } from '../../../shared/api/iscsi.service';
8 import { CephShortVersionPipe } from '../../../shared/pipes/ceph-short-version.pipe';
9 import { DimlessPipe } from '../../../shared/pipes/dimless.pipe';
10 import { IscsiBackstorePipe } from '../../../shared/pipes/iscsi-backstore.pipe';
11 import { ListPipe } from '../../../shared/pipes/list.pipe';
12 import { RelativeDatePipe } from '../../../shared/pipes/relative-date.pipe';
13 import { FormatterService } from '../../../shared/services/formatter.service';
14 import { SharedModule } from '../../../shared/shared.module';
15 import { IscsiComponent } from './iscsi.component';
16
17 describe('IscsiComponent', () => {
18 let component: IscsiComponent;
19 let fixture: ComponentFixture<IscsiComponent>;
20 let iscsiService: IscsiService;
21 let tcmuiscsiData;
22
23 const fakeService = {
24 overview: () => {
25 return new Promise(function() {
26 return;
27 });
28 }
29 };
30
31 configureTestBed({
32 imports: [SharedModule],
33 declarations: [IscsiComponent],
34 schemas: [NO_ERRORS_SCHEMA],
35 providers: [
36 CephShortVersionPipe,
37 DimlessPipe,
38 FormatterService,
39 RelativeDatePipe,
40 IscsiBackstorePipe,
41 ListPipe,
42 { provide: IscsiService, useValue: fakeService },
43 i18nProviders
44 ]
45 });
46
47 beforeEach(() => {
48 fixture = TestBed.createComponent(IscsiComponent);
49 component = fixture.componentInstance;
50 iscsiService = TestBed.get(IscsiService);
51 fixture.detectChanges();
52 tcmuiscsiData = {
53 images: []
54 };
55 spyOn(iscsiService, 'overview').and.callFake(() => of(tcmuiscsiData));
56 });
57
58 it('should create', () => {
59 expect(component).toBeTruthy();
60 });
61
62 it('should refresh without stats available', () => {
63 tcmuiscsiData.images.push({});
64 component.refresh();
65 expect(component.images[0].cdIsBinary).toBe(true);
66 });
67
68 it('should refresh with stats', () => {
69 tcmuiscsiData.images.push({
70 stats_history: {
71 rd_bytes: [[1540551220, 0.0], [1540551225, 0.0], [1540551230, 0.0]],
72 wr_bytes: [[1540551220, 0.0], [1540551225, 0.0], [1540551230, 0.0]]
73 }
74 });
75 component.refresh();
76 expect(component.images[0].stats_history).toEqual({ rd_bytes: [0, 0, 0], wr_bytes: [0, 0, 0] });
77 expect(component.images[0].cdIsBinary).toBe(true);
78 });
79 });