1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
3 import { SharedModule } from '~/app/shared/shared.module';
4 import { HttpClientTestingModule } from '@angular/common/http/testing';
5 import { RouterTestingModule } from '@angular/router/testing';
6 import { ReactiveFormsModule } from '@angular/forms';
7 import { ToastrModule } from 'ngx-toastr';
14 } from 'carbon-components-angular';
15 import { CoreModule } from '~/app/core/core.module';
16 import { RgwStorageClassFormComponent } from './rgw-storage-class-form.component';
18 describe('RgwStorageClassFormComponent', () => {
19 let component: RgwStorageClassFormComponent;
20 let fixture: ComponentFixture<RgwStorageClassFormComponent>;
22 beforeEach(async () => {
23 await TestBed.configureTestingModule({
25 BrowserAnimationsModule,
27 HttpClientTestingModule,
30 ToastrModule.forRoot(),
38 declarations: [RgwStorageClassFormComponent]
39 }).compileComponents();
41 fixture = TestBed.createComponent(RgwStorageClassFormComponent);
42 component = fixture.componentInstance;
43 fixture.detectChanges();
46 it('should create', () => {
47 component.goToListView();
48 expect(component).toBeTruthy();
51 it('should initialize the form with empty values', () => {
52 const storageClassForm = component.storageClassForm;
53 expect(storageClassForm).toBeTruthy();
54 expect(storageClassForm.get('zonegroup')).toBeTruthy();
55 expect(storageClassForm.get('placement_target')).toBeTruthy();
58 it('on zonegroup changes', () => {
59 component.zoneGroupDeatils = {
60 default_zonegroup: 'zonegroup1',
68 name: 'default-placement',
72 storage_class: 'CLOUDIBM',
73 tier_type: 'cloud-s3',
75 endpoint: 'https://s3.amazonaws.com',
76 access_key: 'ACCESSKEY',
77 storage_class: 'STANDARD',
78 target_path: '/path/to/storage',
79 target_storage_class: 'STANDARD',
82 multipart_min_part_size: 87877,
83 multipart_sync_threshold: 987877,
95 storage_class: 'CloudIBM',
96 tier_type: 'cloud-s3',
98 endpoint: 'https://s3.amazonaws.com',
99 access_key: 'ACCESSKEY',
100 storage_class: 'GLACIER',
101 target_path: '/pathStorage',
102 target_storage_class: 'CloudIBM',
105 multipart_min_part_size: 187988787,
106 multipart_sync_threshold: 878787878,
117 component.storageClassForm.get('zonegroup').setValue('zonegroup1');
118 component.onZonegroupChange();
119 expect(component.placementTargets).toEqual(['default-placement', 'placement1']);
120 expect(component.storageClassForm.get('placement_target').value).toBe('default-placement');
123 it('should set form values on submit', () => {
124 const storageClassName = 'storageClass1';
125 component.storageClassForm.get('storage_class').setValue(storageClassName);
126 component.storageClassForm.get('zonegroup').setValue('zonegroup1');
127 component.storageClassForm.get('placement_target').setValue('placement1');
128 component.storageClassForm.get('endpoint').setValue('http://ams03.com');
129 component.storageClassForm.get('access_key').setValue('accesskey');
130 component.storageClassForm.get('secret_key').setValue('secretkey');
131 component.storageClassForm.get('target_path').setValue('/target');
132 component.storageClassForm.get('retain_head_object').setValue(true);
133 component.storageClassForm.get('region').setValue('useast1');
134 component.storageClassForm.get('multipart_sync_threshold').setValue(1024);
135 component.storageClassForm.get('multipart_min_part_size').setValue(256);
136 component.goToListView();
137 component.submitAction();
138 expect(component).toBeTruthy();