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.zoneGroupDetails = {
60 default_zonegroup: 'zonegroup1',
68 name: 'default-placement',
72 storage_class: 'CLOUDIBM',
73 tier_type: 'cloud-s3',
74 retain_head_object: true,
75 allow_read_through: true,
77 endpoint: 'https://s3.amazonaws.com',
78 access_key: 'ACCESSKEY',
79 storage_class: 'STANDARD',
80 target_path: '/path/to/storage',
81 target_storage_class: 'STANDARD',
84 multipart_min_part_size: 87877,
85 multipart_sync_threshold: 987877,
97 storage_class: 'CloudIBM',
98 tier_type: 'cloud-s3',
99 retain_head_object: true,
100 allow_read_through: true,
102 endpoint: 'https://s3.amazonaws.com',
103 access_key: 'ACCESSKEY',
104 storage_class: 'GLACIER',
105 target_path: '/pathStorage',
106 target_storage_class: 'CloudIBM',
109 multipart_min_part_size: 187988787,
110 multipart_sync_threshold: 878787878,
121 component.storageClassForm.get('zonegroup').setValue('zonegroup1');
122 component.onZonegroupChange();
123 expect(component.placementTargets).toEqual(['default-placement', 'placement1']);
124 expect(component.storageClassForm.get('placement_target').value).toBe('default-placement');
127 it('should set form values on submit', () => {
128 const storageClassName = 'storageClass1';
129 component.storageClassForm.get('storage_class').setValue(storageClassName);
130 component.storageClassForm.get('zonegroup').setValue('zonegroup1');
131 component.storageClassForm.get('placement_target').setValue('placement1');
132 component.storageClassForm.get('endpoint').setValue('http://ams03.com');
133 component.storageClassForm.get('access_key').setValue('accesskey');
134 component.storageClassForm.get('secret_key').setValue('secretkey');
135 component.storageClassForm.get('target_path').setValue('/target');
136 component.storageClassForm.get('retain_head_object').setValue(true);
137 component.storageClassForm.get('allow_read_through').setValue(true);
138 component.storageClassForm.get('region').setValue('useast1');
139 component.storageClassForm.get('multipart_sync_threshold').setValue(1024);
140 component.storageClassForm.get('multipart_min_part_size').setValue(256);
141 component.goToListView();
142 component.submitAction();
143 expect(component).toBeTruthy();