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 @@ -46,7 +46,7 @@ <h2 class="profiles-drawer-header-title">Saved profiles</h2>
*ngFor="let profile of vm.profiles; let i = index"
[profile]="profile"
class="profile-item-{{ i }}"
(deleteButtonClicked)="deleteProfile($event, i)"
(deleteButtonClicked)="deleteProfile($event, i, vm.selectedProfile)"
(profileClicked)="openForm($event)">
</app-profile-item>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ describe('RiskAssessmentComponent', () => {
} as MatDialogRef<typeof SimpleDialogComponent>);
tick();

component.deleteProfile(PROFILE_MOCK.name, 0);
component.deleteProfile(PROFILE_MOCK.name, 0, null);
tick();

expect(openSpy).toHaveBeenCalledWith(SimpleDialogComponent, {
Expand All @@ -183,6 +183,21 @@ describe('RiskAssessmentComponent', () => {

openSpy.calls.reset();
}));

it('should close form and set selected profile to null if selected profile was deleted', fakeAsync(() => {
spyOn(component.dialog, 'open').and.returnValue({
afterClosed: () => of(true),
} as MatDialogRef<typeof SimpleDialogComponent>);
tick();

component.deleteProfile(PROFILE_MOCK.name, 0, PROFILE_MOCK);
tick();

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 @@ -62,7 +62,11 @@ export class RiskAssessmentComponent implements OnInit, OnDestroy {
this.focusManagerService.focusFirstElementInContainer();
}

deleteProfile(profileName: string, index: number): void {
deleteProfile(
profileName: string,
index: number,
selectedProfile: Profile | null
): void {
const dialogRef = this.dialog.open(SimpleDialogComponent, {
ariaLabel: 'Delete risk profile',
data: {
Expand All @@ -81,6 +85,7 @@ export class RiskAssessmentComponent implements OnInit, OnDestroy {
.subscribe(deleteProfile => {
if (deleteProfile) {
this.store.deleteProfile(profileName);
this.closeFormAfterDelete(profileName, selectedProfile);
this.setFocus(index);
}
});
Expand All @@ -100,6 +105,13 @@ export class RiskAssessmentComponent implements OnInit, OnDestroy {
}
}

private closeFormAfterDelete(name: string, selectedProfile: Profile | null) {
if (selectedProfile?.name === name) {
this.isOpenProfileForm = false;
this.store.updateSelectedProfile(null);
}
}

private saveProfile(profile: Profile) {
this.store.saveProfile(profile);
this.isOpenProfileForm = false;
Expand Down