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 @@ -29,6 +29,7 @@ import { MatSidenavModule } from '@angular/material/sidenav';
import {
COPY_PROFILE_MOCK,
NEW_PROFILE_MOCK,
NEW_PROFILE_MOCK_DRAFT,
PROFILE_MOCK,
} from '../../mocks/profile.mock';
import { of } from 'rxjs';
Expand Down Expand Up @@ -247,17 +248,39 @@ describe('RiskAssessmentComponent', () => {
});

describe('with profile selected', () => {
it('should open save profile modal', fakeAsync(() => {
it('should open save profile modal for valid profile', fakeAsync(() => {
const openSpy = spyOn(component.dialog, 'open').and.returnValue({
afterClosed: () => of(true),
} as MatDialogRef<typeof SimpleDialogComponent>);

component.saveProfileClicked(NEW_PROFILE_MOCK, PROFILE_MOCK);

expect(openSpy).toHaveBeenCalledWith(SimpleDialogComponent, {
ariaLabel: 'Save changes',
ariaLabel: 'Save profile',
data: {
title: 'Save changes',
title: 'Save profile',
content: `You are about to save changes in Primary profile. Are you sure?`,
},
autoFocus: true,
hasBackdrop: true,
disableClose: true,
panelClass: 'simple-dialog',
});

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

it('should open save draft profile modal', fakeAsync(() => {
const openSpy = spyOn(component.dialog, 'open').and.returnValue({
afterClosed: () => of(true),
} as MatDialogRef<typeof SimpleDialogComponent>);

component.saveProfileClicked(NEW_PROFILE_MOCK_DRAFT, PROFILE_MOCK);

expect(openSpy).toHaveBeenCalledWith(SimpleDialogComponent, {
ariaLabel: 'Save draft profile',
data: {
title: 'Save draft profile',
content: `You are about to save changes in Primary profile. Are you sure?`,
},
autoFocus: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { SimpleDialogComponent } from '../../components/simple-dialog/simple-dia
import { Subject, takeUntil } from 'rxjs';
import { MatDialog } from '@angular/material/dialog';
import { LiveAnnouncer } from '@angular/cdk/a11y';
import { Profile } from '../../model/profile';
import { Profile, ProfileStatus } from '../../model/profile';
import { Observable } from 'rxjs/internal/Observable';
import { DeviceValidators } from '../devices/components/device-form/device.validators';

Expand Down Expand Up @@ -116,7 +116,10 @@ export class RiskAssessmentComponent implements OnInit, OnDestroy {
this.saveProfile(profile);
this.store.setFocusOnCreateButton();
} else {
this.openSaveDialog(selectedProfile.name)
this.openSaveDialog(
selectedProfile.name,
profile.status === ProfileStatus.DRAFT
)
.pipe(takeUntil(this.destroy$))
.subscribe(saveProfile => {
if (saveProfile) {
Expand Down Expand Up @@ -160,11 +163,14 @@ export class RiskAssessmentComponent implements OnInit, OnDestroy {
this.store.setFocus({ nextItem, firstItem });
}

private openSaveDialog(profileName: string): Observable<boolean> {
private openSaveDialog(
profileName: string,
draft: boolean = false
): Observable<boolean> {
const dialogRef = this.dialog.open(SimpleDialogComponent, {
ariaLabel: 'Save changes',
ariaLabel: `Save ${draft ? 'draft profile' : 'profile'}`,
data: {
title: 'Save changes',
title: `Save ${draft ? 'draft profile' : 'profile'}`,
content: `You are about to save changes in ${profileName}. Are you sure?`,
},
autoFocus: true,
Expand Down