122 lines
4.3 KiB
TypeScript
122 lines
4.3 KiB
TypeScript
import { TestBed } from '@angular/core/testing';
|
|
import { TenantCard } from './tenant-card';
|
|
|
|
describe('TenantCard', () => {
|
|
it('rejects files larger than the upload limit before emitting', () => {
|
|
const fixture = TestBed.createComponent(TenantCard);
|
|
fixture.componentRef.setInput('tenant', {
|
|
id: 'tenant-1',
|
|
firstName: 'Camille',
|
|
lastName: 'Martin',
|
|
email: 'camille@example.com',
|
|
phone: '',
|
|
address: '',
|
|
});
|
|
const file = new File(['identity'], 'archive.zip');
|
|
Object.defineProperty(file, 'size', { value: 250 * 1024 * 1024 + 1 });
|
|
const input = document.createElement('input');
|
|
Object.defineProperty(input, 'files', { value: { item: () => file } });
|
|
|
|
fixture.componentInstance.selectFile({ target: input } as unknown as Event);
|
|
|
|
expect(fixture.componentInstance.uploadError()).toContain('250 Mo');
|
|
});
|
|
|
|
it('shows measurable progress and disables only its upload control', () => {
|
|
const fixture = TestBed.createComponent(TenantCard);
|
|
fixture.componentRef.setInput('tenant', {
|
|
id: 'tenant-1',
|
|
firstName: 'Camille',
|
|
lastName: 'Martin',
|
|
email: 'camille@example.com',
|
|
phone: '',
|
|
address: '',
|
|
});
|
|
fixture.componentRef.setInput('uploading', true);
|
|
fixture.componentRef.setInput('uploadProgress', 50);
|
|
fixture.detectChanges();
|
|
|
|
expect(fixture.nativeElement.querySelector('input[type=file]').disabled).toBe(true);
|
|
expect(fixture.nativeElement.querySelector('mat-progress-bar')).not.toBeNull();
|
|
expect(fixture.nativeElement.textContent).toContain('Envoi : 50 %');
|
|
});
|
|
|
|
it('falls back to indeterminate upload feedback when no total is available', () => {
|
|
const fixture = TestBed.createComponent(TenantCard);
|
|
fixture.componentRef.setInput('tenant', {
|
|
id: 'tenant-1',
|
|
firstName: 'Camille',
|
|
lastName: 'Martin',
|
|
email: 'camille@example.com',
|
|
phone: '',
|
|
address: '',
|
|
});
|
|
fixture.componentRef.setInput('uploading', true);
|
|
fixture.detectChanges();
|
|
|
|
expect(fixture.nativeElement.textContent).toContain('Envoi…');
|
|
expect(fixture.nativeElement.querySelector('mat-progress-bar')).not.toBeNull();
|
|
});
|
|
|
|
it('shows progress only on the selected attachment download', () => {
|
|
const fixture = TestBed.createComponent(TenantCard);
|
|
fixture.componentRef.setInput('tenant', {
|
|
id: 'tenant-1',
|
|
firstName: 'Camille',
|
|
lastName: 'Martin',
|
|
email: 'camille@example.com',
|
|
phone: '',
|
|
address: '',
|
|
attachments: [
|
|
{ id: 'attachment-1', fileName: 'id.pdf', contentType: 'application/pdf', size: 42 },
|
|
],
|
|
});
|
|
fixture.componentRef.setInput('downloadingAttachmentIds', new Set(['attachment-1']));
|
|
fixture.detectChanges();
|
|
|
|
const download = fixture.nativeElement.querySelector('.attachment-row');
|
|
expect(download.disabled).toBe(true);
|
|
expect(download.textContent).toContain('Téléchargement…');
|
|
});
|
|
|
|
it('shows a separate remove action for attachments', () => {
|
|
const fixture = TestBed.createComponent(TenantCard);
|
|
fixture.componentRef.setInput('tenant', {
|
|
id: 'tenant-1',
|
|
firstName: 'Camille',
|
|
lastName: 'Martin',
|
|
email: 'camille@example.com',
|
|
phone: '',
|
|
address: '',
|
|
attachments: [
|
|
{ id: 'attachment-1', fileName: 'id.pdf', contentType: 'application/pdf', size: 42 },
|
|
],
|
|
});
|
|
fixture.componentRef.setInput('deletingAttachmentIds', new Set(['attachment-1']));
|
|
fixture.detectChanges();
|
|
|
|
const remove = fixture.nativeElement.querySelector('.attachment-delete');
|
|
expect(remove.disabled).toBe(true);
|
|
expect(remove.textContent).toContain('Suppression…');
|
|
expect(remove.getAttribute('aria-label')).toBe('Retirer la pièce jointe id.pdf');
|
|
});
|
|
|
|
it('uses a Font Awesome cross icon for the remove action', () => {
|
|
const fixture = TestBed.createComponent(TenantCard);
|
|
fixture.componentRef.setInput('tenant', {
|
|
id: 'tenant-1',
|
|
firstName: 'Camille',
|
|
lastName: 'Martin',
|
|
email: 'camille@example.com',
|
|
phone: '',
|
|
address: '',
|
|
attachments: [
|
|
{ id: 'attachment-1', fileName: 'id.pdf', contentType: 'application/pdf', size: 42 },
|
|
],
|
|
});
|
|
fixture.detectChanges();
|
|
|
|
expect(fixture.nativeElement.querySelector('.attachment-delete fa-icon')).not.toBeNull();
|
|
});
|
|
});
|