]>
Commit | Line | Data |
---|---|---|
11fdf7f2 | 1 | import { HttpClientTestingModule } from '@angular/common/http/testing'; |
a4b75251 TL |
2 | import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; |
3 | import { By } from '@angular/platform-browser'; | |
e306af50 | 4 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; |
11fdf7f2 TL |
5 | import { RouterTestingModule } from '@angular/router/testing'; |
6 | ||
f67539c2 | 7 | import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap'; |
e306af50 | 8 | import { of } from 'rxjs'; |
11fdf7f2 | 9 | |
f67539c2 | 10 | import { PerformanceCounterModule } from '~/app/ceph/performance-counter/performance-counter.module'; |
a4b75251 TL |
11 | import { RgwDaemon } from '~/app/ceph/rgw/models/rgw-daemon'; |
12 | import { RgwDaemonService } from '~/app/shared/api/rgw-daemon.service'; | |
f67539c2 TL |
13 | import { RgwSiteService } from '~/app/shared/api/rgw-site.service'; |
14 | import { Permissions } from '~/app/shared/models/permissions'; | |
15 | import { AuthStorageService } from '~/app/shared/services/auth-storage.service'; | |
16 | import { SharedModule } from '~/app/shared/shared.module'; | |
17 | import { configureTestBed, TabHelper } from '~/testing/unit-test-helper'; | |
11fdf7f2 TL |
18 | import { RgwDaemonDetailsComponent } from '../rgw-daemon-details/rgw-daemon-details.component'; |
19 | import { RgwDaemonListComponent } from './rgw-daemon-list.component'; | |
20 | ||
21 | describe('RgwDaemonListComponent', () => { | |
22 | let component: RgwDaemonListComponent; | |
23 | let fixture: ComponentFixture<RgwDaemonListComponent>; | |
e306af50 TL |
24 | let getPermissionsSpy: jasmine.Spy; |
25 | let getRealmsSpy: jasmine.Spy; | |
a4b75251 | 26 | let listDaemonsSpy: jest.SpyInstance; |
e306af50 | 27 | const permissions = new Permissions({ grafana: ['read'] }); |
a4b75251 TL |
28 | const daemon: RgwDaemon = { |
29 | id: '8000', | |
30 | service_map_id: '4803', | |
31 | version: 'ceph version', | |
32 | server_hostname: 'ceph', | |
33 | realm_name: 'realm1', | |
34 | zonegroup_name: 'zg1-realm1', | |
35 | zone_name: 'zone1-zg1-realm1', | |
36 | default: true | |
37 | }; | |
e306af50 | 38 | |
f67539c2 TL |
39 | const expectTabsAndHeading = (length: number, heading: string) => { |
40 | const tabs = TabHelper.getTextContents(fixture); | |
e306af50 | 41 | expect(tabs.length).toEqual(length); |
f67539c2 | 42 | expect(tabs[length - 1]).toEqual(heading); |
e306af50 | 43 | }; |
11fdf7f2 TL |
44 | |
45 | configureTestBed({ | |
46 | declarations: [RgwDaemonListComponent, RgwDaemonDetailsComponent], | |
47 | imports: [ | |
e306af50 | 48 | BrowserAnimationsModule, |
11fdf7f2 | 49 | HttpClientTestingModule, |
f67539c2 | 50 | NgbNavModule, |
11fdf7f2 TL |
51 | PerformanceCounterModule, |
52 | SharedModule, | |
53 | RouterTestingModule | |
f67539c2 | 54 | ] |
11fdf7f2 TL |
55 | }); |
56 | ||
57 | beforeEach(() => { | |
f67539c2 | 58 | getPermissionsSpy = spyOn(TestBed.inject(AuthStorageService), 'getPermissions'); |
e306af50 | 59 | getPermissionsSpy.and.returnValue(new Permissions({})); |
f67539c2 | 60 | getRealmsSpy = spyOn(TestBed.inject(RgwSiteService), 'get'); |
e306af50 | 61 | getRealmsSpy.and.returnValue(of([])); |
a4b75251 TL |
62 | listDaemonsSpy = jest |
63 | .spyOn(TestBed.inject(RgwDaemonService), 'list') | |
64 | .mockReturnValue(of([daemon])); | |
11fdf7f2 TL |
65 | fixture = TestBed.createComponent(RgwDaemonListComponent); |
66 | component = fixture.componentInstance; | |
11fdf7f2 TL |
67 | }); |
68 | ||
69 | it('should create', () => { | |
e306af50 | 70 | fixture.detectChanges(); |
11fdf7f2 TL |
71 | expect(component).toBeTruthy(); |
72 | }); | |
e306af50 | 73 | |
a4b75251 TL |
74 | it('should show a row with daemon info', fakeAsync(() => { |
75 | fixture.detectChanges(); | |
76 | tick(); | |
77 | expect(listDaemonsSpy).toHaveBeenCalledTimes(1); | |
78 | expect(component.daemons).toEqual([daemon]); | |
79 | expect(fixture.debugElement.query(By.css('cd-table')).nativeElement.textContent).toContain( | |
39ae355f | 80 | 'total of 1' |
a4b75251 TL |
81 | ); |
82 | ||
83 | fixture.destroy(); | |
84 | })); | |
85 | ||
e306af50 TL |
86 | it('should only show Daemons List tab', () => { |
87 | fixture.detectChanges(); | |
88 | ||
89 | expectTabsAndHeading(1, 'Daemons List'); | |
90 | }); | |
91 | ||
92 | it('should show Overall Performance tab', () => { | |
93 | getPermissionsSpy.and.returnValue(permissions); | |
94 | fixture.detectChanges(); | |
95 | ||
96 | expectTabsAndHeading(2, 'Overall Performance'); | |
97 | }); | |
98 | ||
99 | it('should show Sync Performance tab', () => { | |
100 | getPermissionsSpy.and.returnValue(permissions); | |
101 | getRealmsSpy.and.returnValue(of(['realm1'])); | |
102 | fixture.detectChanges(); | |
103 | ||
104 | expectTabsAndHeading(3, 'Sync Performance'); | |
105 | }); | |
11fdf7f2 | 106 | }); |