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
|
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { of } from 'rxjs';
import { IscsiService } from '~/app/shared/api/iscsi.service';
import { CephShortVersionPipe } from '~/app/shared/pipes/ceph-short-version.pipe';
import { DimlessPipe } from '~/app/shared/pipes/dimless.pipe';
import { IscsiBackstorePipe } from '~/app/shared/pipes/iscsi-backstore.pipe';
import { FormatterService } from '~/app/shared/services/formatter.service';
import { SharedModule } from '~/app/shared/shared.module';
import { configureTestBed } from '~/testing/unit-test-helper';
import { IscsiComponent } from './iscsi.component';
describe('IscsiComponent', () => {
let component: IscsiComponent;
let fixture: ComponentFixture<IscsiComponent>;
let iscsiService: IscsiService;
let tcmuiscsiData: Record<string, any>;
const fakeService = {
overview: () => {
return new Promise(function () {
return;
});
}
};
configureTestBed({
imports: [BrowserAnimationsModule, SharedModule],
declarations: [IscsiComponent],
schemas: [NO_ERRORS_SCHEMA],
providers: [
CephShortVersionPipe,
DimlessPipe,
FormatterService,
IscsiBackstorePipe,
{ provide: IscsiService, useValue: fakeService }
]
});
beforeEach(() => {
fixture = TestBed.createComponent(IscsiComponent);
component = fixture.componentInstance;
iscsiService = TestBed.inject(IscsiService);
fixture.detectChanges();
tcmuiscsiData = {
images: []
};
spyOn(iscsiService, 'overview').and.callFake(() => of(tcmuiscsiData));
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should refresh without stats available', () => {
tcmuiscsiData.images.push({});
component.refresh();
expect(component.images[0].cdIsBinary).toBe(true);
});
it('should refresh with stats', () => {
tcmuiscsiData.images.push({
stats_history: {
rd_bytes: [
[1540551220, 0.0],
[1540551225, 0.0],
[1540551230, 0.0]
],
wr_bytes: [
[1540551220, 0.0],
[1540551225, 0.0],
[1540551230, 0.0]
]
}
});
component.refresh();
expect(component.images[0].stats_history).toEqual({ rd_bytes: [0, 0, 0], wr_bytes: [0, 0, 0] });
expect(component.images[0].cdIsBinary).toBe(true);
});
});
|