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';
17 } from 'carbon-components-angular';
18 import { CdLabelComponent } from '~/app/shared/components/cd-label/cd-label.component';
19 import { RouterTestingModule } from '@angular/router/testing';
21 class MockRgwBucketService {
22 setLifecycle = jest.fn().mockReturnValue(of(null));
23 getLifecycle = jest.fn().mockReturnValue(of(null));
26 describe('RgwBucketTieringFormComponent', () => {
27 let component: RgwBucketTieringFormComponent;
28 let fixture: ComponentFixture<RgwBucketTieringFormComponent>;
29 let rgwBucketService: MockRgwBucketService;
32 declarations: [RgwBucketTieringFormComponent, CdLabelComponent],
35 HttpClientTestingModule,
40 ToastrModule.forRoot(),
47 { provide: 'bucket', useValue: { bucket: 'bucket1', owner: 'dashboard' } },
48 { provide: RgwBucketService, useClass: MockRgwBucketService }
53 fixture = TestBed.createComponent(RgwBucketTieringFormComponent);
54 component = fixture.componentInstance;
55 fixture.detectChanges();
56 rgwBucketService = (TestBed.inject(RgwBucketService) as unknown) as MockRgwBucketService;
59 it('should create', () => {
60 expect(component).toBeTruthy();
63 it('should call setLifecyclePolicy function', () => {
65 component.tieringForm.setValue({
67 storageClass: 'CLOUD',
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(
82 JSON.stringify(component.configuredLifecycle.LifecycleConfiguration),