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
27 changes: 27 additions & 0 deletions modules/ui/src/app/mocks/profile.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,30 @@ export const RENAME_PROFILE_MOCK = {
name: 'Primary profile',
rename: 'New profile',
};

export const COPY_PROFILE_MOCK: Profile = {
name: 'Copy of Primary profile',
status: ProfileStatus.VALID,
questions: [
{
question: 'What is the email of the device owner(s)?',
answer: 'boddey@google.com, cmeredith@google.com',
},
{
question: 'What type of device do you need reviewed?',
answer: 'IoT Sensor',
},
{
question: 'Are any of the following statements true about your device?',
answer: 'First',
},
{
question: 'What features does the device have?',
answer: [0, 1, 2],
},
{
question: 'Comments',
answer: 'Yes',
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ProfileFormComponent } from './profile-form.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import {
COPY_PROFILE_MOCK,
NEW_PROFILE_MOCK,
NEW_PROFILE_MOCK_DRAFT,
PROFILE_FORM,
Expand Down Expand Up @@ -132,7 +133,6 @@ describe('ProfileFormComponent', () => {
name.dispatchEvent(new Event('input'));
component.nameControl.markAsTouched();

fixture.detectChanges();
fixture.detectChanges();

const nameError = compiled.querySelector('mat-error')?.innerHTML;
Expand Down Expand Up @@ -457,6 +457,15 @@ describe('ProfileFormComponent', () => {
component.nameControl.hasError('has_same_profile_name')
).toBeTrue();
});

it('should have an error when uses the name of copy profile', () => {
component.selectedProfile = COPY_PROFILE_MOCK;
component.profiles = [PROFILE_MOCK, PROFILE_MOCK_2, COPY_PROFILE_MOCK];

expect(
component.nameControl.hasError('has_same_profile_name')
).toBeTrue();
});
});

describe('with no profile', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ export class ProfileFormComponent implements OnInit {
this.getControl(index).setValue(profile.questions[index].answer);
}
});
this.nameControl.markAsTouched();
this.triggerResize();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ export class ProfileValidators {
): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null => {
const value = control.value?.trim();
if (value && profiles.length && (!profile || profile?.name !== value)) {
if (
value &&
profiles.length &&
(!profile ||
!profile.created ||
(profile.created && profile?.name !== value))
) {
const isSameProfileName = this.hasSameProfileName(value, profiles);
return isSameProfileName ? { has_same_profile_name: true } : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@
class="profile-item-button copy"
mat-icon-button
attr.aria-label="Copy {{ profile.name }}"
matTooltip="Copy {{ profile.name }}"
(click)="copyProfileClicked.emit(profile)">
<mat-icon fontSet="material-symbols-outlined"> content_copy </mat-icon>
</button>
<button
class="profile-item-button delete"
mat-icon-button
attr.aria-label="Delete {{ profile.name }}"
matTooltip="Delete {{ profile.name }}"
(click)="deleteButtonClicked.emit(profile.name)">
<mat-icon fontSet="material-symbols-outlined"> delete </mat-icon>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { TestRunService } from '../../services/test-run.service';
import SpyObj = jasmine.SpyObj;
import { MatSidenavModule } from '@angular/material/sidenav';
import { NEW_PROFILE_MOCK, PROFILE_MOCK } from '../../mocks/profile.mock';
import {
COPY_PROFILE_MOCK,
NEW_PROFILE_MOCK,
PROFILE_MOCK,
} from '../../mocks/profile.mock';
import { of } from 'rxjs';
import { Component, Input } from '@angular/core';
import { Profile, ProfileFormat } from '../../model/profile';
Expand Down Expand Up @@ -220,9 +224,7 @@ describe('RiskAssessmentComponent', () => {
describe('#getCopyOfProfile', () => {
it('should open the form with copy of profile', () => {
const copy = component.getCopyOfProfile(PROFILE_MOCK);
expect(copy).toEqual(
Object.assign({}, PROFILE_MOCK, { name: 'Copy of Primary profile' })
);
expect(copy).toEqual(COPY_PROFILE_MOCK);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class RiskAssessmentComponent implements OnInit, OnDestroy {
getCopyOfProfile(profile: Profile): Profile {
const copyOfProfile = { ...profile };
copyOfProfile.name = this.getCopiedProfileName(profile.name);
delete copyOfProfile.created; // new profile is not create yet
return copyOfProfile;
}

Expand Down