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';
13 describe('RgwMultisiteZoneFormComponent', () => {
14 let component: RgwMultisiteZoneFormComponent;
15 let fixture: ComponentFixture<RgwMultisiteZoneFormComponent>;
16 let rgwZoneService: RgwZoneService;
17 let rgwZoneServiceSpy: jasmine.Spy;
20 TestBed.configureTestingModule({
25 HttpClientTestingModule,
26 ToastrModule.forRoot()
28 providers: [NgbActiveModal],
29 declarations: [RgwMultisiteZoneFormComponent]
30 }).compileComponents();
32 fixture = TestBed.createComponent(RgwMultisiteZoneFormComponent);
33 component = fixture.componentInstance;
34 rgwZoneService = TestBed.inject(RgwZoneService);
36 rgwZoneServiceSpy = spyOn(rgwZoneService, 'get');
38 rgwZoneServiceSpy.and.returnValue(
42 key: 'default-placement',
46 data_pool: 'standard-data-pool',
47 compression_type: 'gzip'
50 index_pool: 'index-pool',
51 data_extra_pool: 'extra-data-pool'
63 { name: 'default-placement', tags: [], storage_classes: ['STANDARD'] }
65 default_placement: 'default-placement'
73 endpoints: ['http://192.168.100.100:80'],
74 access_key: 'zxcftyuuhgg',
75 secret_key: 'Qwsdcfgghuiioklpoozsd'
79 component.zone = new RgwZone();
80 component.zone.name = component.info.data.name;
81 component.action = 'edit';
83 fixture.detectChanges();
85 component.getZonePlacementData('default-placement');
88 it('should create', () => {
89 expect(component).toBeTruthy();
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'
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');
108 it('should create a new zone', () => {
109 component.action = 'create';
110 const createSpy = spyOn(rgwZoneService, 'create').and.returnValue(of({}));
112 expect(createSpy).toHaveBeenCalledWith(
114 endpoints: 'http://192.168.100.100:80',
116 system_key: { access_key: 'zxcftyuuhgg', secret_key: 'Qwsdcfgghuiioklpoozsd' }
118 { name: 'zonegroup2' },
121 'http://192.168.100.100:80'