]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
c508cf74a778445fba41a7d34734d7a27f2840c9
[ceph.git] /
1 import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
2 import { HttpClientModule } from '@angular/common/http';
3 import { of } from 'rxjs';
4 import { RouterTestingModule } from '@angular/router/testing';
5 import { SharedModule } from '~/app/shared/shared.module';
6
7 import { NvmeofService } from '../../../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 { NvmeofSubsystemsComponent } from './nvmeof-subsystems.component';
12 import { NvmeofTabsComponent } from '../nvmeof-tabs/nvmeof-tabs.component';
13 import { NvmeofSubsystemsDetailsComponent } from '../nvmeof-subsystems-details/nvmeof-subsystems-details.component';
14 import { ComboBoxModule, GridModule } from 'carbon-components-angular';
15
16 const mockSubsystems = [
17   {
18     nqn: 'nqn.2001-07.com.ceph:1720603703820',
19     enable_ha: true,
20     serial_number: 'Ceph30487186726692',
21     model_number: 'Ceph bdev Controller',
22     min_cntlid: 1,
23     max_cntlid: 2040,
24     namespace_count: 0,
25     subtype: 'NVMe',
26     max_namespaces: 256
27   }
28 ];
29
30 const mockGroups = [
31   [
32     {
33       service_name: 'nvmeof.rbd.default',
34       service_type: 'nvmeof',
35       unmanaged: false,
36       spec: {
37         group: 'default'
38       }
39     },
40     {
41       service_name: 'nvmeof.rbd.foo',
42       service_type: 'nvmeof',
43       unmanaged: false,
44       spec: {
45         group: 'foo'
46       }
47     }
48   ],
49   2
50 ];
51
52 class MockNvmeOfService {
53   listSubsystems() {
54     return of(mockSubsystems);
55   }
56
57   listGatewayGroups() {
58     return of(mockGroups);
59   }
60 }
61
62 class MockAuthStorageService {
63   getPermissions() {
64     return { nvmeof: {} };
65   }
66 }
67
68 class MockModalService {}
69
70 class MockTaskWrapperService {}
71
72 describe('NvmeofSubsystemsComponent', () => {
73   let component: NvmeofSubsystemsComponent;
74   let fixture: ComponentFixture<NvmeofSubsystemsComponent>;
75
76   beforeEach(async () => {
77     await TestBed.configureTestingModule({
78       declarations: [
79         NvmeofSubsystemsComponent,
80         NvmeofTabsComponent,
81         NvmeofSubsystemsDetailsComponent
82       ],
83       imports: [HttpClientModule, RouterTestingModule, SharedModule, ComboBoxModule, GridModule],
84       providers: [
85         { provide: NvmeofService, useClass: MockNvmeOfService },
86         { provide: AuthStorageService, useClass: MockAuthStorageService },
87         { provide: ModalService, useClass: MockModalService },
88         { provide: TaskWrapperService, useClass: MockTaskWrapperService }
89       ]
90     }).compileComponents();
91
92     fixture = TestBed.createComponent(NvmeofSubsystemsComponent);
93     component = fixture.componentInstance;
94     component.ngOnInit();
95     fixture.detectChanges();
96   });
97
98   it('should create', () => {
99     expect(component).toBeTruthy();
100   });
101
102   it('should retrieve subsystems', fakeAsync(() => {
103     component.getSubsystems();
104     tick();
105     expect(component.subsystems).toEqual(mockSubsystems);
106   }));
107
108   it('should load gateway groups correctly', () => {
109     expect(component.gwGroups.length).toBe(2);
110   });
111
112   it('should set first group as default initially', () => {
113     expect(component.group).toBe(mockGroups[0][0].spec.group);
114   });
115 });