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
|
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import { NgbNavModule, NgbProgressbarModule } from '@ng-bootstrap/ng-bootstrap';
import { ToastrModule } from 'ngx-toastr';
import { of } from 'rxjs';
import { RbdMirroringService } from '~/app/shared/api/rbd-mirroring.service';
import { SharedModule } from '~/app/shared/shared.module';
import { configureTestBed } from '~/testing/unit-test-helper';
import { DaemonListComponent } from '../daemon-list/daemon-list.component';
import { ImageListComponent } from '../image-list/image-list.component';
import { MirrorHealthColorPipe } from '../mirror-health-color.pipe';
import { PoolListComponent } from '../pool-list/pool-list.component';
import { OverviewComponent } from './overview.component';
describe('OverviewComponent', () => {
let component: OverviewComponent;
let fixture: ComponentFixture<OverviewComponent>;
let rbdMirroringService: RbdMirroringService;
configureTestBed({
declarations: [
DaemonListComponent,
ImageListComponent,
MirrorHealthColorPipe,
OverviewComponent,
PoolListComponent
],
imports: [
BrowserAnimationsModule,
SharedModule,
NgbNavModule,
NgbProgressbarModule,
HttpClientTestingModule,
RouterTestingModule,
ReactiveFormsModule,
ToastrModule.forRoot()
]
});
beforeEach(() => {
fixture = TestBed.createComponent(OverviewComponent);
component = fixture.componentInstance;
rbdMirroringService = TestBed.inject(RbdMirroringService);
component.siteName = 'site-A';
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
describe('edit site name', () => {
beforeEach(() => {
spyOn(rbdMirroringService, 'getSiteName').and.callFake(() => of({ site_name: 'site-A' }));
spyOn(rbdMirroringService, 'refresh').and.stub();
fixture.detectChanges();
});
afterEach(() => {
expect(rbdMirroringService.refresh).toHaveBeenCalledTimes(1);
});
it('should call setSiteName', () => {
component.editing = true;
spyOn(rbdMirroringService, 'setSiteName').and.callFake(() => of({ site_name: 'new-site-A' }));
component.rbdmirroringForm.patchValue({
siteName: 'new-site-A'
});
component.updateSiteName();
expect(rbdMirroringService.setSiteName).toHaveBeenCalledWith('new-site-A');
});
});
});
|