]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | import { HttpClientTestingModule } from '@angular/common/http/testing'; |
2 | import { ComponentFixture, TestBed } from '@angular/core/testing'; | |
e306af50 | 3 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; |
9f95a23c TL |
4 | import { RouterTestingModule } from '@angular/router/testing'; |
5 | ||
adb31ebb | 6 | import { ToastrModule } from 'ngx-toastr'; |
9f95a23c TL |
7 | import { of } from 'rxjs'; |
8 | ||
f67539c2 TL |
9 | import { CephModule } from '~/app/ceph/ceph.module'; |
10 | import { CoreModule } from '~/app/core/core.module'; | |
11 | import { CephServiceService } from '~/app/shared/api/ceph-service.service'; | |
12 | import { OrchestratorService } from '~/app/shared/api/orchestrator.service'; | |
13 | import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context'; | |
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 } from '~/testing/unit-test-helper'; | |
9f95a23c TL |
18 | import { ServicesComponent } from './services.component'; |
19 | ||
20 | describe('ServicesComponent', () => { | |
21 | let component: ServicesComponent; | |
22 | let fixture: ComponentFixture<ServicesComponent>; | |
23 | ||
24 | const fakeAuthStorageService = { | |
25 | getPermissions: () => { | |
26 | return new Permissions({ hosts: ['read'] }); | |
27 | } | |
28 | }; | |
29 | ||
30 | const services = [ | |
31 | { | |
1911f103 | 32 | service_type: 'osd', |
9f95a23c | 33 | service_name: 'osd', |
1911f103 | 34 | status: { |
1911f103 TL |
35 | size: 3, |
36 | running: 3, | |
37 | last_refresh: '2020-02-25T04:33:26.465699' | |
38 | } | |
9f95a23c TL |
39 | }, |
40 | { | |
1911f103 | 41 | service_type: 'crash', |
9f95a23c | 42 | service_name: 'crash', |
1911f103 | 43 | status: { |
1911f103 TL |
44 | size: 1, |
45 | running: 1, | |
46 | last_refresh: '2020-02-25T04:33:26.465766' | |
47 | } | |
9f95a23c TL |
48 | } |
49 | ]; | |
50 | ||
51 | configureTestBed({ | |
e306af50 TL |
52 | imports: [ |
53 | BrowserAnimationsModule, | |
54 | CephModule, | |
55 | CoreModule, | |
56 | SharedModule, | |
57 | HttpClientTestingModule, | |
adb31ebb TL |
58 | RouterTestingModule, |
59 | ToastrModule.forRoot() | |
e306af50 | 60 | ], |
f67539c2 | 61 | providers: [{ provide: AuthStorageService, useValue: fakeAuthStorageService }] |
9f95a23c TL |
62 | }); |
63 | ||
64 | beforeEach(() => { | |
65 | fixture = TestBed.createComponent(ServicesComponent); | |
66 | component = fixture.componentInstance; | |
f67539c2 TL |
67 | const orchService = TestBed.inject(OrchestratorService); |
68 | const cephServiceService = TestBed.inject(CephServiceService); | |
9f95a23c TL |
69 | spyOn(orchService, 'status').and.returnValue(of({ available: true })); |
70 | spyOn(cephServiceService, 'list').and.returnValue(of(services)); | |
71 | fixture.detectChanges(); | |
72 | }); | |
73 | ||
74 | it('should create', () => { | |
75 | expect(component).toBeTruthy(); | |
76 | }); | |
77 | ||
78 | it('should have columns that are sortable', () => { | |
e306af50 TL |
79 | expect( |
80 | component.columns | |
adb31ebb | 81 | // Filter the 'Expand/Collapse Row' column. |
e306af50 | 82 | .filter((column) => !(column.cellClass === 'cd-datatable-expand-collapse')) |
adb31ebb TL |
83 | // Filter the 'Placement' column. |
84 | .filter((column) => !(column.prop === '')) | |
e306af50 TL |
85 | .every((column) => Boolean(column.prop)) |
86 | ).toBeTruthy(); | |
9f95a23c TL |
87 | }); |
88 | ||
89 | it('should return all services', () => { | |
f67539c2 | 90 | component.getServices(new CdTableFetchDataContext(() => undefined)); |
9f95a23c TL |
91 | expect(component.services.length).toBe(2); |
92 | }); | |
adb31ebb TL |
93 | |
94 | it('should not display doc panel if orchestrator is available', () => { | |
95 | expect(component.showDocPanel).toBeFalsy(); | |
96 | }); | |
9f95a23c | 97 | }); |