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 @@ -45,7 +45,7 @@
[profileFormat]="vm.profileFormat"
(saveProfile)="saveProfileClicked($event, vm.selectedProfile)"
(deleteCopy)="deleteCopy($event, vm.profiles)"
(delete)="deleteProfile($event)"
(delete)="deleteProfile($event, vm.profiles)"
(copyProfile)="copyProfile($event, vm.profiles)"
(discard)="discard($event, vm.profiles)"></app-profile-form>
</ng-template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ describe('RiskAssessmentComponent', () => {
} as MatDialogRef<typeof SimpleDialogComponent>);
tick();

component.deleteProfile(PROFILE_MOCK);
component.deleteProfile(PROFILE_MOCK, [PROFILE_MOCK]);
tick();

expect(openSpy).toHaveBeenCalledWith(SimpleDialogComponent, {
Expand Down Expand Up @@ -235,14 +235,29 @@ describe('RiskAssessmentComponent', () => {

tick();

component.deleteProfile(PROFILE_MOCK);
component.deleteProfile(PROFILE_MOCK, [PROFILE_MOCK]);
tick();

expect(
mockRiskAssessmentStore.updateSelectedProfile
).toHaveBeenCalledWith(null);
expect(component.isOpenProfileForm).toBeFalse();
}));

it('should remove copy and close form when unsaved copy is deleted', fakeAsync(() => {
spyOn(component.dialog, 'open').and.returnValue({
afterClosed: () => of(true),
} as MatDialogRef<typeof SimpleDialogComponent>);
component.isCopyProfile = true;
component.deleteProfile(PROFILE_MOCK, [PROFILE_MOCK]);
tick();

expect(mockRiskAssessmentStore.removeProfile).toHaveBeenCalled();
expect(
mockRiskAssessmentStore.updateSelectedProfile
).toHaveBeenCalledWith(null);
expect(component.isOpenProfileForm).toBeFalse();
}));
});

describe('#openForm', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class RiskAssessmentComponent
return copyOfProfile;
}

deleteProfile(profile: Profile): void {
deleteProfile(profile: Profile, profiles: Profile[]): void {
const profileName = profile.name;
const dialogRef = this.dialog.open(SimpleDialogComponent, {
data: {
Expand All @@ -169,15 +169,22 @@ export class RiskAssessmentComponent
.pipe(takeUntil(this.destroy$))
.subscribe(deleteProfile => {
if (deleteProfile) {
this.store.deleteProfile({
name: profileName,
onDelete: (idx = 0) => {
this.closeFormAfterDelete(profileName, profile);
timer(100).subscribe(() => {
this.setFocus(idx);
});
},
});
if (profile && this.isCopyProfile) {
this.deleteCopy(profile, profiles);
this.closeFormAfterDelete(profile.name, profile);
this.focusAddButton();
return;
} else {
this.store.deleteProfile({
name: profileName,
onDelete: (idx = 0) => {
this.closeFormAfterDelete(profileName, profile);
timer(100).subscribe(() => {
this.setFocus(idx);
});
},
});
}
} else {
this.store.setFocusOnSelectedProfile();
}
Expand Down Expand Up @@ -279,7 +286,7 @@ export class RiskAssessmentComponent
this.copyProfileAndOpenForm(entity, profiles);
break;
case ProfileAction.Delete:
this.deleteProfile(entity);
this.deleteProfile(entity, profiles);
break;
}
}
Expand Down
Loading