]> 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.1 Octopus source
[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 { RelativeDatePipe } from '../../../shared/pipes/relative-date.pipe';
12 import { FormatterService } from '../../../shared/services/formatter.service';
13 import { SharedModule } from '../../../shared/shared.module';
14 import { IscsiComponent } from './iscsi.component';
15
16 describe('IscsiComponent', () => {
17 let component: IscsiComponent;
18 let fixture: ComponentFixture<IscsiComponent>;
19 let iscsiService: IscsiService;
20 let tcmuiscsiData: Record<string, any>;
21
22 const fakeService = {
23 overview: () => {
24 return new Promise(function() {
25 return;
26 });
27 }
28 };
29
30 configureTestBed({
31 imports: [SharedModule],
32 declarations: [IscsiComponent],
33 schemas: [NO_ERRORS_SCHEMA],
34 providers: [
35 CephShortVersionPipe,
36 DimlessPipe,
37 FormatterService,
38 RelativeDatePipe,
39 IscsiBackstorePipe,
40 { provide: IscsiService, useValue: fakeService },
41 i18nProviders
42 ]
43 });
44
45 beforeEach(() => {
46 fixture = TestBed.createComponent(IscsiComponent);
47 component = fixture.componentInstance;
48 iscsiService = TestBed.get(IscsiService);
49 fixture.detectChanges();
50 tcmuiscsiData = {
51 images: []
52 };
53 spyOn(iscsiService, 'overview').and.callFake(() => of(tcmuiscsiData));
54 });
55
56 it('should create', () => {
57 expect(component).toBeTruthy();
58 });
59
60 it('should refresh without stats available', () => {
61 tcmuiscsiData.images.push({});
62 component.refresh();
63 expect(component.images[0].cdIsBinary).toBe(true);
64 });
65
66 it('should refresh with stats', () => {
67 tcmuiscsiData.images.push({
68 stats_history: {
69 rd_bytes: [
70 [1540551220, 0.0],
71 [1540551225, 0.0],
72 [1540551230, 0.0]
73 ],
74 wr_bytes: [
75 [1540551220, 0.0],
76 [1540551225, 0.0],
77 [1540551230, 0.0]
78 ]
79 }
80 });
81 component.refresh();
82 expect(component.images[0].stats_history).toEqual({ rd_bytes: [0, 0, 0], wr_bytes: [0, 0, 0] });
83 expect(component.images[0].cdIsBinary).toBe(true);
84 });
85 });