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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap';
import { of } from 'rxjs';
import { PerformanceCounterModule } from '~/app/ceph/performance-counter/performance-counter.module';
import { RgwDaemon } from '~/app/ceph/rgw/models/rgw-daemon';
import { RgwDaemonService } from '~/app/shared/api/rgw-daemon.service';
import { RgwSiteService } from '~/app/shared/api/rgw-site.service';
import { Permissions } from '~/app/shared/models/permissions';
import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
import { SharedModule } from '~/app/shared/shared.module';
import { configureTestBed, TabHelper } from '~/testing/unit-test-helper';
import { RgwDaemonDetailsComponent } from '../rgw-daemon-details/rgw-daemon-details.component';
import { RgwDaemonListComponent } from './rgw-daemon-list.component';
describe('RgwDaemonListComponent', () => {
let component: RgwDaemonListComponent;
let fixture: ComponentFixture<RgwDaemonListComponent>;
let getPermissionsSpy: jasmine.Spy;
let getRealmsSpy: jasmine.Spy;
let listDaemonsSpy: jest.SpyInstance;
const permissions = new Permissions({ grafana: ['read'] });
const daemon: RgwDaemon = {
id: '8000',
service_map_id: '4803',
version: 'ceph version',
server_hostname: 'ceph',
realm_name: 'realm1',
zonegroup_name: 'zg1-realm1',
zone_name: 'zone1-zg1-realm1',
default: true
};
const expectTabsAndHeading = (length: number, heading: string) => {
const tabs = TabHelper.getTextContents(fixture);
expect(tabs.length).toEqual(length);
expect(tabs[length - 1]).toEqual(heading);
};
configureTestBed({
declarations: [RgwDaemonListComponent, RgwDaemonDetailsComponent],
imports: [
BrowserAnimationsModule,
HttpClientTestingModule,
NgbNavModule,
PerformanceCounterModule,
SharedModule,
RouterTestingModule
]
});
beforeEach(() => {
getPermissionsSpy = spyOn(TestBed.inject(AuthStorageService), 'getPermissions');
getPermissionsSpy.and.returnValue(new Permissions({}));
getRealmsSpy = spyOn(TestBed.inject(RgwSiteService), 'get');
getRealmsSpy.and.returnValue(of([]));
listDaemonsSpy = jest
.spyOn(TestBed.inject(RgwDaemonService), 'list')
.mockReturnValue(of([daemon]));
fixture = TestBed.createComponent(RgwDaemonListComponent);
component = fixture.componentInstance;
});
it('should create', () => {
fixture.detectChanges();
expect(component).toBeTruthy();
});
it('should show a row with daemon info', fakeAsync(() => {
fixture.detectChanges();
tick();
expect(listDaemonsSpy).toHaveBeenCalledTimes(1);
expect(component.daemons).toEqual([daemon]);
expect(fixture.debugElement.query(By.css('cd-table')).nativeElement.textContent).toContain(
'total 1'
);
fixture.destroy();
}));
it('should only show Daemons List tab', () => {
fixture.detectChanges();
expectTabsAndHeading(1, 'Daemons List');
});
it('should show Overall Performance tab', () => {
getPermissionsSpy.and.returnValue(permissions);
fixture.detectChanges();
expectTabsAndHeading(2, 'Overall Performance');
});
it('should show Sync Performance tab', () => {
getPermissionsSpy.and.returnValue(permissions);
getRealmsSpy.and.returnValue(of(['realm1']));
fixture.detectChanges();
expectTabsAndHeading(3, 'Sync Performance');
});
});
|