]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
5a8d5c3d4bb2a09070e71e5ded469a523fa42cde
[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.zoneGroupDetails = {
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                     retain_head_object: true,
75                     allow_read_through: true,
76                     s3: {
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',
82                       region: 'useastr1',
83                       secret: 'SECRETKEY',
84                       multipart_min_part_size: 87877,
85                       multipart_sync_threshold: 987877,
86                       host_style: true
87                     }
88                   }
89                 }
90               ]
91             },
92             {
93               name: 'placement1',
94               tier_targets: [
95                 {
96                   val: {
97                     storage_class: 'CloudIBM',
98                     tier_type: 'cloud-s3',
99                     retain_head_object: true,
100                     allow_read_through: true,
101                     s3: {
102                       endpoint: 'https://s3.amazonaws.com',
103                       access_key: 'ACCESSKEY',
104                       storage_class: 'GLACIER',
105                       target_path: '/pathStorage',
106                       target_storage_class: 'CloudIBM',
107                       region: 'useast1',
108                       secret: 'SECRETKEY',
109                       multipart_min_part_size: 187988787,
110                       multipart_sync_threshold: 878787878,
111                       host_style: false
112                     }
113                   }
114                 }
115               ]
116             }
117           ]
118         }
119       ]
120     };
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');
125   });
126
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();
144   });
145 });