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
@@ -0,0 +1,120 @@
<vitamui-dialog-header
[stepper]="stepper"
[subhead]="'PROFILE.POP_UP_SAVE.SAVE_PROFILE.POPUP_CREATE_PROFILE_NOTICE_TITLE_DIALOG' | translate"
[title]="[
'PROFILE.POP_UP_CREATION.POPUP_CREATION_TITLE_DIALOG' | translate,
'PROFILE.POP_UP_SAVE.SAVE_PROFILE.POPUP_CREATE_NOTICE_TITLE_DIALOG' | translate,
]"
></vitamui-dialog-header>

<form [formGroup]="noticeForm">
<vitamui-stepper #stepper [(selectedIndex)]="stepIndex">
<cdk-step>
<mat-dialog-content>
<div class="gap-5">
<app-pastis-generic-popup
[firstChoice]="ProfileType.PA"
[secondChoice]="ProfileType.PUA"
[title]="'PROFILE.POP_UP_CREATION.CHOICE.TITLE' | translate"
(changeStatusEvent)="noticeForm.controls.profileType.setValue($event)"
>
<i
class="vitamui-icon vitamui-icon-info vitamui-grey-700 clickable"
[style.fontSize.px]="25"
vitamuiTooltip="{{ 'PROFILE.CREATE_PROFILE.INFORMATION.TITRE_PA' | translate }} &#13; {{
'PROFILE.CREATE_PROFILE.INFORMATION.CONTENT_PA' | translate
}} &#13; {{ 'PROFILE.CREATE_PROFILE.INFORMATION.TITRE_PUA' | translate }} &#13; {{
'PROFILE.CREATE_PROFILE.INFORMATION.CONTENT_PUA' | translate
}}"
vitamuiTooltipPosition="RIGHT"
[vitamuiTooltipShowDelay]="300"
></i>
</app-pastis-generic-popup>
<div>
<div class="text bold caption primary">{{ 'PROFILE.CREATE_PROFILE.INFORMATION.SEDA_VERSION' | translate }}</div>
<mat-radio-group class="hgap-2" formControlName="profileVersion">
@for (profileVersionOption of ProfileVersionOptions; track profileVersionOption.version) {
<mat-radio-button [value]="profileVersionOption.version">{{ profileVersionOption.label }}</mat-radio-button>
}
</mat-radio-group>
</div>
</div>
</mat-dialog-content>
<mat-dialog-actions>
<vitamui-next-step [disabled]="!isStepOneValid()"></vitamui-next-step>
<button (click)="onClose()" class="btn cancel link" type="button">
{{ 'COMMON.UNDO' | translate }}
</button>
</mat-dialog-actions>
</cdk-step>
<cdk-step>
<mat-dialog-content>
<mat-dialog-content class="gap-3 align-items-stretch">
<div class="row">
@if (externalIdentifierEnabledSignal()) {
<div class="col-10 form-control">
<vitamui-input
class="col-9 px-0"
[placeholder]="'PROFILE.POP_UP_CREATION_NOTICE.IDENTIFIER' | translate"
formControlName="identifier"
[errorMessageMap]="{
identifierExist: 'ERROR_IDENTIFIER.IDENTIFIER_ALREADY_EXISTS' | translate,
}"
>
</vitamui-input>
</div>
}
</div>

<div class="row">
<div class="col-10 form-control">
<vitamui-input class="col-9 px-0" formControlName="name" [placeholder]="'PROFILE.POP_UP_CREATION_NOTICE.NAME' | translate">
</vitamui-input>
</div>
</div>

