Skip to content
Snippets Groups Projects
Commit cafea3dc authored by OZGCloud's avatar OZGCloud
Browse files

OZG-5981 add component for download archive file; tiny code improvements

parent 295e3e48
No related branches found
No related tags found
No related merge requests found
Showing
with 210 additions and 9 deletions
......@@ -39,6 +39,7 @@ import { BinaryFileListComponent } from './binary-file-list-container/binary-fil
import { BinaryFileUriContainerComponent } from './binary-file-uri-container/binary-file-uri-container.component';
import { BinaryFile2ContainerComponent } from './binary-file2-container/binary-file2-container.component';
import { BinaryFile2Component } from './binary-file2-container/binary-file2/binary-file2.component';
import { DownloadArchiveFileButtonContainerComponent } from './download-archive-file-button-container/download-archive-file-button-container.component';
import { HorizontalBinaryFileListComponent } from './horizontal-binary-file-list/horizontal-binary-file-list.component';
import { VerticalBinaryFileListComponent } from './vertical-binary-file-list/vertical-binary-file-list.component';
......@@ -63,6 +64,7 @@ import { VerticalBinaryFileListComponent } from './vertical-binary-file-list/ver
BinaryFileUriContainerComponent,
BinaryFileListContainerComponent,
BinaryFileListComponent,
DownloadArchiveFileButtonContainerComponent,
],
exports: [
BinaryFileAttachmentContainerComponent,
......
<button
*ngIf="downloadArchiveInProgress$ | async"
data-test-class="download-archive"
(click)="downloadArchive()"
>
Download
</button>
import { BinaryFileService } from '@alfa-client/binary-file-shared';
import { Mock, dispatchEventFromFixture, mock } from '@alfa-client/test-utils';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import faker from '@faker-js/faker';
import { getDataTestClassOf } from 'libs/tech-shared/test/data-test';
import { DownloadArchiveFileButtonContainerComponent } from './download-archive-file-button-container.component';
describe('DownloadArchiveFileButtonContainerComponent', () => {
let component: DownloadArchiveFileButtonContainerComponent;
let fixture: ComponentFixture<DownloadArchiveFileButtonContainerComponent>;
const downloadArchiveButton: string = getDataTestClassOf('download-archive');
const binaryFileService: Mock<BinaryFileService> = mock(BinaryFileService);
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [DownloadArchiveFileButtonContainerComponent],
providers: [
{
provide: BinaryFileService,
useValue: binaryFileService,
},
],
}).compileComponents();
fixture = TestBed.createComponent(DownloadArchiveFileButtonContainerComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
describe('download attachments', () => {
const downloadUri: string = faker.internet.url();
it('should call service to download archive', () => {
component.downloadUri = downloadUri;
dispatchEventFromFixture(fixture, downloadArchiveButton, 'click');
expect(binaryFileService.downloadArchive).toHaveBeenCalledWith(downloadUri);
});
});
});
import { BinaryFileService } from '@alfa-client/binary-file-shared';
import { StateResource, createEmptyStateResource } from '@alfa-client/tech-shared';
import { Component, Input } from '@angular/core';
import { Observable, of } from 'rxjs';
@Component({
selector: 'alfa-download-archive-file-button-container',
templateUrl: './download-archive-file-button-container.component.html',
})
export class DownloadArchiveFileButtonContainerComponent {
@Input() downloadUri: string;
public downloadArchiveInProgress$: Observable<StateResource<unknown>> = of(
createEmptyStateResource(),
);
constructor(private binaryFileService: BinaryFileService) {}
public downloadArchive(): void {
this.downloadArchiveInProgress$ = this.binaryFileService.downloadArchive(this.downloadUri);
}
}
......@@ -25,6 +25,11 @@
-->
<ozgcloud-spinner [stateResource]="binaryFileListStateResource">
<ods-attachment-container [title]="title" data-test-id="file-list">
<alfa-download-archive-file-button-container
*ngIf="archiveDownloadUri"
data-test-class="download-archive-file-button"
[downloadUri]="archiveDownloadUri"
></alfa-download-archive-file-button-container>
<ng-container
*ngFor="
let binaryFileResource of binaryFileListStateResource.resource
......
......@@ -23,22 +23,32 @@
*/
import { BinaryFileResource } from '@alfa-client/binary-file-shared';
import { ToEmbeddedResourcesPipe, createStateResource } from '@alfa-client/tech-shared';
import { getMockComponent } from '@alfa-client/test-utils';
import {
existsAsHtmlElement,
getMockComponent,
notExistsAsHtmlElement,
} from '@alfa-client/test-utils';
import { SpinnerComponent } from '@alfa-client/ui';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import faker from '@faker-js/faker';
import { ResourceUri } from '@ngxp/rest';
import { AttachmentContainerComponent } from '@ods/system';
import {
createBinaryFileListResource,
createBinaryFileResource,
} from 'libs/binary-file-shared/test/binary-file';
import { getDataTestClassOf } from 'libs/tech-shared/test/data-test';
import { MockComponent } from 'ng-mocks';
import { BinaryFile2ContainerComponent } from '../binary-file2-container/binary-file2-container.component';
import { DownloadArchiveFileButtonContainerComponent } from '../download-archive-file-button-container/download-archive-file-button-container.component';
import { VerticalBinaryFileListComponent } from './vertical-binary-file-list.component';
describe('VerticalBinaryFileListComponent', () => {
let component: VerticalBinaryFileListComponent;
let fixture: ComponentFixture<VerticalBinaryFileListComponent>;
const downloadArchiveFileButton: string = getDataTestClassOf('download-archive-file-button');
const binaryFile: BinaryFileResource = createBinaryFileResource();
beforeEach(async () => {
......@@ -49,6 +59,7 @@ describe('VerticalBinaryFileListComponent', () => {
MockComponent(AttachmentContainerComponent),
MockComponent(BinaryFile2ContainerComponent),
MockComponent(SpinnerComponent),
MockComponent(DownloadArchiveFileButtonContainerComponent),
],
}).compileComponents();
});
......@@ -96,4 +107,40 @@ describe('VerticalBinaryFileListComponent', () => {
});
});
});
describe('download archive button', () => {
const downloadUri: ResourceUri = faker.internet.url();
it('should be visible if uri exists', () => {
component.archiveDownloadUri = downloadUri;
fixture.detectChanges();
existsAsHtmlElement(fixture, downloadArchiveFileButton);
});
it('should be hidden if uri is undefined', () => {
component.archiveDownloadUri = undefined;
fixture.detectChanges();
notExistsAsHtmlElement(fixture, downloadArchiveFileButton);
});
describe('component should be called with', () => {
beforeEach(() => {
component.archiveDownloadUri = downloadUri;
fixture.detectChanges();
});
it('downloadUri', () => {
const comp: DownloadArchiveFileButtonContainerComponent = getMockComponent(
fixture,
DownloadArchiveFileButtonContainerComponent,
);
expect(comp.downloadUri).toBe(downloadUri);
});
});
});
});
......@@ -24,6 +24,7 @@
import { BinaryFileListLinkRel, BinaryFileListResource } from '@alfa-client/binary-file-shared';
import { StateResource, createEmptyStateResource } from '@alfa-client/tech-shared';
import { Component, Input } from '@angular/core';
import { ResourceUri } from '@ngxp/rest';
@Component({
selector: 'alfa-vertical-binary-file-list',
......@@ -35,6 +36,7 @@ export class VerticalBinaryFileListComponent {
@Input() downloadFileNamePrefix: string;
@Input() title: string = '';
@Input() deletable: boolean = false;
@Input() archiveDownloadUri: ResourceUri;
readonly fileListRel = BinaryFileListLinkRel;
}
......@@ -18,6 +18,7 @@
data-test-id="attachment-list"
[binaryFileListStateResource]="attachmentListStateResource"
[downloadFileNamePrefix]="downloadPrefix"
[archiveDownloadUri]="attachmentsDownloadUri"
>
</alfa-vertical-binary-file-list>
</ng-container>
......
......@@ -8,6 +8,8 @@ import {
VorgangWithEingangResource,
} from '@alfa-client/vorgang-shared';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import faker from '@faker-js/faker';
import { getUrl } from '@ngxp/rest';
import { createBinaryFileListResource } from 'libs/binary-file-shared/test/binary-file';
import { getDataTestIdOf } from 'libs/tech-shared/test/data-test';
import { createVorgangWithEingangResource } from 'libs/vorgang-shared/test/vorgang';
......@@ -21,6 +23,7 @@ describe('VorgangDetailDateienContainerComponent', () => {
const attachmentList: string = getDataTestIdOf('attachment-list');
const representationList: string = getDataTestIdOf('representation-list');
const vorgang: VorgangWithEingangResource = createVorgangWithEingangResource();
const vorgangService: Mock<VorgangService> = mock(VorgangService);
......@@ -56,15 +59,21 @@ describe('VorgangDetailDateienContainerComponent', () => {
expect(component.handleVorgangChange).toHaveBeenCalled();
});
describe('handle vorgang chagne', () => {
describe('handle vorgang change', () => {
it('should set downloadPrefix', () => {
const vorgang: VorgangWithEingangResource = createVorgangWithEingangResource();
component.vorgangWithEingang = vorgang;
component.handleVorgangChange(vorgang);
expect(component.downloadPrefix).toEqual(vorgang.nummer);
});
it('should call handle attachements', () => {
component.handleAttachments = jest.fn();
component.handleVorgangChange(vorgang);
expect(component.handleAttachments).toHaveBeenCalledWith(vorgang);
});
describe('on vorgang with "representation" link', () => {
it('should call vorgangService methods', () => {
component.handleVorgangChange(
......@@ -74,6 +83,16 @@ describe('VorgangDetailDateienContainerComponent', () => {
expect(vorgangService.getRepresentations).toHaveBeenCalled();
});
});
});
describe('handle attachments', () => {
it('should call set download uri', () => {
component.setAttachmentsDownloadUri = jest.fn();
component.handleAttachments(vorgang);
expect(component.setAttachmentsDownloadUri).toHaveBeenCalledWith(vorgang);
});
describe('on vorgang with "attachments" link', () => {
it('should call vorgangService methods', () => {
......@@ -86,6 +105,28 @@ describe('VorgangDetailDateienContainerComponent', () => {
});
});
describe('download attachments link', () => {
it('should be set if exists', () => {
const vorganWithLink: VorgangWithEingangResource = createVorgangWithEingangResource([
VorgangWithEingangLinkRel.DOWNLOAD_ATTACHMENTS,
]);
component.handleVorgangChange(vorganWithLink);
expect(component.attachmentsDownloadUri).toBe(
getUrl(vorganWithLink, VorgangWithEingangLinkRel.DOWNLOAD_ATTACHMENTS),
);
});
it('should NOT be set if missing', () => {
const vorganWithLink: VorgangWithEingangResource = createVorgangWithEingangResource();
component.handleVorgangChange(vorganWithLink);
expect(component.attachmentsDownloadUri).toBeUndefined();
});
});
describe('on existing attachments', () => {
describe('binary file list component should be called with', () => {
const binaryFileListResource: BinaryFileListResource = createBinaryFileListResource();
......@@ -108,6 +149,16 @@ describe('VorgangDetailDateienContainerComponent', () => {
getVerticalBinaryFileListComponent(attachmentList);
expect(binaryFileListComp.downloadFileNamePrefix).toEqual(component.downloadPrefix);
});
it('archiveDownloadUri', () => {
component.attachmentsDownloadUri = faker.internet.url();
fixture.detectChanges();
const binaryFileListComp: VerticalBinaryFileListComponent =
getVerticalBinaryFileListComponent(attachmentList);
expect(binaryFileListComp.archiveDownloadUri).toEqual(component.attachmentsDownloadUri);
});
});
});
......
......@@ -6,7 +6,7 @@ import {
VorgangWithEingangResource,
} from '@alfa-client/vorgang-shared';
import { Component, Input } from '@angular/core';
import { hasLink } from '@ngxp/rest';
import { getUrl, hasLink } from '@ngxp/rest';
import { Observable, of } from 'rxjs';
@Component({
......@@ -26,16 +26,33 @@ export class VorgangDetailDateienContainerComponent {
);
public downloadPrefix: string;
public attachmentsDownloadUri: string;
public readonly vorgangWithEingangLinkRel = VorgangWithEingangLinkRel;
constructor(private vorgangService: VorgangService) {}
handleVorgangChange(vorgangWithEingang: VorgangWithEingangResource): void {
this.downloadPrefix = vorgangWithEingang.nummer;
this.getAttachmentsIfExists(vorgangWithEingang);
this.handleAttachments(vorgangWithEingang);
this.getRepresentationsIfExists(vorgangWithEingang);
}
handleAttachments(vorgangWithEingang: VorgangWithEingangResource): void {
this.setAttachmentsDownloadUri(vorgangWithEingang);
this.getAttachmentsIfExists(vorgangWithEingang);
}
setAttachmentsDownloadUri(vorgangWithEingang: VorgangWithEingangResource): void {
if (hasLink(vorgangWithEingang, VorgangWithEingangLinkRel.DOWNLOAD_ATTACHMENTS)) {
this.attachmentsDownloadUri = getUrl(
vorgangWithEingang,
VorgangWithEingangLinkRel.DOWNLOAD_ATTACHMENTS,
);
}
}
private getAttachmentsIfExists(vorgangWithEingang: VorgangWithEingangResource): void {
if (hasLink(vorgangWithEingang, VorgangWithEingangLinkRel.ATTACHMENTS)) {
this.attachmentListStateResource$ = this.vorgangService.getAttachments();
......
......@@ -64,6 +64,7 @@ export enum VorgangWithEingangLinkRel {
BESCHEID_DRAFT = 'bescheidDraft',
BESCHEIDE = 'bescheide',
UEBERSPRINGEN_UND_ABSCHLIESSEN = 'ueberspringen_und_abschliessen',
DOWNLOAD_ATTACHMENTS = 'downloadAttachments',
}
export enum LoeschAnforderungLinkRel {
......
......@@ -110,8 +110,8 @@ class VorgangWithEingangProcessor implements RepresentationModelProcessor<Entity
.addLink(linkTo(methodOn(ForwardingController.class).findByVorgangId(vorgang.getId())).withRel(REL_VORGANG_FORWARDING))
.addLink(linkTo(methodOn(HistorieController.class).getAll(vorgang.getId())).withRel(REL_HISTORIE))
.ifMatch(() -> userManagerUrlProvider.isConfiguredForSearchUserProfile() && hasOrganisationsEinheitId(vorgang))
.addLink(() -> buildSearchUserProfilesLink(vorgang))
.ifMatch(() -> isCreateBescheidEnabled(vorgang))
.addLink(this::buildSearchUserProfilesLink)
.ifMatch(this::isCreateBescheidEnabled)
.addLink(linkTo(methodOn(CommandByRelationController.class).createCommand(vorgang.getId(), vorgang.getId(), vorgang.getVersion(),
null)).withRel(REL_BESCHEID))
.ifMatch(this::isProcessable)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment