]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
ecf8c4959af2e0f0019283c1ca0d814ce50fe40e
[ceph.git] /
1 import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
2
3 import { NvmeofListenersListComponent } from './nvmeof-listeners-list.component';
4 import { HttpClientModule } from '@angular/common/http';
5 import { RouterTestingModule } from '@angular/router/testing';
6 import { SharedModule } from '~/app/shared/shared.module';
7 import { NvmeofService } from '~/app/shared/api/nvmeof.service';
8 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
9 import { ModalService } from '~/app/shared/services/modal.service';
10 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
11 import { of } from 'rxjs';
12
13 const mockListeners = [
14   {
15     host_name: 'ceph-node-02',
16     trtype: 'TCP',
17     traddr: '192.168.100.102',
18     adrfam: 0,
19     trsvcid: 4421
20   }
21 ];
22
23 class MockNvmeOfService {
24   listListeners() {
25     return of(mockListeners);
26   }
27 }
28
29 class MockAuthStorageService {
30   getPermissions() {
31     return { nvmeof: {} };
32   }
33 }
34
35 class MockModalService {}
36
37 class MockTaskWrapperService {}
38
39 describe('NvmeofListenersListComponent', () => {
40   let component: NvmeofListenersListComponent;
41   let fixture: ComponentFixture<NvmeofListenersListComponent>;
42
43   beforeEach(async () => {
44     await TestBed.configureTestingModule({
45       declarations: [NvmeofListenersListComponent],
46       imports: [HttpClientModule, RouterTestingModule, SharedModule],
47       providers: [
48         { provide: NvmeofService, useClass: MockNvmeOfService },
49         { provide: AuthStorageService, useClass: MockAuthStorageService },
50         { provide: ModalService, useClass: MockModalService },
51         { provide: TaskWrapperService, useClass: MockTaskWrapperService }
52       ]
53     }).compileComponents();
54
55     fixture = TestBed.createComponent(NvmeofListenersListComponent);
56     component = fixture.componentInstance;
57     component.ngOnInit();
58     fixture.detectChanges();
59   });
60
61   it('should create', () => {
62     expect(component).toBeTruthy();
63   });
64
65   it('should retrieve subsystems', fakeAsync(() => {
66     component.listListeners();
67     tick();
68     expect(component.listeners).toEqual(mockListeners);
69   }));
70 });