<div class="row">
<div class="col-10 form-control">
<vitamui-input
[textarea]="true"
formControlName="description"
[placeholder]="'PROFILE.POP_UP_CREATION_NOTICE.DESCRIPTION' | translate"
class="w-100"
>
</vitamui-input>
</div>
</div>
@if (modePUA()) {
<div class="row">
<div class="col-10 form-control">
<div class="d-flex justify-content-between align-items-center py-1 px-2 mb-2">
<vitamui-slide-toggle formControlName="additionalProperties">
{{ 'PROFILE.POP_UP_CREATION_NOTICE.ALLOW_METADATA' | translate }}
</vitamui-slide-toggle>
</div>
</div>
</div>
}
<vitamui-select
class="d-block"
formControlName="status"
[placeholder]="'PROFILE.POP_UP_CREATION_NOTICE.SAVE_AS_ACTIVE_OR_INACTIVE' | translate"
[options]="statusOptions"
[enableSearch]="false"
></vitamui-select>
</mat-dialog-content>
</mat-dialog-content>
<mat-dialog-actions>
<div>
<button type="submit" (click)="validate()" [disabled]="!isFormValid()" class="btn primary">
{{ 'PROFILE.POP_UP_SAVE.SAVE_PROFILE.POPUP_CREATE_NOTICE_OK_LABEL' | translate }}
</button>
<button (click)="onClose()" class="btn cancel link" type="button">
{{ 'COMMON.UNDO' | translate }}
</button>
</div>
<vitamui-previous-step></vitamui-previous-step>
</mat-dialog-actions>
</cdk-step>
</vitamui-stepper>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/*
* Copyright French Prime minister Office/SGMAP/DINSIC/Vitam Program (2019-2022)
* and the signatories of the "VITAM - Accord du Contributeur" agreement.
*
* contact@programmevitam.fr
*
* This software is a computer program whose purpose is to implement
* implement a digital archiving front-office system for the secure and
* efficient high volumetry VITAM solution.
*
* This software is governed by the CeCILL-C license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-C
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*/
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';

import { CreateProfilNoticeComponent } from './create-profil-notice.component';
import { MatDialogRef } from '@angular/material/dialog';
import { ProfileService } from '../../core/services/profile.service';
import { ApplicationService, InputComponent, SelectComponent, SlideToggleComponent } from 'vitamui-library';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { BehaviorSubject, of } from 'rxjs';
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
import { ProfileType } from '../../models/profile-type.enum';
import { MatRadioModule } from '@angular/material/radio';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';

