]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
48c368692aac0843dcce61302428d75092fceb62
[ceph.git] /
1 import { ComponentFixture, TestBed } from '@angular/core/testing';
2 import { HttpClientTestingModule } from '@angular/common/http/testing';
3 import { RgwBucketTieringFormComponent } from './rgw-bucket-tiering-form.component';
4 import { configureTestBed } from '~/testing/unit-test-helper';
5 import { of } from 'rxjs';
6 import { RgwBucketService } from '~/app/shared/api/rgw-bucket.service';
7 import { ReactiveFormsModule } from '@angular/forms';
8 import { ToastrModule } from 'ngx-toastr';
9 import { ComponentsModule } from '~/app/shared/components/components.module';
10 import {
11   InputModule,
12   ModalModule,
13   ModalService,
14   NumberModule,
15   RadioModule,
16   SelectModule
17 } from 'carbon-components-angular';
18 import { CdLabelComponent } from '~/app/shared/components/cd-label/cd-label.component';
19 import { RouterTestingModule } from '@angular/router/testing';
20
21 class MockRgwBucketService {
22   setLifecycle = jest.fn().mockReturnValue(of(null));
23   getLifecycle = jest.fn().mockReturnValue(of(null));
24 }
25
26 describe('RgwBucketTieringFormComponent', () => {
27   let component: RgwBucketTieringFormComponent;
28   let fixture: ComponentFixture<RgwBucketTieringFormComponent>;
29   let rgwBucketService: MockRgwBucketService;
30
31   configureTestBed({
32     declarations: [RgwBucketTieringFormComponent, CdLabelComponent],
33     imports: [
34       ReactiveFormsModule,
35       HttpClientTestingModule,
36       RadioModule,
37       SelectModule,
38       NumberModule,
39       InputModule,
40       ToastrModule.forRoot(),
41       ComponentsModule,
42       ModalModule,
43       RouterTestingModule
44     ],
45     providers: [
46       ModalService,
47       { provide: 'bucket', useValue: { bucket: 'bucket1', owner: 'dashboard' } },
48       { provide: RgwBucketService, useClass: MockRgwBucketService }
49     ]
50   });
51
52   beforeEach(() => {
53     fixture = TestBed.createComponent(RgwBucketTieringFormComponent);
54     component = fixture.componentInstance;
55     fixture.detectChanges();
56     rgwBucketService = (TestBed.inject(RgwBucketService) as unknown) as MockRgwBucketService;
57   });
58
59   it('should create', () => {
60     expect(component).toBeTruthy();
61   });
62
63   it('should call setLifecyclePolicy function', () => {
64     component.ngOnInit();
65     component.tieringForm.setValue({
66       name: 'test',
67       storageClass: 'CLOUD',
68       hasPrefix: false,
69       prefix: '',
70       tags: [],
71       status: 'Enabled',
72       days: 60
73     });
74     const createTieringSpy = jest.spyOn(component, 'submitTieringConfig');
75     const setLifecycleSpy = jest.spyOn(rgwBucketService, 'setLifecycle').mockReturnValue(of(null));
76     component.submitTieringConfig();
77     expect(createTieringSpy).toHaveBeenCalled();
78     expect(component.tieringForm.valid).toBe(true);
79     expect(setLifecycleSpy).toHaveBeenCalled();
80     expect(setLifecycleSpy).toHaveBeenCalledWith(
81       'bucket1',
82       JSON.stringify(component.configuredLifecycle.LifecycleConfiguration),
83       'dashboard'
84     );
85   });
86 });