]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
2f1c43ca6c168ed500c1cbc73b11d9a793f7f3e9
[ceph-ci.git] /
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';
8 import {
9   CheckboxModule,
10   ComboBoxModule,
11   GridModule,
12   InputModule,
13   SelectModule
14 } from 'carbon-components-angular';
15 import { CoreModule } from '~/app/core/core.module';
16 import { RgwStorageClassFormComponent } from './rgw-storage-class-form.component';
17
18 describe('RgwStorageClassFormComponent', () => {
19   let component: RgwStorageClassFormComponent;
20   let fixture: ComponentFixture<RgwStorageClassFormComponent>;
21
22   beforeEach(async () => {
23     await TestBed.configureTestingModule({
24       imports: [
25         BrowserAnimationsModule,
26         SharedModule,
27         HttpClientTestingModule,
28         RouterTestingModule,
29         ReactiveFormsModule,
30         ToastrModule.forRoot(),
31         GridModule,
32         InputModule,
33         CoreModule,
34         SelectModule,
35         ComboBoxModule,
36         CheckboxModule
37       ],
38       declarations: [RgwStorageClassFormComponent]
39     }).compileComponents();
40
41     fixture = TestBed.createComponent(RgwStorageClassFormComponent);
42     component = fixture.componentInstance;
43     fixture.detectChanges();
44   });
45
46   it('should create', () => {
47     component.goToListView();
48     expect(component).toBeTruthy();
49   });
50
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();
56   });
57
58   it('on zonegroup changes', () => {
59     component.zoneGroupDeatils = {
60       default_zonegroup: 'zonegroup1',
61       name: 'zonegrp1',
62       zonegroups: [
63         {
64           name: 'zonegroup1',
65           id: 'zonegroup-id-1',
66           placement_targets: [
67             {
68               name: 'default-placement',
69               tier_targets: [
70                 {
71                   val: {
72                     storage_class: 'CLOUDIBM',
73                     tier_type: 'cloud-s3',
74                     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',
80                       region: 'useastr1',
81                       secret: 'SECRETKEY',
82                       multipart_min_part_size: 87877,
83                       multipart_sync_threshold: 987877,
84                       host_style: true
85                     }
86                   }
87                 }
88               ]
89             },
90             {
91               name: 'placement1',
92               tier_targets: [
93                 {
94                   val: {
95                     storage_class: 'CloudIBM',
96                     tier_type: 'cloud-s3',
97                     s3: {
98                       endpoint: 'https://s3.amazonaws.com',
99                       access_key: 'ACCESSKEY',
100                       storage_class: 'GLACIER',
101                       target_path: '/pathStorage',
102                       target_storage_class: 'CloudIBM',
103                       region: 'useast1',
104                       secret: 'SECRETKEY',
105                       multipart_min_part_size: 187988787,
106                       multipart_sync_threshold: 878787878,
107                       host_style: false
108                     }
109                   }
110                 }
111               ]
112             }
113           ]
114         }
115       ]
116     };
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');
121   });
122
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();
139   });
140 });