Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export class ProfileFormComponent implements OnInit, AfterViewInit {
@ViewChildren(CdkTextareaAutosize)
autosize!: QueryList<CdkTextareaAutosize>;
@Input() profileFormat!: ProfileFormat[];
@Input() isCopyProfile!: boolean;
@Input()
set profiles(profiles: Profile[]) {
this.profileList = profiles;
Expand Down Expand Up @@ -212,7 +213,7 @@ export class ProfileFormComponent implements OnInit, AfterViewInit {
const request: any = {
questions: [],
};
if (profile) {
if (profile && !this.isCopyProfile) {
request.name = profile.name;
request.rename = this.nameControl.value?.trim();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ <h2 class="title" tabindex="-1">Risk assessment</h2>
<div class="main-content">
<app-profile-form
[selectedProfile]="vm.selectedProfile"
[isCopyProfile]="isCopyProfile"
[profiles]="vm.profiles"
[profileFormat]="vm.profileFormat"
(saveProfile)="saveProfileClicked($event, vm.selectedProfile)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,24 @@ describe('RiskAssessmentComponent', () => {
});
});

it('#profileClicked should call openForm with profile', fakeAsync(() => {
spyOn(component, 'openForm');

component.profileClicked(PROFILE_MOCK);
tick();

expect(component.openForm).toHaveBeenCalledWith(PROFILE_MOCK);
}));

it('#copyProfileAndOpenForm should call openForm with copy of profile', fakeAsync(() => {
spyOn(component, 'openForm');

component.copyProfileAndOpenForm(PROFILE_MOCK);
tick();

expect(component.openForm).toHaveBeenCalledWith(COPY_PROFILE_MOCK);
}));

describe('#saveProfile', () => {
describe('with no profile selected', () => {
beforeEach(() => {
Expand Down Expand Up @@ -384,6 +402,7 @@ class FakeProfileItemComponent {
})
class FakeProfileFormComponent {
@Input() profiles!: Profile[];
@Input() isCopyProfile!: boolean;
@Input() selectedProfile!: Profile;
@Input() profileFormat!: ProfileFormat[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { SuccessDialogComponent } from './components/success-dialog/success-dial
export class RiskAssessmentComponent implements OnInit, OnDestroy {
viewModel$ = this.store.viewModel$;
isOpenProfileForm = false;
isCopyProfile = false;
private destroy$: Subject<boolean> = new Subject<boolean>();
constructor(
private store: RiskAssessmentStore,
Expand Down Expand Up @@ -71,6 +72,7 @@ export class RiskAssessmentComponent implements OnInit, OnDestroy {
}

async copyProfileAndOpenForm(profile: Profile) {
this.isCopyProfile = true;
await this.openForm(this.getCopyOfProfile(profile));
}

Expand Down Expand Up @@ -124,7 +126,10 @@ export class RiskAssessmentComponent implements OnInit, OnDestroy {
this.liveAnnouncer.clear();
if (!selectedProfile) {
this.saveProfile(profile, this.store.setFocusOnCreateButton);
} else if (this.compareProfiles(profile, selectedProfile)) {
} else if (
this.compareProfiles(profile, selectedProfile) ||
this.isCopyProfile
) {
this.saveProfile(profile, this.store.setFocusOnSelectedProfile);
} else {
this.openSaveDialog(
Expand Down Expand Up @@ -187,6 +192,7 @@ export class RiskAssessmentComponent implements OnInit, OnDestroy {
discard(selectedProfile: Profile | null) {
this.liveAnnouncer.clear();
this.isOpenProfileForm = false;
this.isCopyProfile = false;
if (selectedProfile) {
timer(100).subscribe(() => {
this.store.setFocusOnSelectedProfile();
Expand Down Expand Up @@ -220,6 +226,7 @@ export class RiskAssessmentComponent implements OnInit, OnDestroy {
},
});
this.isOpenProfileForm = false;
this.isCopyProfile = false;
}

private setFocus(index: number): void {
Expand Down