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

OZG-5708: improve code after code review

parent db384c88
No related branches found
No related tags found
No related merge requests found
Showing
with 132 additions and 40 deletions
......@@ -397,7 +397,7 @@ export class BescheidService {
public createBescheidDocument(): Observable<StateResource<CommandResource>> {
this.clearUploadBescheidDocumentInProgress();
this.setCreateBescheidDocumenInProgress();
this.setCreateBescheidDocumentInProgress();
this.doCreateBescheidDocument()
.pipe(filterIsLoadedOrHasError(), first())
.subscribe((commandStateResource: StateResource<CommandResource>) =>
......@@ -414,7 +414,7 @@ export class BescheidService {
return this.createBescheidDocumentInProgress$.asObservable();
}
private setCreateBescheidDocumenInProgress(): void {
private setCreateBescheidDocumentInProgress(): void {
this.createBescheidDocumentInProgress$.next(createEmptyStateResource(true));
}
......
......@@ -27,7 +27,7 @@ import { toResource } from 'libs/tech-shared/test/resource';
import { times } from 'lodash-es';
import { CommandListLinkRel } from '../src/lib/command.linkrel';
import { CommandErrorMessage } from '../src/lib/command.message';
import { Command, CommandListResource, CommandOrder, CommandResource, CommandStatus, CreateCommand, CreateCommandProps } from '../src/lib/command.model';
import { Command, CommandListResource, CommandOrder, CommandResource, CommandStatus, CreateCommand, CreateCommandProps, } from '../src/lib/command.model';
export function createCommand(): Command {
return {
......@@ -71,7 +71,7 @@ export function createCommandErrorResource(linkRelations: string[] = []): Comman
export function createCommandErrorStateResource(
linkRelations: string[] = [],
): StateResource<CommandResource> {
return createStateResource(createCommandResource(linkRelations));
return createStateResource(createCommandErrorResource(linkRelations));
}
export function createCreateCommand(
......
import { CommonModule } from '@angular/common';
import { Component, Input } from '@angular/core';
import { isNotEmpty } from '@alfa-client/tech-shared';
import { FileIconComponent } from '../icons/file-icon/file-icon.component';
import { SpinnerIconComponent } from '../icons/spinner-icon/spinner-icon.component';
......@@ -50,7 +51,7 @@ export class AttachmentComponent {
@Input() isLoading: boolean = false;
@Input() set errorMessages(errorMessages: string[]) {
this.hasError = errorMessages?.length > 0;
this.hasError = isNotEmpty(errorMessages);
this.errors = errorMessages;
}
......
......@@ -31,6 +31,7 @@ export * from './lib/form.util';
export * from './lib/http.util';
export * from './lib/message-code';
export * from './lib/ngrx/actions';
export * from './lib/pipe/convert-api-error-to-error-messages.pipe';
export * from './lib/pipe/convert-for-data-test.pipe';
export * from './lib/pipe/convert-to-boolean.pipe';
export * from './lib/pipe/enum-to-label.pipe';
......
......@@ -2,6 +2,7 @@ import { BescheidService } from '@alfa-client/bescheid-shared';
import { BinaryFile2ContainerComponent } from '@alfa-client/binary-file';
import { BinaryFileResource } from '@alfa-client/binary-file-shared';
import {
ConvertApiErrorToErrorMessagesPipe,
convertForDataTest,
ConvertForDataTestPipe,
createErrorStateResource,
......@@ -26,7 +27,6 @@ import {
createLoadedBinaryFileResource,
createLoadingBinaryFileStateResource,
} from '../../../../../../../binary-file-shared/test/binary-file';
import { ConvertApiErrorToErrorMessagesPipe } from '../../../../../../../tech-shared/src/lib/pipe/convert-api-error-to-error-messages.pipe';
import { getDataTestIdOf } from '../../../../../../../tech-shared/test/data-test';
import { createApiError } from '../../../../../../../tech-shared/test/error';
import { BescheidenFormService } from '../../bescheiden.formservice';
......
......@@ -11,7 +11,7 @@
*ngIf="
!bescheidDocumentFile.loading &&
!uploadBescheidDocumentInProgress.loading &&
!createBescheidDocumentInProgress.loading
!createDocumentInProgess.loading
"
[file]="bescheidDocumentFile.resource"
[deletable]="deletable"
......@@ -31,21 +31,12 @@
description="Bescheiddokument wird hochgeladen"
></ods-attachment>
<ods-attachment
*ngIf="
createBescheidDocumentInProgress.loading ||
createBescheidDocumentInProgress.resource?.errorMessage
"
*ngIf="createDocumentInProgess.loading || hasCreateDocumentError"
errorCaption="Fehler beim automatischen Erstellen"
loadingCaption="Bescheiddokument"
description="Bescheiddokument wird erstellt"
[isLoading]="createBescheidDocumentInProgress.loading"
[errorMessages]="
createBescheidDocumentInProgress.resource?.errorMessage ?
['Bescheiddokument konnte nicht erzeugt werden.']
: []
"
[attr.data-test-id]="
'create-bescheid-document-error-' + !!createBescheidDocumentInProgress.resource?.errorMessage
"
[isLoading]="createDocumentInProgess.loading"
[errorMessages]="createDocumentErrorMessages"
data-test-id="create-bescheid-document-attachment"
></ods-attachment>
</ods-attachment-container>
import { BescheidLinkRel, BescheidResource, BescheidService } from '@alfa-client/bescheid-shared';
import { BinaryFile2ContainerComponent } from '@alfa-client/binary-file';
import { createStateResource } from '@alfa-client/tech-shared';
import { CommandResource } from '@alfa-client/command-shared';
import {
ConvertApiErrorToErrorMessagesPipe,
createEmptyStateResource,
createStateResource,
StateResource,
} from '@alfa-client/tech-shared';
import { existsAsHtmlElement, Mock, mock, notExistsAsHtmlElement } from '@alfa-client/test-utils';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { getUrl } from '@ngxp/rest';
......@@ -11,18 +17,18 @@ import { getDataTestIdOf } from 'libs/tech-shared/test/data-test';
import { createApiError } from 'libs/tech-shared/test/error';
import { MockComponent, MockPipe } from 'ng-mocks';
import {
createCommandErrorResource,
createCommandErrorStateResource,
createCommandResource,
createCommandStateResource,
} from '../../../../../../../command-shared/test/command';
import { ConvertApiErrorToErrorMessagesPipe } from '../../../../../../../tech-shared/src/lib/pipe/convert-api-error-to-error-messages.pipe';
import { VorgangDetailBescheidenResultDokumentComponent } from './vorgang-detail-bescheiden-result-dokument.component';
describe('VorgangDetailBescheidenResultDokumentComponent', () => {
let component: VorgangDetailBescheidenResultDokumentComponent;
let fixture: ComponentFixture<VorgangDetailBescheidenResultDokumentComponent>;
const createBescheidDocumentError: string = getDataTestIdOf(
'create-bescheid-document-error-true',
const createBescheidDocumentAttachment: string = getDataTestIdOf(
'create-bescheid-document-attachment',
);
const uploadBescheidDocumentError: string = getDataTestIdOf(
'upload-bescheid-document-error-true',
......@@ -78,6 +84,35 @@ describe('VorgangDetailBescheidenResultDokumentComponent', () => {
notExistsAsHtmlElement(fixture, missingBescheidDocumentErrorMessage);
});
describe('create bescheid document ods-attachment', () => {
it('should be shown if error exists', () => {
component.createBescheidDocumentInProgress = createCommandErrorStateResource();
fixture.detectChanges();
existsAsHtmlElement(fixture, createBescheidDocumentAttachment);
});
it('should be shown while loading', () => {
component.createBescheidDocumentInProgress = createStateResource(
createCommandResource(),
true,
);
fixture.detectChanges();
existsAsHtmlElement(fixture, createBescheidDocumentAttachment);
});
it('should be hidden on loaded without error', () => {
component.createBescheidDocumentInProgress = createCommandStateResource();
fixture.detectChanges();
notExistsAsHtmlElement(fixture, createBescheidDocumentAttachment);
});
});
});
describe('handle bescheid document', () => {
......@@ -118,23 +153,61 @@ describe('VorgangDetailBescheidenResultDokumentComponent', () => {
});
});
describe('create bescheid document error', () => {
it('should be shown if error exists', () => {
component.createBescheidDocumentInProgress = createStateResource(
createCommandErrorResource(),
describe('set create bescheid document in progress', () => {
beforeEach(() => {
component.handleCreateBescheidDocumentCommandError = jest.fn();
});
it('should set create document in progress', () => {
const commandStateResource: StateResource<CommandResource> = createEmptyStateResource();
component.createBescheidDocumentInProgress = commandStateResource;
expect(component.createDocumentInProgess).toBe(commandStateResource);
});
it('should handle command error', () => {
const commandStateResource: StateResource<CommandResource> = createEmptyStateResource();
component.createBescheidDocumentInProgress = commandStateResource;
expect(component.handleCreateBescheidDocumentCommandError).toHaveBeenCalledWith(
commandStateResource,
);
});
});
fixture.detectChanges();
describe('handleCreateBescheidDocumentCommandError', () => {
it('should set has error', () => {
component.handleCreateBescheidDocumentCommandError(createCommandErrorStateResource());
existsAsHtmlElement(fixture, createBescheidDocumentError);
expect(component.hasCreateDocumentError).toBeTruthy();
});
it('should be hidden on non error', () => {
component.createBescheidDocumentInProgress = createCommandStateResource();
it('should not set has error', () => {
component.handleCreateBescheidDocumentCommandError(createCommandStateResource());
fixture.detectChanges();
expect(component.hasCreateDocumentError).toBeFalsy();
});
it('should not set has error on empty state resource', () => {
component.handleCreateBescheidDocumentCommandError(createEmptyStateResource());
expect(component.hasCreateDocumentError).toBeFalsy();
});
it('should set error messages', () => {
component.handleCreateBescheidDocumentCommandError(createCommandErrorStateResource());
expect(component.createDocumentErrorMessages).toEqual([
VorgangDetailBescheidenResultDokumentComponent.CREATE_DOCUMENT_ERROR_MESSAGE,
]);
});
it('should not set error messages', () => {
component.handleCreateBescheidDocumentCommandError(createCommandStateResource());
notExistsAsHtmlElement(fixture, createBescheidDocumentError);
expect(component.createDocumentErrorMessages).toEqual([]);
});
});
});
......@@ -5,8 +5,8 @@ import {
UploadFileInProgress,
} from '@alfa-client/bescheid-shared';
import { BinaryFileResource } from '@alfa-client/binary-file-shared';
import { CommandResource } from '@alfa-client/command-shared';
import { createEmptyStateResource, StateResource } from '@alfa-client/tech-shared';
import { CommandResource, hasCommandError } from '@alfa-client/command-shared';
import { createEmptyStateResource, isNotNil, StateResource } from '@alfa-client/tech-shared';
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { getUrl, hasLink } from '@ngxp/rest';
......@@ -15,20 +15,32 @@ import { getUrl, hasLink } from '@ngxp/rest';
templateUrl: './vorgang-detail-bescheiden-result-dokument.component.html',
})
export class VorgangDetailBescheidenResultDokumentComponent {
static readonly CREATE_DOCUMENT_ERROR_MESSAGE: string =
'Bescheiddokument konnte nicht erzeugt werden.';
@Input() bescheidDocumentFile: StateResource<BinaryFileResource>;
@Input() uploadBescheidDocumentInProgress: UploadFileInProgress = { loading: false };
@Input() createBescheidDocumentInProgress: StateResource<CommandResource> =
createEmptyStateResource();
@Input() set createBescheidDocumentInProgress(
commandStateResource: StateResource<CommandResource>,
) {
this.createDocumentInProgess = commandStateResource;
this.handleCreateBescheidDocumentCommandError(commandStateResource);
}
@Input() set bescheidDraftStateResource(bescheidStateResource: StateResource<BescheidResource>) {
this.handleBescheidDocument(bescheidStateResource.resource);
}
@Input() public deletable: boolean;
@Input() public showMissingBescheidDocumentError: boolean;
@Input() public showMissingBescheidDocumentError: boolean;
@Output() deleteFile: EventEmitter<void> = new EventEmitter<void>();
createDocumentErrorMessages: string[] = [];
createDocumentInProgess: StateResource<CommandResource> = createEmptyStateResource();
hasCreateDocumentError: boolean = false;
constructor(private bescheidService: BescheidService) {}
handleBescheidDocument(bescheid: BescheidResource): void {
......@@ -38,4 +50,18 @@ export class VorgangDetailBescheidenResultDokumentComponent {
);
}
}
handleCreateBescheidDocumentCommandError(
commandStateResource: StateResource<CommandResource>,
): void {
this.hasCreateDocumentError =
isNotNil(commandStateResource.resource) && hasCommandError(commandStateResource.resource);
if (this.hasCreateDocumentError) {
this.createDocumentErrorMessages = [
VorgangDetailBescheidenResultDokumentComponent.CREATE_DOCUMENT_ERROR_MESSAGE,
];
} else {
this.createDocumentErrorMessages = [];
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment