]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
c7e7a6b5c5adb07ff6583a83fba6786b76b006ea
[ceph.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 import { TIER_TYPE_DISPLAY } from '../models/rgw-storage-class.model';
18
19 describe('RgwStorageClassFormComponent', () => {
20   let component: RgwStorageClassFormComponent;
21   let fixture: ComponentFixture<RgwStorageClassFormComponent>;
22
23   beforeEach(async () => {
24     await TestBed.configureTestingModule({
25       imports: [
26         BrowserAnimationsModule,
27         SharedModule,
28         HttpClientTestingModule,
29         RouterTestingModule,
30         ReactiveFormsModule,
31         ToastrModule.forRoot(),
32         GridModule,
33         InputModule,
34         CoreModule,
35         SelectModule,
36         ComboBoxModule,
37         CheckboxModule
38       ],
39       declarations: [RgwStorageClassFormComponent]
40     }).compileComponents();
41
42     fixture = TestBed.createComponent(RgwStorageClassFormComponent);
43     component = fixture.componentInstance;
44     fixture.detectChanges();
45   });
46
47   it('should create', () => {
48     component.goToListView();
49     expect(component).toBeTruthy();
50   });
51
52   it('should initialize the form with empty values', () => {
53     const storageClassForm = component.storageClassForm;
54     expect(storageClassForm).toBeTruthy();
55     expect(storageClassForm.get('zonegroup')).toBeTruthy();
56     expect(storageClassForm.get('placement_target')).toBeTruthy();
57   });
58
59   it('on zonegroup changes', () => {
60     component.zoneGroupDetails = {
61       default_zonegroup: 'zonegroup1',
62       name: 'zonegrp1',
63       zonegroups: [
64         {
65           name: 'zonegroup1',
66           id: 'zonegroup-id-1',
67           placement_targets: [
68             {
69               name: 'default-placement',
70               tier_targets: [
71                 {
72                   key: 'test',
73                   val: {
74                     tier_type: 'cloud-s3',
75                     retain_head_object: true,
76                     storage_class: 'CLOUDIBM',
77                     allow_read_through: true,
78                     read_through_restore_days: 1,
79                     restore_storage_class: 'test67',
80                     s3: {
81                       storage_class: 'CLOUDIBM',
82                       endpoint: 'https://s3.amazonaws.com',
83                       access_key: 'ACCESSKEY',
84                       target_path: '/path/to/storage',
85                       target_storage_class: 'STANDARD',
86                       region: 'useastr1',
87                       secret: 'SECRETKEY',
88                       multipart_min_part_size: 87877,
89                       multipart_sync_threshold: 987877,
90                       host_style: true
91                     },
92                     's3-glacier': {
93                       glacier_restore_days: 5,
94                       glacier_restore_tier_type: 'Standard'
95                     }
96                   }
97                 }
98               ]
99             }
100           ]
101         }
102       ]
103     };
104     component.storageClassForm.get('zonegroup').setValue('zonegroup1');
105     component.onZonegroupChange();
106     expect(component.placementTargets).toEqual(['default-placement']);
107     expect(component.storageClassForm.get('placement_target').value).toBe('default-placement');
108   });
109
110   it('should set form values on submit', () => {
111     const storageClassName = 'storageClass1';
112     component.storageClassForm.get('storage_class').setValue(storageClassName);
113     component.storageClassForm.get('zonegroup').setValue('zonegroup1');
114     component.storageClassForm.get('placement_target').setValue('placement1');
115     component.storageClassForm.get('endpoint').setValue('http://ams03.com');
116     component.storageClassForm.get('access_key').setValue('accesskey');
117     component.storageClassForm.get('secret_key').setValue('secretkey');
118     component.storageClassForm.get('target_path').setValue('/target');
119     component.storageClassForm.get('retain_head_object').setValue(true);
120     component.storageClassForm.get('allow_read_through').setValue(true);
121     component.storageClassForm.get('region').setValue('useast1');
122     component.storageClassForm.get('multipart_sync_threshold').setValue(1024);
123     component.storageClassForm.get('multipart_min_part_size').setValue(256);
124     component.goToListView();
125     component.submitAction();
126     expect(component).toBeTruthy();
127   });
128
129   it('should set required validators for CLOUD_TIER fields', () => {
130     (component as any).updateValidatorsBasedOnStorageClass(TIER_TYPE_DISPLAY.CLOUD_TIER);
131     const requiredFields = ['region', 'endpoint', 'access_key', 'secret_key', 'target_path'];
132     requiredFields.forEach((field) => {
133       const control = component.storageClassForm.get(field);
134       control.setValue('');
135       control.updateValueAndValidity();
136     });
137     ['glacier_restore_tier_type', 'restore_storage_class'].forEach((field) => {
138       const control = component.storageClassForm.get(field);
139       control.setValue('');
140       control.updateValueAndValidity();
141       expect(component).toBeTruthy();
142     });
143   });
144
145   it('should set required validators for GLACIER fields', () => {
146     (component as any).updateValidatorsBasedOnStorageClass(TIER_TYPE_DISPLAY.GLACIER);
147     const requiredFields = [
148       'region',
149       'endpoint',
150       'access_key',
151       'secret_key',
152       'target_path',
153       'glacier_restore_tier_type',
154       'restore_storage_class'
155     ];
156     requiredFields.forEach((field) => {
157       const control = component.storageClassForm.get(field);
158       control.setValue('');
159       control.updateValueAndValidity();
160       expect(component).toBeTruthy();
161     });
162   });
163
164   it('should clear validators for LOCAL fields', () => {
165     (component as any).updateValidatorsBasedOnStorageClass(TIER_TYPE_DISPLAY.LOCAL);
166
167     const allFields = [
168       'region',
169       'endpoint',
170       'access_key',
171       'secret_key',
172       'target_path',
173       'glacier_restore_tier_type',
174       'restore_storage_class'
175     ];
176     allFields.forEach((field) => {
177       const control = component.storageClassForm.get(field);
178       control.setValue('');
179       control.updateValueAndValidity();
180       expect(component).toBeTruthy();
181     });
182   });
183 });