]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
1e134eb0bf4b3ac01c659d026932e64eb32a7b02
[ceph.git] /
1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2 import { ReactiveFormsModule } from '@angular/forms';
3 import { RgwMultisiteZoneFormComponent } from './rgw-multisite-zone-form.component'; // Adjust path as necessary
4 import { of } from 'rxjs';
5 import { RgwZoneService } from '~/app/shared/api/rgw-zone.service';
6 import { HttpClientTestingModule } from '@angular/common/http/testing';
7 import { RouterTestingModule } from '@angular/router/testing';
8 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
9 import { ToastrModule } from 'ngx-toastr';
10 import { SharedModule } from '~/app/shared/shared.module';
11 import { RgwZone } from '../models/rgw-multisite';
12
13 describe('RgwMultisiteZoneFormComponent', () => {
14   let component: RgwMultisiteZoneFormComponent;
15   let fixture: ComponentFixture<RgwMultisiteZoneFormComponent>;
16   let rgwZoneService: RgwZoneService;
17   let rgwZoneServiceSpy: jasmine.Spy;
18
19   beforeEach(() => {
20     TestBed.configureTestingModule({
21       imports: [
22         SharedModule,
23         ReactiveFormsModule,
24         RouterTestingModule,
25         HttpClientTestingModule,
26         ToastrModule.forRoot()
27       ],
28       providers: [NgbActiveModal],
29       declarations: [RgwMultisiteZoneFormComponent]
30     }).compileComponents();
31
32     fixture = TestBed.createComponent(RgwMultisiteZoneFormComponent);
33     component = fixture.componentInstance;
34     rgwZoneService = TestBed.inject(RgwZoneService);
35
36     rgwZoneServiceSpy = spyOn(rgwZoneService, 'get');
37
38     rgwZoneServiceSpy.and.returnValue(
39       of({
40         placement_pools: [
41           {
42             key: 'default-placement',
43             val: {
44               storage_classes: {
45                 STANDARD: {
46                   data_pool: 'standard-data-pool',
47                   compression_type: 'gzip'
48                 }
49               },
50               index_pool: 'index-pool',
51               data_extra_pool: 'extra-data-pool'
52             }
53           }
54         ]
55       })
56     );
57
58     component.info = {
59       parent: {
60         data: {
61           name: 'zonegroup2',
62           placement_targets: [
63             { name: 'default-placement', tags: [], storage_classes: ['STANDARD'] }
64           ],
65           default_placement: 'default-placement'
66         }
67       },
68       data: {
69         name: 'zone2',
70         parent: 'zonegroup2',
71         is_default: true,
72         is_master: true,
73         endpoints: ['http://192.168.100.100:80'],
74         access_key: 'zxcftyuuhgg',
75         secret_key: 'Qwsdcfgghuiioklpoozsd'
76       }
77     };
78
79     component.zone = new RgwZone();
80     component.zone.name = component.info.data.name;
81     component.action = 'edit';
82
83     fixture.detectChanges();
84
85     component.getZonePlacementData('default-placement');
86   });
87
88   it('should create', () => {
89     expect(component).toBeTruthy();
90   });
91
92   it('should set correct values in the form on edit', () => {
93     expect(component.multisiteZoneForm.get('zoneName')?.value).toBe('zone2');
94     expect(component.multisiteZoneForm.get('selectedZonegroup')?.value).toBe('zonegroup2');
95     expect(component.multisiteZoneForm.get('default_zone')?.value).toBe(true);
96     expect(component.multisiteZoneForm.get('master_zone')?.value).toBe(true);
97     expect(component.multisiteZoneForm.get('zone_endpoints')?.value).toBe(
98       'http://192.168.100.100:80'
99     );
100     expect(component.multisiteZoneForm.get('access_key')?.value).toBe('zxcftyuuhgg');
101     expect(component.multisiteZoneForm.get('secret_key')?.value).toBe('Qwsdcfgghuiioklpoozsd');
102     expect(component.multisiteZoneForm.get('placementTarget')?.value).toBe('default-placement');
103     expect(component.multisiteZoneForm.get('storageClass')?.value).toBe('STANDARD');
104     expect(component.multisiteZoneForm.get('storageDataPool')?.value).toBe('standard-data-pool');
105     expect(component.multisiteZoneForm.get('storageCompression')?.value).toBe('gzip');
106   });
107
108   it('should create a new zone', () => {
109     component.action = 'create';
110     const createSpy = spyOn(rgwZoneService, 'create').and.returnValue(of({}));
111     component.submit();
112     expect(createSpy).toHaveBeenCalledWith(
113       {
114         endpoints: 'http://192.168.100.100:80',
115         name: 'zone2',
116         system_key: { access_key: 'zxcftyuuhgg', secret_key: 'Qwsdcfgghuiioklpoozsd' }
117       },
118       { name: 'zonegroup2' },
119       true,
120       true,
121       'http://192.168.100.100:80'
122     );
123   });
124 });