|
1 | | -import { HttpClientTestingModule } from '@angular/common/http/testing'; |
2 | 1 | import { ComponentFixture, TestBed } from '@angular/core/testing'; |
3 | 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'; |
4 | 7 | import { RouterTestingModule } from '@angular/router/testing'; |
5 | 8 | import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; |
6 | 9 | import { ToastrModule } from 'ngx-toastr'; |
7 | 10 | import { SharedModule } from '~/app/shared/shared.module'; |
8 | | - |
9 | | -import { RgwMultisiteZoneFormComponent } from './rgw-multisite-zone-form.component'; |
10 | | -import { configureTestBed } from '~/testing/unit-test-helper'; |
| 11 | +import { RgwZone } from '../models/rgw-multisite'; |
11 | 12 |
|
12 | 13 | describe('RgwMultisiteZoneFormComponent', () => { |
13 | 14 | let component: RgwMultisiteZoneFormComponent; |
14 | 15 | let fixture: ComponentFixture<RgwMultisiteZoneFormComponent>; |
15 | | - |
16 | | - configureTestBed({ |
17 | | - imports: [ |
18 | | - SharedModule, |
19 | | - ReactiveFormsModule, |
20 | | - RouterTestingModule, |
21 | | - HttpClientTestingModule, |
22 | | - ToastrModule.forRoot() |
23 | | - ], |
24 | | - providers: [NgbActiveModal], |
25 | | - declarations: [RgwMultisiteZoneFormComponent] |
26 | | - }); |
| 16 | + let rgwZoneService: RgwZoneService; |
| 17 | + let rgwZoneServiceSpy: jasmine.Spy; |
27 | 18 |
|
28 | 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 | + |
29 | 32 | fixture = TestBed.createComponent(RgwMultisiteZoneFormComponent); |
30 | 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 | + |
31 | 83 | fixture.detectChanges(); |
| 84 | + |
| 85 | + component.getZonePlacementData('default-placement'); |
32 | 86 | }); |
33 | 87 |
|
34 | 88 | it('should create', () => { |
35 | 89 | expect(component).toBeTruthy(); |
36 | 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 | + }); |
37 | 124 | }); |
0 commit comments