]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/blob
bc3edd515229687d6f89853aad8653dfc54c79ad
[ceph-ci.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 { ModalCdsService } from '~/app/shared/services/modal-cds.service';
10 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
11 import { NvmeofSubsystemsComponent } from './nvmeof-subsystems.component';
12 import { NvmeofSubsystemsDetailsComponent } from '../nvmeof-subsystems-details/nvmeof-subsystems-details.component';
13 import { ComboBoxModule, GridModule } from 'carbon-components-angular';
14 import { CephServiceSpec } from '~/app/shared/models/service.interface';
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 const mockformattedGwGroups = [
53   {
54     content: 'default'
55   },
56   {
57     content: 'foo'
58   }
59 ];
60
61 class MockNvmeOfService {
62   listSubsystems() {
63     return of(mockSubsystems);
64   }
65
66   getInitiators() {
67     return of([]);
68   }
69
70   formatGwGroupsList(_data: CephServiceSpec[][]) {
71     return mockformattedGwGroups;
72   }
73
74   listGatewayGroups() {
75     return of(mockGroups);
76   }
77 }
78
79 class MockAuthStorageService {
80   getPermissions() {
81     return { nvmeof: {} };
82   }
83 }
84
85 class MockModalService {}
86
87 class MockTaskWrapperService {}
88
89 describe('NvmeofSubsystemsComponent', () => {
90   let component: NvmeofSubsystemsComponent;
91   let fixture: ComponentFixture<NvmeofSubsystemsComponent>;
92
93   beforeEach(async () => {
94     await TestBed.configureTestingModule({
95       declarations: [NvmeofSubsystemsComponent, NvmeofSubsystemsDetailsComponent],
96       imports: [HttpClientModule, RouterTestingModule, SharedModule, ComboBoxModule, GridModule],
97       providers: [
98         { provide: NvmeofService, useClass: MockNvmeOfService },
99         { provide: AuthStorageService, useClass: MockAuthStorageService },
100         { provide: ModalCdsService, useClass: MockModalService },
101         { provide: TaskWrapperService, useClass: MockTaskWrapperService }
102       ]
103     }).compileComponents();
104
105     fixture = TestBed.createComponent(NvmeofSubsystemsComponent);
106     component = fixture.componentInstance;
107     component.ngOnInit();
108     fixture.detectChanges();
109   });
110
111   it('should create', () => {
112     expect(component).toBeTruthy();
113   });
114
115   it('should retrieve subsystems', fakeAsync(() => {
116     component.getSubsystems();
117     tick();
118     const expected = mockSubsystems.map((s) => ({
119       ...s,
120       gw_group: component.group,
121       auth: 'No authentication',
122       initiator_count: 0
123     }));
124     expect(component.subsystems).toEqual(expected);
125   }));
126
127   it('should load gateway groups correctly', () => {
128     expect(component.gwGroups.length).toBe(2);
129   });
130
131   it('should set first group as default initially', () => {
132     expect(component.group).toBe(mockGroups[0][0].spec.group);
133   });
134 });