]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/iscsi/iscsi.component.spec.ts
import 15.2.4
[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 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
4
5 import { of } from 'rxjs';
6
7 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
8 import { IscsiService } from '../../../shared/api/iscsi.service';
9 import { CephShortVersionPipe } from '../../../shared/pipes/ceph-short-version.pipe';
10 import { DimlessPipe } from '../../../shared/pipes/dimless.pipe';
11 import { IscsiBackstorePipe } from '../../../shared/pipes/iscsi-backstore.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: Record<string, any>;
22
23 const fakeService = {
24 overview: () => {
25 return new Promise(function () {
26 return;
27 });
28 }
29 };
30
31 configureTestBed({
32 imports: [BrowserAnimationsModule, SharedModule],
33 declarations: [IscsiComponent],
34 schemas: [NO_ERRORS_SCHEMA],
35 providers: [
36 CephShortVersionPipe,
37 DimlessPipe,
38 FormatterService,
39 RelativeDatePipe,
40 IscsiBackstorePipe,
41 { provide: IscsiService, useValue: fakeService },
42 i18nProviders
43 ]
44 });
45
46 beforeEach(() => {
47 fixture = TestBed.createComponent(IscsiComponent);
48 component = fixture.componentInstance;
49 iscsiService = TestBed.get(IscsiService);
50 fixture.detectChanges();
51 tcmuiscsiData = {
52 images: []
53 };
54 spyOn(iscsiService, 'overview').and.callFake(() => of(tcmuiscsiData));
55 });
56
57 it('should create', () => {
58 expect(component).toBeTruthy();
59 });
60
61 it('should refresh without stats available', () => {
62 tcmuiscsiData.images.push({});
63 component.refresh();
64 expect(component.images[0].cdIsBinary).toBe(true);
65 });
66
67 it('should refresh with stats', () => {
68 tcmuiscsiData.images.push({
69 stats_history: {
70 rd_bytes: [
71 [1540551220, 0.0],
72 [1540551225, 0.0],
73 [1540551230, 0.0]
74 ],
75 wr_bytes: [
76 [1540551220, 0.0],
77 [1540551225, 0.0],
78 [1540551230, 0.0]
79 ]
80 }
81 });
82 component.refresh();
83 expect(component.images[0].stats_history).toEqual({ rd_bytes: [0, 0, 0], wr_bytes: [0, 0, 0] });
84 expect(component.images[0].cdIsBinary).toBe(true);
85 });
86 });