import { MonitorService } from '~/app/shared/api/monitor.service';
import { ModalCdsService } from '~/app/shared/services/modal-cds.service';
import { Permissions } from '~/app/shared/models/permissions';
+import { FROM_STORAGE_CLASS } from './../../rgw/models/rgw-storage-class.model';
interface FormFieldDescription {
externalFieldName: string;
isApplicationsSelected = true;
msrCrush: boolean = false;
isStretchMode: boolean = false;
+ private fromStorageClass: boolean = false;
+ private previousPath: string = '';
readonly DEFAULT_REPLICATED_MIN_SIZE = 1;
readonly DEFAULT_REPLICATED_MAX_SIZE = 3;
this.resource = $localize`pool`;
this.authenticate();
this.createForm();
+ const nav = this.router.getCurrentNavigation();
+ this.fromStorageClass = nav?.extras?.state?.['from'] === FROM_STORAGE_CLASS;
+ this.previousPath = nav?.extras?.state?.['returnUrl'] || '/pool';
}
authenticate() {
}
this.form.setErrors({ cdSubmitButton: true });
},
- complete: () => this.router.navigate(['/pool'])
+ complete: () => this.navigateAfterPoolForm()
});
}
+ navigateAfterPoolForm(): void {
+ if (this.fromStorageClass) {
+ this.router.navigate([this.previousPath]);
+ } else {
+ this.router.navigate(['/pool']);
+ }
+ }
+
appSelection(events: SelectOption[]) {
this.data.applications.selected = events.map((e: SelectOption) => e.name);
this.form.get('name').updateValueAndValidity({ emitEvent: false, onlySelf: true });
+import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
+import { Router } from '@angular/router';
import { SharedModule } from '~/app/shared/shared.module';
-import { HttpClientTestingModule } from '@angular/common/http/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { CoreModule } from '~/app/core/core.module';
import { RgwStorageClassFormComponent } from './rgw-storage-class-form.component';
import { TIER_TYPE_DISPLAY } from '../models/rgw-storage-class.model';
+import { PoolFormComponent } from '../../pool/pool-form/pool-form.component';
+import { RgwZonegroupService } from '~/app/shared/api/rgw-zonegroup.service';
+import { PoolService } from '~/app/shared/api/pool.service';
+import { of } from 'rxjs';
describe('RgwStorageClassFormComponent', () => {
let component: RgwStorageClassFormComponent;
let fixture: ComponentFixture<RgwStorageClassFormComponent>;
+ let router: Router;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [RgwStorageClassFormComponent]
}).compileComponents();
+ spyOn(TestBed.inject(RgwZonegroupService), 'getAllZonegroupsInfo').and.returnValue(
+ of({ zonegroups: [], default_zonegroup: '' })
+ );
+ spyOn(TestBed.inject(PoolService), 'getList').and.returnValue(of([]));
+
fixture = TestBed.createComponent(RgwStorageClassFormComponent);
component = fixture.componentInstance;
+ router = TestBed.inject(Router);
fixture.detectChanges();
});
expect(component).toBeTruthy();
});
});
+
+ describe('pool form navigation from storage class form', () => {
+ const storageClassReturnUrl = '/rgw/storage-class/create';
+
+ const createPoolFormNavigationContext = (
+ fromStorageClass: boolean,
+ previousPath: string,
+ poolRouter: Router
+ ) => {
+ const poolForm = Object.create(PoolFormComponent.prototype) as PoolFormComponent;
+ (poolForm as any).fromStorageClass = fromStorageClass;
+ (poolForm as any).previousPath = previousPath;
+ (poolForm as any).router = poolRouter;
+ return poolForm;
+ };
+
+ it('should return to storage class form after pool creation when opened from storage class', () => {
+ const navigateSpy = spyOn(router, 'navigate');
+ const poolForm = createPoolFormNavigationContext(true, storageClassReturnUrl, router);
+
+ poolForm.navigateAfterPoolForm();
+
+ expect(navigateSpy).toHaveBeenCalledWith([storageClassReturnUrl]);
+ });
+
+ it('should return to pool list after pool creation when not opened from storage class', () => {
+ const navigateSpy = spyOn(router, 'navigate');
+ const poolForm = createPoolFormNavigationContext(false, '/pool', router);
+
+ poolForm.navigateAfterPoolForm();
+
+ expect(navigateSpy).toHaveBeenCalledWith(['/pool']);
+ });
+
+ it('should return to pool list when pool creation is cancelled outside storage class form', () => {
+ const navigateSpy = spyOn(router, 'navigate');
+ const poolForm = createPoolFormNavigationContext(false, '/pool', router);
+
+ poolForm.navigateAfterPoolForm();
+
+ expect(navigateSpy).toHaveBeenCalledWith(['/pool']);
+ });
+ });
});
AclType,
ZoneRequest,
AllZonesResponse,
- POOL
+ POOL,
+ FROM_STORAGE_CLASS
} from '../models/rgw-storage-class.model';
import { NotificationType } from '~/app/shared/enum/notification-type.enum';
import { NotificationService } from '~/app/shared/services/notification.service';
rgwPools: Pool[];
zones: any[];
POOL = POOL;
+ FROM_STORAGE_CLASS = FROM_STORAGE_CLASS;
constructor(
public actionLabels: ActionLabelsI18n,
this.router.navigate([`rgw/storage-class`]);
}
+ navigateCreatePool(): void {
+ this.router.navigate([POOL.PATH], {
+ state: { from: FROM_STORAGE_CLASS, returnUrl: this.router.url }
+ });
+ }
+
getTierTargetByStorageClass(placementTargetInfo: PlacementTarget, storageClass: string) {
const tierTarget = placementTargetInfo?.tier_targets?.find(
(target: TierTarget) => target.val.storage_class === storageClass