Skip to content
Draft
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 @@ -218,12 +218,10 @@ describe('ArchiveSearchComponent', () => {
expect(archiveServiceStub.hasArchiveSearchRole).toHaveBeenCalled();
});
it('should open a modal with TransferAcknowledgmentComponent', () => {
component.accessContractId = 'accessContract';
component.showAcknowledgmentTransferForm();
expect(matDialogSpy.open).toHaveBeenCalledWith(TransferAcknowledgmentComponent, {
disableClose: true,
data: {
accessContract: 'accessContract',
tenantIdentifier: '1',
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,6 @@ export class ArchiveSearchComponent implements OnInit, OnChanges, OnDestroy, Aft
const dialogRef = this.dialog.open(TransferAcknowledgmentComponent, {
disableClose: true,
data: {
accessContract: this.accessContractId,
tenantIdentifier: this.tenantIdentifier.toString(),
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[title]="'ARCHIVE_SEARCH.TRANSFER_ACKNOWLEDGMENT.TITLE_FIRST_STEP' | translate"
></vitamui-dialog-header>

<vitamui-stepper #stepper [selectedIndex]="stepIndex" (selectionChange)="stepIndex = $event.selectedIndex">
<vitamui-stepper #stepper>
<!-- Step 1 -->
<cdk-step>
<mat-dialog-content>
Expand All @@ -17,19 +17,21 @@ <h4>
</h4>
</div>

<div *ngIf="isLoadingData; then loadingMode; else dragAndDropArea"></div>
<vitamui-file-selector
[formControl]="atrControl"
[maxSizeInBytes]="FILE_MAX_SIZE"
[extensions]="[ATR_EXTENSION]"
[fileValidators]="atrContentValidator"
[errorMessageMap]="{
fileBadFormat: 'ARCHIVE_SEARCH.TRANSFER_ACKNOWLEDGMENT.FILE_BAD_FORMAT',
atrNotValid: 'ARCHIVE_SEARCH.TRANSFER_ACKNOWLEDGMENT.ATR_NOT_VALID',
}"
/>
</mat-dialog-content>

<mat-dialog-actions>
<button
(click)="validateAndParseXmlFile()"
[disabled]="isDisabled || hasError || hasFileSizeError || isAtrNotValid || isLoadingData"
class="btn primary"
type="button"
>
{{ 'COMMON.NEXT' | translate }}
</button>
<button (click)="onClose()" class="btn cancel link" type="button" [disabled]="isLoadingData">
<vitamui-next-step [disabled]="atrControl.invalid || atrControl.pending" />
<button (click)="onClose()" class="btn cancel link" type="button">
{{ 'COMMON.UNDO' | translate }}
</button>
</mat-dialog-actions>
Expand Down Expand Up @@ -81,9 +83,7 @@ <h4>

<mat-dialog-actions>
<div>
<button (click)="goToNextStep()" class="btn primary" type="button">
{{ 'COMMON.NEXT' | translate }}
</button>
<vitamui-next-step />
<button (click)="onCancel()" class="btn cancel link" type="button">
{{ 'ARCHIVE_SEARCH.TRANSFER_ACKNOWLEDGMENT.CANCEL_ACTION' | translate }}
</button>
Expand All @@ -95,7 +95,32 @@ <h4>
<!-- Step 3 -->
<cdk-step>
<mat-dialog-content>
<div *ngIf="isSubmitBtnDisabled; then loadingMode; else transferReplyStatusDetails"></div>
@if (isSubmitBtnDisabled) {
<div class="vitamui-min-content">
<mat-spinner class="vitamui-spinner large"></mat-spinner>
</div>
} @else {
<div>
<p class="detail-text">
{{ 'ARCHIVE_SEARCH.TRANSFER_ACKNOWLEDGMENT.ACKNOWLEDGMENT_TRANSFER_CONTROL' | translate }}
</p>
<p class="text-size">
{{ 'ARCHIVE_SEARCH.TRANSFER_ACKNOWLEDGMENT.ACKNOWLEDGMENT_TRANSFER_REPLY_CODE' | translate }}
{{ transfertDetails.archiveTransferReply }}
</p>
<p class="text-size">
@if (transfertDetailsCode === 'OK') {
{{ 'ARCHIVE_SEARCH.TRANSFER_ACKNOWLEDGMENT.CONFIRM_SUCCESS_TRANSFER' | translate }}
}
@if (transfertDetailsCode === 'WARNING') {
{{ 'ARCHIVE_SEARCH.TRANSFER_ACKNOWLEDGMENT.CONFIRM_SUCCESS_TRANSFER' | translate }}
}
@if (transfertDetailsCode === 'KO') {
{{ 'ARCHIVE_SEARCH.TRANSFER_ACKNOWLEDGMENT.CONFIRM_FAILURE_TRANSFER' | translate }}
}
</p>
</div>
}
</mat-dialog-content>

<mat-dialog-actions>
Expand Down Expand Up @@ -129,81 +154,3 @@ <h4>
</button>
</mat-dialog-actions>
</ng-template>

<ng-template #loadingMode>
<div class="vitamui-min-content">
<mat-spinner class="vitamui-spinner large"></mat-spinner>
</div>
</ng-template>

<ng-template #transferReplyStatusDetails>
<div>
<p class="detail-text">
{{ 'ARCHIVE_SEARCH.TRANSFER_ACKNOWLEDGMENT.ACKNOWLEDGMENT_TRANSFER_CONTROL' | translate }}
</p>
<p class="text-size">
{{ 'ARCHIVE_SEARCH.TRANSFER_ACKNOWLEDGMENT.ACKNOWLEDGMENT_TRANSFER_REPLY_CODE' | translate }}
{{ transfertDetails.archiveTransferReply }}
</p>
<p class="text-size" [ngSwitch]="transfertDetailsCode">
<ng-container *ngSwitchCase="'OK'"> {{ 'ARCHIVE_SEARCH.TRANSFER_ACKNOWLEDGMENT.CONFIRM_SUCCESS_TRANSFER' | translate }}</ng-container>
<ng-container *ngSwitchCase="'WARNING'">
{{ 'ARCHIVE_SEARCH.TRANSFER_ACKNOWLEDGMENT.CONFIRM_SUCCESS_TRANSFER' | translate }}
</ng-container>
<ng-container *ngSwitchCase="'KO'">
{{ 'ARCHIVE_SEARCH.TRANSFER_ACKNOWLEDGMENT.CONFIRM_FAILURE_TRANSFER' | translate }}
</ng-container>
</p>
</div>
</ng-template>

<ng-template #dragAndDropArea>
<div class="d-flex">
<div class="drag-and-drop-area" vitamuiCommonDragAndDrop (fileToUploadEmitter)="handleFile($event)">
<div *ngIf="fileName && fileSize > 0 && fileSizeString" class="drag-container">
<div class="file-info-class">
{{ fileName }}
<span class="text light"> | {{ fileSizeString }} </span>
<i class="material-icons success-icon" *ngIf="!hasError">check_circle</i>
<div>
<span class="text danger bold">{{ message }} </span>
<i class="material-icons error-icon" *ngIf="hasError">cancel </i>
</div>

<div *ngIf="hasFileSizeError">
<div>
<span class="text danger bold"> {{ 'ARCHIVE_SEARCH.TRANSFER_ACKNOWLEDGMENT.AUTHORIZED_SIZE' | translate }}</span>
<i class="material-icons error-icon">cancel </i>
</div>
</div>

<div *ngIf="isAtrNotValid">
<div>
<span class="text danger bold"> {{ 'ARCHIVE_SEARCH.TRANSFER_ACKNOWLEDGMENT.ATR_NOT_VALID' | translate }}</span>
<i class="material-icons error-icon">cancel </i>
</div>
</div>
</div>
</div>

<input type="file" #atrXmlFile class="input-file" (change)="handleFile($event.target.files)" />

<div class="drop-area">
<div class="atr-drop">{{ 'ARCHIVE_SEARCH.TRANSFER_ACKNOWLEDGMENT.DRAG_AND_DROP' | translate }}<br /></div>

<div class="atr-drop">
<div class="upload">
<span class="url-select" (click)="addTransferAtrFile()">
{{ 'ARCHIVE_SEARCH.TRANSFER_ACKNOWLEDGMENT.BROWSE' | translate }}</span
>
</div>
</div>
<div class="atr-drop-small">
<span> {{ 'ARCHIVE_SEARCH.TRANSFER_ACKNOWLEDGMENT.ACCEPTED_FORMAT' | translate }}</span
><br /><br />
<span> {{ 'ARCHIVE_SEARCH.TRANSFER_ACKNOWLEDGMENT.MAX_SIZE' | translate }}</span>
</div>
</div>
</div>
</div>
</ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import { ArchiveService } from '../../archive.service';
import { TransferAcknowledgmentComponent } from './transfer-acknowledgment.component';
import { DecimalPipe } from '@angular/common';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { CdkStep } from '@angular/cdk/stepper';

const translations: any = { TEST: 'Mock translate test' };

Expand Down Expand Up @@ -84,8 +86,11 @@ describe('TransferAcknowledgmentComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [TransferAcknowledgmentComponent, MockDateTimePipe],
declarations: [MockDateTimePipe],
imports: [
TransferAcknowledgmentComponent,
CdkStep,
NoopAnimationsModule,
InjectorModule,
LoggerModule.forRoot(),
TranslateModule.forRoot({
Expand Down Expand Up @@ -118,77 +123,23 @@ describe('TransferAcknowledgmentComponent', () => {
expect(component).toBeTruthy();
});

it('All the parameters must be initialized', () => {
// When
component.initializeParameters();

// Then
expect(component.transfertDetailsCode).toBeNull();
expect(component.isDisabled).toBeFalsy();
expect(component.hasFileSizeError).toBeFalsy();
expect(component.isAtrNotValid).toBeFalsy();
expect(component.transfertDetails).toEqual({});
expect(component.hasError).toBeFalsy();
expect(component.message).toBeNull();
});

it('Should return true when the file extension is xml ', () => {
// Given
const fileName = 'ATR_aeeaaaaaaghduohdabkogamdgezb2taaaaaq.xml';

// When
const response: boolean = component.checkFileExtension(fileName);

// Then
expect(response).toBeTruthy();
});

it('Should have an accessContract ', () => {
expect(component.data.accessContract).not.toBeNull();
});

it('Should return false when the file extension is not xml ', () => {
// Given
const fileName = 'SIP-recherche-perf.zip';
// When
const response: boolean = component.checkFileExtension(fileName);
// Then
expect(response).toBeFalsy();
});

it('Should have a tenant identifier ', () => {
expect(component.data.tenantIdentifier).not.toBeNull();
});

it('Should return true if the extension file is xml ', () => {
const contents = 'text for test';
const blob = new Blob([contents], { type: 'text/plain' });
const file = new File([blob], 'fileExample.xml', { type: 'text/plain' });
expect(component.checkFileExtension(file.name)).toBeTruthy();
});

it('should call transferAcknowledgment()', () => {
const archiveService = TestBed.inject(ArchiveService);
const matDialogRef = TestBed.inject(MatDialogRef);
component.applyTransferAcknowledgment();
expect(archiveService.transferAcknowledgment).toHaveBeenCalled();
expect(matDialogRef.close).toHaveBeenCalled();
});

it('should return KO as status()', () => {
// Given
component.transfertDetails = { archiveTransferReply: '\n\t\tKO\n\t' };

// When
component.goToNextStep();
const file = new File([''], '');
component.atrControl.setValue([file]);
component.data.tenantIdentifier = '42';

// Then
expect(component.transfertDetailsCode).not.toBeNull();
expect(component.transfertDetailsCode).toEqual('KO');
component.applyTransferAcknowledgment();
expect(archiveService.transferAcknowledgment).toHaveBeenCalledWith('42', file);
expect(matDialogRef.close).toHaveBeenCalled();
});

it('should parseXmlToTransferDetails for valid XML', async () => {
const xmlOK = `<?xml version="1.0" encoding="UTF-8"?>
const xmlOK = new File(
[
`<?xml version="1.0" encoding="UTF-8"?>
<ArchiveTransferReply xmlns="fr:gouv:culture:archivesdefrance:seda:v2.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="fr:gouv:culture:archivesdefrance:seda:v2.3 seda-2.3/seda-2.3-main.xsd">
Expand All @@ -202,10 +153,13 @@ describe('TransferAcknowledgmentComponent', () => {
<TransferringAgency>
<Identifier>Identifier5</Identifier>
</TransferringAgency>
</ArchiveTransferReply>`;
</ArchiveTransferReply>`,
],
'ok.xml',
);

await component.parseXmlToTransferDetails(xmlOK);
expect(component.isAtrNotValid).toBeFalse();
const errors = await component.atrContentValidator(xmlOK);
expect(errors).toBeFalsy();
expect(component.transfertDetails).toEqual({
messageRequestIdentifier: 'SIP SEDA de test',
date: '2024-06-04T12:56:58.824Z',
Expand All @@ -217,18 +171,21 @@ describe('TransferAcknowledgmentComponent', () => {
});

it('should parseXmlToTransferDetails for XML without ArchiveTransferReply', async () => {
const xmlNoArchiveTransferReply = '<toto></toto>';
const xmlNoArchiveTransferReply = new File(['<toto></toto>'], 'xmlNoArchiveTransferReply.xml');

await component.parseXmlToTransferDetails(xmlNoArchiveTransferReply);
expect(component.isAtrNotValid).toBeTrue();
const errors = await component.atrContentValidator(xmlNoArchiveTransferReply);
expect(errors).toBeTruthy();
expect(errors.fileErrors.atrNotValid).toBeTruthy();
expect(errors.controlErrors.invalidFiles).toBeTruthy();
});

it('should parseXmlToTransferDetails for invalid XML', async () => {
const xmlBadFormat = 'This is not XML';
const xmlBadFormat = new File(['This is not XML'], 'xmlBadFormat.xml');

await component.parseXmlToTransferDetails(xmlBadFormat);
expect(component.hasError).toBeTrue();
expect(component.message).toBeTruthy();
const errors = await component.atrContentValidator(xmlBadFormat);
expect(errors).toBeTruthy();
expect(errors.fileErrors.fileBadFormat).toBeTruthy();
expect(errors.controlErrors.invalidFiles).toBeTruthy();
});

describe('DOM', () => {
Expand All @@ -240,24 +197,6 @@ describe('TransferAcknowledgmentComponent', () => {
expect(formTitlesHtmlElements[0].textContent).toContain('ARCHIVE_SEARCH.TRANSFER_ACKNOWLEDGMENT.OPERATION_MESSAGE_IDENTIFIER ');
});

it('should emit handleFileInput function when a file is added ', () => {
// Given
const contents = '<a>test</a>';
const blob = new Blob([contents], { type: 'text/plain' });
const file = new File([blob], 'atrFile.xml', { type: 'text/plain' });
component.fileToUpload = file;
spyOn(component, 'handleFile');
const nativeElement = fixture.nativeElement;
const checkBox = nativeElement.querySelector('input[type=file]');

// When
checkBox.dispatchEvent(new Event('change'));
fixture.detectChanges();

// Then
expect(component.handleFile).toHaveBeenCalled();
});

it('should have an input file', () => {
const nativeElement = fixture.nativeElement;
const elInput = nativeElement.querySelector('input[type=file]');
Expand All @@ -270,11 +209,6 @@ describe('TransferAcknowledgmentComponent', () => {
expect(matDialogSpyTest.close).toHaveBeenCalled();
});

it('should have 3 cdk steps', () => {
const elementCdkStep = fixture.nativeElement.querySelectorAll('cdk-step');
expect(elementCdkStep.length).toBe(3);
});

it('should call close for all open dialogs', () => {
const matDialogSpyTest = TestBed.inject(MatDialogRef);
component.onConfirm();
Expand Down
Loading
Loading