1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
4 import { RouterTestingModule } from '@angular/router/testing';
6 import { ToastrModule } from 'ngx-toastr';
7 import { of } from 'rxjs';
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';
18 import { ServicesComponent } from './services.component';
20 describe('ServicesComponent', () => {
21 let component: ServicesComponent;
22 let fixture: ComponentFixture<ServicesComponent>;
24 const fakeAuthStorageService = {
25 getPermissions: () => {
26 return new Permissions({ hosts: ['read'] });
37 last_refresh: '2020-02-25T04:33:26.465699'
41 service_type: 'crash',
42 service_name: 'crash',
46 last_refresh: '2020-02-25T04:33:26.465766'
53 BrowserAnimationsModule,
57 HttpClientTestingModule,
59 ToastrModule.forRoot()
61 providers: [{ provide: AuthStorageService, useValue: fakeAuthStorageService }]
65 fixture = TestBed.createComponent(ServicesComponent);
66 component = fixture.componentInstance;
67 const orchService = TestBed.inject(OrchestratorService);
68 const cephServiceService = TestBed.inject(CephServiceService);
69 spyOn(orchService, 'status').and.returnValue(of({ available: true }));
70 spyOn(cephServiceService, 'list').and.returnValue(of(services));
71 fixture.detectChanges();
74 it('should create', () => {
75 expect(component).toBeTruthy();
78 it('should have columns that are sortable', () => {
81 // Filter the 'Expand/Collapse Row' column.
82 .filter((column) => !(column.cellClass === 'cd-datatable-expand-collapse'))
83 // Filter the 'Placement' column.
84 .filter((column) => !(column.prop === ''))
85 .every((column) => Boolean(column.prop))
89 it('should return all services', () => {
90 component.getServices(new CdTableFetchDataContext(() => undefined));
91 expect(component.services.length).toBe(2);
94 it('should not display doc panel if orchestrator is available', () => {
95 expect(component.showDocPanel).toBeFalsy();