]>
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 | ||
6 | import { of } from 'rxjs'; | |
7 | ||
8 | import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper'; | |
9 | import { CoreModule } from '../../../core/core.module'; | |
10 | import { CephServiceService } from '../../../shared/api/ceph-service.service'; | |
11 | import { OrchestratorService } from '../../../shared/api/orchestrator.service'; | |
12 | import { CdTableFetchDataContext } from '../../../shared/models/cd-table-fetch-data-context'; | |
13 | import { Permissions } from '../../../shared/models/permissions'; | |
14 | import { AuthStorageService } from '../../../shared/services/auth-storage.service'; | |
15 | import { SharedModule } from '../../../shared/shared.module'; | |
16 | import { CephModule } from '../../ceph.module'; | |
17 | import { ServicesComponent } from './services.component'; | |
18 | ||
19 | describe('ServicesComponent', () => { | |
20 | let component: ServicesComponent; | |
21 | let fixture: ComponentFixture<ServicesComponent>; | |
22 | ||
23 | const fakeAuthStorageService = { | |
24 | getPermissions: () => { | |
25 | return new Permissions({ hosts: ['read'] }); | |
26 | } | |
27 | }; | |
28 | ||
29 | const services = [ | |
30 | { | |
1911f103 | 31 | service_type: 'osd', |
9f95a23c | 32 | service_name: 'osd', |
1911f103 TL |
33 | status: { |
34 | container_image_id: 'e70344c77bcbf3ee389b9bf5128f635cf95f3d59e005c5d8e67fc19bcc74ed23', | |
35 | container_image_name: 'docker.io/ceph/daemon-base:latest-master-devel', | |
36 | size: 3, | |
37 | running: 3, | |
38 | last_refresh: '2020-02-25T04:33:26.465699' | |
39 | } | |
9f95a23c TL |
40 | }, |
41 | { | |
1911f103 | 42 | service_type: 'crash', |
9f95a23c | 43 | service_name: 'crash', |
1911f103 TL |
44 | status: { |
45 | container_image_id: 'e70344c77bcbf3ee389b9bf5128f635cf95f3d59e005c5d8e67fc19bcc74ed23', | |
46 | container_image_name: 'docker.io/ceph/daemon-base:latest-master-devel', | |
47 | size: 1, | |
48 | running: 1, | |
49 | last_refresh: '2020-02-25T04:33:26.465766' | |
50 | } | |
9f95a23c TL |
51 | } |
52 | ]; | |
53 | ||
54 | configureTestBed({ | |
e306af50 TL |
55 | imports: [ |
56 | BrowserAnimationsModule, | |
57 | CephModule, | |
58 | CoreModule, | |
59 | SharedModule, | |
60 | HttpClientTestingModule, | |
61 | RouterTestingModule | |
62 | ], | |
9f95a23c TL |
63 | providers: [{ provide: AuthStorageService, useValue: fakeAuthStorageService }, i18nProviders], |
64 | declarations: [] | |
65 | }); | |
66 | ||
67 | beforeEach(() => { | |
68 | fixture = TestBed.createComponent(ServicesComponent); | |
69 | component = fixture.componentInstance; | |
70 | const orchService = TestBed.get(OrchestratorService); | |
71 | const cephServiceService = TestBed.get(CephServiceService); | |
72 | spyOn(orchService, 'status').and.returnValue(of({ available: true })); | |
73 | spyOn(cephServiceService, 'list').and.returnValue(of(services)); | |
74 | fixture.detectChanges(); | |
75 | }); | |
76 | ||
77 | it('should create', () => { | |
78 | expect(component).toBeTruthy(); | |
79 | }); | |
80 | ||
81 | it('should have columns that are sortable', () => { | |
e306af50 TL |
82 | expect( |
83 | component.columns | |
84 | .filter((column) => !(column.cellClass === 'cd-datatable-expand-collapse')) | |
85 | .every((column) => Boolean(column.prop)) | |
86 | ).toBeTruthy(); | |
9f95a23c TL |
87 | }); |
88 | ||
89 | it('should return all services', () => { | |
90 | component.getServices(new CdTableFetchDataContext(() => {})); | |
91 | expect(component.services.length).toBe(2); | |
92 | }); | |
93 | }); |