{ }); }); + 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(() => { @@ -384,6 +402,7 @@ class FakeProfileItemComponent { }) class FakeProfileFormComponent { @Input() profiles!: Profile[]; + @Input() isCopyProfile!: boolean; @Input() selectedProfile!: Profile; @Input() profileFormat!: ProfileFormat[]; } diff --git a/modules/ui/src/app/pages/risk-assessment/risk-assessment.component.ts b/modules/ui/src/app/pages/risk-assessment/risk-assessment.component.ts index b6eae14e2..787a116ef 100644 --- a/modules/ui/src/app/pages/risk-assessment/risk-assessment.component.ts +++ b/modules/ui/src/app/pages/risk-assessment/risk-assessment.component.ts @@ -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 = new Subject(); constructor( private store: RiskAssessmentStore, @@ -71,6 +72,7 @@ export class RiskAssessmentComponent implements OnInit, OnDestroy { } async copyProfileAndOpenForm(profile: Profile) { + this.isCopyProfile = true; await this.openForm(this.getCopyOfProfile(profile)); } @@ -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( @@ -220,6 +225,7 @@ export class RiskAssessmentComponent implements OnInit, OnDestroy { }, }); this.isOpenProfileForm = false; + this.isCopyProfile = false; } private setFocus(index: number): void { From 5f0ea2b2d69fcc76ac4a20f00e3137079b7a5e86 Mon Sep 17 00:00:00 2001 From: Volha Mardvilka Date: Mon, 21 Oct 2024 12:04:01 +0000 Subject: [PATCH 2/2] 374055268: (fix) prevent overwrite copied profile --- .../src/app/pages/risk-assessment/risk-assessment.component.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/ui/src/app/pages/risk-assessment/risk-assessment.component.ts b/modules/ui/src/app/pages/risk-assessment/risk-assessment.component.ts index 787a116ef..e30efe710 100644 --- a/modules/ui/src/app/pages/risk-assessment/risk-assessment.component.ts +++ b/modules/ui/src/app/pages/risk-assessment/risk-assessment.component.ts @@ -192,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();