});
});
+ describe('host type change events', () => {
+ it('should emit host type changes for parent step visibility', () => {
+ const emitSpy = spyOn(component.hostTypeChanged, 'emit');
+ form.get('hostType')?.setValue(component.HOST_TYPE.ALL);
+
+ expect(emitSpy).toHaveBeenCalledWith(component.HOST_TYPE.ALL);
+ });
+ });
+
describe('custom NQN validator', () => {
it('should mark invalid NQN format', () => {
form.get('hostname')?.setValue('invalid-nqn');
-import { Component, Input, OnInit, TemplateRef, ViewChild, ViewEncapsulation } from '@angular/core';
+import {
+ Component,
+ EventEmitter,
+ Input,
+ OnInit,
+ Output,
+ TemplateRef,
+ ViewChild,
+ ViewEncapsulation
+} from '@angular/core';
import { FormControl, UntypedFormControl } from '@angular/forms';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
@Input() group!: string;
@Input() existingHosts: string[] = [];
@Input() allowAllHosts = true;
+ @Output() hostTypeChanged = new EventEmitter<string>();
@ViewChild('rightInfluencer', { static: true })
rightInfluencer?: TemplateRef<any>;
formGroup: CdFormGroup;
ngOnInit() {
this.createForm();
- this.formGroup.get('hostType')?.valueChanges.subscribe(() => {
+ this.formGroup.get('hostType')?.valueChanges.subscribe((hostType: string) => {
+ this.hostTypeChanged.emit(hostType);
this.formGroup.get('hostname')?.updateValueAndValidity();
});
this.formGroup.get('hostname')?.updateValueAndValidity();
});
+ this.hostTypeChanged.emit(this.formGroup.get('hostType')?.value);
this.formGroup.get('hostname')?.updateValueAndValidity();
}
<cd-nvmeof-subsystem-step-two
#tearsheetStep
[group]="group"
+ (hostTypeChanged)="onHostTypeChanged($event)"
></cd-nvmeof-subsystem-step-two>
</cd-tearsheet-step>
@if (showAuthStep) {
gw_group: mockGroupName
});
});
+
+ it('should hide authentication step when host type is ALL', () => {
+ component.onHostTypeChanged(HOST_TYPE.ALL);
+
+ expect(component.showAuthStep).toBeFalsy();
+ expect(component.steps.some((step) => step.label === 'Authentication')).toBeFalsy();
+ });
+
+ it('should show authentication step when host type is SPECIFIC', () => {
+ component.onHostTypeChanged(HOST_TYPE.ALL);
+ component.onHostTypeChanged(HOST_TYPE.SPECIFIC);
+
+ expect(component.showAuthStep).toBeTruthy();
+ expect(component.steps.some((step) => step.label === 'Authentication')).toBeTruthy();
+ });
});
});
this.rebuildSteps();
}
+ onHostTypeChanged(hostType: string) {
+ this.setAuthStepVisibility(this.shouldShowAuthStep(hostType));
+ }
+
private setAuthStepVisibility(nextShowAuth: boolean) {
if (this.showAuthStep === nextShowAuth) return;
this.showAuthStep = nextShowAuth;
this.rebuildSteps();
}
+ private shouldShowAuthStep(hostType: string | null | undefined): boolean {
+ return (hostType ?? HOST_TYPE.SPECIFIC) === HOST_TYPE.SPECIFIC;
+ }
+
populateReviewData() {
if (!this.tearsheet) return;
this.stepTwoValue = step2;
}
- const nextShowAuth = (step2?.hostType ?? HOST_TYPE.SPECIFIC) === HOST_TYPE.SPECIFIC;
+ const nextShowAuth = this.shouldShowAuthStep(step2?.hostType);
if (nextShowAuth !== this.showAuthStep) {
this.setAuthStepVisibility(nextShowAuth);