describe('CreateProfilNoticeComponent', () => {
let component: CreateProfilNoticeComponent;
let fixture: ComponentFixture<CreateProfilNoticeComponent>;
let mockDialogRef: jasmine.SpyObj<MatDialogRef<CreateProfilNoticeComponent>>;
let mockProfileService: jasmine.SpyObj<ProfileService>;
let mockAppService: jasmine.SpyObj<ApplicationService>;
let mockTranslate: jasmine.SpyObj<TranslateService>;
let externalIdSubject: BehaviorSubject<boolean>;

beforeEach(() => {
mockDialogRef = jasmine.createSpyObj('MatDialogRef', ['close']);
mockProfileService = jasmine.createSpyObj('ProfileService', ['checkPuaProfile', 'checkPaProfile', 'controlSchema']);
mockAppService = jasmine.createSpyObj('ApplicationService', ['isApplicationExternalIdentifierEnabled']);
mockProfileService.controlSchema = new BehaviorSubject<string>(JSON.stringify({ additionalProperties: true }));
mockTranslate = jasmine.createSpyObj('TranslateService', ['instant']);

mockTranslate.instant.and.callFake((key: string) => key);
externalIdSubject = new BehaviorSubject<boolean>(true);
mockAppService.isApplicationExternalIdentifierEnabled.and.returnValue(externalIdSubject.asObservable());

TestBed.configureTestingModule({
imports: [
ReactiveFormsModule,
TranslateModule.forRoot(),
MatRadioModule,
InputComponent,
SelectComponent,
SlideToggleComponent,
NoopAnimationsModule,
CreateProfilNoticeComponent,
],
providers: [
FormBuilder,
{ provide: MatDialogRef, useValue: mockDialogRef },
{ provide: ProfileService, useValue: mockProfileService },
{ provide: ApplicationService, useValue: mockAppService },
],
}).compileComponents();

fixture = TestBed.createComponent(CreateProfilNoticeComponent);
component = fixture.componentInstance;
});

it('should validate identifier via checkPaProfile when not PUA', fakeAsync(() => {
component.profileTypeSignal.set(ProfileType.PA);
fixture.detectChanges();
mockProfileService.checkPaProfile.and.returnValue(of(true));
component.noticeForm.controls.identifier?.setValue('DUPLICATE');

expect(mockProfileService.checkPaProfile).toHaveBeenCalledWith(jasmine.objectContaining({ identifier: 'DUPLICATE' }));
}));

it('should disable identifier validators if External ID is disabled', fakeAsync(() => {
fixture.detectChanges();
component.noticeForm.controls.profileType?.setValue(ProfileType.PUA);

externalIdSubject.next(false);

component.profileTypeSignal.set(ProfileType.PA);
component.profileTypeSignal.set(ProfileType.PUA);
fixture.detectChanges();

const identifierCtrl = component.noticeForm.controls.identifier;

expect(component.externalIdentifierEnabledSignal()).toBeFalse();

expect(identifierCtrl?.hasValidator(Validators.required)).toBeFalse();
expect(identifierCtrl?.hasValidator(Validators.minLength(2))).toBeFalse();
expect(identifierCtrl?.hasValidator(Validators.maxLength(100))).toBeFalse();

identifierCtrl?.setValue('');
expect(identifierCtrl?.valid).toBeTrue();
expect(identifierCtrl?.validator).toBeNull();
}));

it('should check PA and set isIdentifierOK to true if unique', fakeAsync(() => {
component.profileTypeSignal.set(ProfileType.PA);
fixture.detectChanges();
mockProfileService.checkPaProfile.and.returnValue(of(false));
component.noticeForm.controls.identifier?.setValue('UNIQUE_TEST');

expect(mockProfileService.checkPaProfile).toHaveBeenCalledWith(jasmine.objectContaining({ identifier: 'UNIQUE_TEST' }));
expect(component.noticeForm.controls.identifier.invalid).toBeFalse();
}));

it('should check PA and alert if duplicated', fakeAsync(() => {
component.profileTypeSignal.set(ProfileType.PA);
fixture.detectChanges();
mockAppService.isApplicationExternalIdentifierEnabled.and.returnValue(of(true));
mockProfileService.checkPaProfile.and.returnValue(of(true));

component.noticeForm.controls.identifier?.setValue('DUPLICATE_PA');

expect(mockProfileService.checkPaProfile).toHaveBeenCalledWith(jasmine.objectContaining({ identifier: 'DUPLICATE_PA' }));
expect(component.noticeForm.controls.identifier.invalid).toBeTrue();
}));

it('should check PUA and set isIdentifierOK to true if unique', fakeAsync(() => {
component.profileTypeSignal.set(ProfileType.PUA);
fixture.detectChanges();
mockProfileService.checkPuaProfile.and.returnValue(of(false));
component.noticeForm.controls.identifier?.setValue('UNIQUE_PUA');

expect(mockProfileService.checkPuaProfile).toHaveBeenCalledWith(jasmine.objectContaining({ identifier: 'UNIQUE_PUA' }));
expect(component.noticeForm.controls.identifier.invalid).toBeFalse();
}));

it('should check PUA and alert if duplicated', fakeAsync(() => {
component.profileTypeSignal.set(ProfileType.PUA);
fixture.detectChanges();
mockProfileService.checkPuaProfile.and.returnValue(of(true));
component.noticeForm.controls.identifier?.setValue('DUPLICATE_TEST');

expect(mockProfileService.checkPuaProfile).toHaveBeenCalledWith(jasmine.objectContaining({ identifier: 'DUPLICATE_TEST' }));
component.noticeForm.controls.profileType?.setValue(ProfileType.PUA);
expect(component.noticeForm.controls.identifier.invalid).toBeTrue();
}));

it('should create', () => {
expect(component).toBeTruthy();
});
});
Loading
Loading