]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | import { NO_ERRORS_SCHEMA } from '@angular/core'; |
2 | import { ComponentFixture, TestBed } from '@angular/core/testing'; | |
e306af50 | 3 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; |
11fdf7f2 TL |
4 | |
5 | import { of } from 'rxjs'; | |
6 | ||
f67539c2 TL |
7 | import { IscsiService } from '~/app/shared/api/iscsi.service'; |
8 | import { CephShortVersionPipe } from '~/app/shared/pipes/ceph-short-version.pipe'; | |
9 | import { DimlessPipe } from '~/app/shared/pipes/dimless.pipe'; | |
10 | import { IscsiBackstorePipe } from '~/app/shared/pipes/iscsi-backstore.pipe'; | |
11 | import { FormatterService } from '~/app/shared/services/formatter.service'; | |
12 | import { SharedModule } from '~/app/shared/shared.module'; | |
13 | import { configureTestBed } from '~/testing/unit-test-helper'; | |
11fdf7f2 TL |
14 | import { IscsiComponent } from './iscsi.component'; |
15 | ||
16 | describe('IscsiComponent', () => { | |
17 | let component: IscsiComponent; | |
18 | let fixture: ComponentFixture<IscsiComponent>; | |
19 | let iscsiService: IscsiService; | |
9f95a23c | 20 | let tcmuiscsiData: Record<string, any>; |
11fdf7f2 TL |
21 | |
22 | const fakeService = { | |
23 | overview: () => { | |
e306af50 | 24 | return new Promise(function () { |
11fdf7f2 TL |
25 | return; |
26 | }); | |
27 | } | |
28 | }; | |
29 | ||
30 | configureTestBed({ | |
e306af50 | 31 | imports: [BrowserAnimationsModule, SharedModule], |
11fdf7f2 TL |
32 | declarations: [IscsiComponent], |
33 | schemas: [NO_ERRORS_SCHEMA], | |
34 | providers: [ | |
35 | CephShortVersionPipe, | |
36 | DimlessPipe, | |
37 | FormatterService, | |
11fdf7f2 | 38 | IscsiBackstorePipe, |
f67539c2 | 39 | { provide: IscsiService, useValue: fakeService } |
11fdf7f2 TL |
40 | ] |
41 | }); | |
42 | ||
43 | beforeEach(() => { | |
44 | fixture = TestBed.createComponent(IscsiComponent); | |
45 | component = fixture.componentInstance; | |
f67539c2 | 46 | iscsiService = TestBed.inject(IscsiService); |
11fdf7f2 TL |
47 | fixture.detectChanges(); |
48 | tcmuiscsiData = { | |
49 | images: [] | |
50 | }; | |
51 | spyOn(iscsiService, 'overview').and.callFake(() => of(tcmuiscsiData)); | |
52 | }); | |
53 | ||
54 | it('should create', () => { | |
55 | expect(component).toBeTruthy(); | |
56 | }); | |
57 | ||
58 | it('should refresh without stats available', () => { | |
59 | tcmuiscsiData.images.push({}); | |
60 | component.refresh(); | |
61 | expect(component.images[0].cdIsBinary).toBe(true); | |
62 | }); | |
63 | ||
64 | it('should refresh with stats', () => { | |
65 | tcmuiscsiData.images.push({ | |
66 | stats_history: { | |
801d1391 TL |
67 | rd_bytes: [ |
68 | [1540551220, 0.0], | |
69 | [1540551225, 0.0], | |
70 | [1540551230, 0.0] | |
71 | ], | |
72 | wr_bytes: [ | |
73 | [1540551220, 0.0], | |
74 | [1540551225, 0.0], | |
75 | [1540551230, 0.0] | |
76 | ] | |
11fdf7f2 TL |
77 | } |
78 | }); | |
79 | component.refresh(); | |
80 | expect(component.images[0].stats_history).toEqual({ rd_bytes: [0, 0, 0], wr_bytes: [0, 0, 0] }); | |
81 | expect(component.images[0].cdIsBinary).toBe(true); | |
82 | }); | |
83 | }); |