]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/blob
413cec31ce346543376382a5400eb31890a99183
[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 { 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 { 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   formatGwGroupsList(_data: CephServiceSpec[][]) {
67     return mockformattedGwGroups;
68   }
69
70   listGatewayGroups() {
71     return of(mockGroups);
72   }
73 }
74
75 class MockAuthStorageService {
76   getPermissions() {
77     return { nvmeof: {} };
78   }
79 }
80
81 class MockModalService {}
82
83 class MockTaskWrapperService {}
84
85 describe('NvmeofSubsystemsComponent', () => {
86   let component: NvmeofSubsystemsComponent;
87   let fixture: ComponentFixture<NvmeofSubsystemsComponent>;
88
89   beforeEach(async () => {
90     await TestBed.configureTestingModule({
91       declarations: [NvmeofSubsystemsComponent, NvmeofSubsystemsDetailsComponent],
92       imports: [HttpClientModule, RouterTestingModule, SharedModule, ComboBoxModule, GridModule],
93       providers: [
94         { provide: NvmeofService, useClass: MockNvmeOfService },
95         { provide: AuthStorageService, useClass: MockAuthStorageService },
96         { provide: ModalService, useClass: MockModalService },
97         { provide: TaskWrapperService, useClass: MockTaskWrapperService }
98       ]
99     }).compileComponents();
100
101     fixture = TestBed.createComponent(NvmeofSubsystemsComponent);
102     component = fixture.componentInstance;
103     component.ngOnInit();
104     fixture.detectChanges();
105   });
106
107   it('should create', () => {
108     expect(component).toBeTruthy();
109   });
110
111   it('should retrieve subsystems', fakeAsync(() => {
112     component.getSubsystems();
113     tick();
114     expect(component.subsystems).toEqual(mockSubsystems);
115   }));
116
117   it('should load gateway groups correctly', () => {
118     expect(component.gwGroups.length).toBe(2);
119   });
120
121   it('should set first group as default initially', () => {
122     expect(component.group).toBe(mockGroups[0][0].spec.group);
123   });
124 });