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

Merge branch 'master' into OZG-5600-OZG-5715-darkmode

parents e988c04e 85221a75
Branches
Tags
No related merge requests found
Showing with 97 additions and 35 deletions
......@@ -21,6 +21,8 @@ export function createBescheid(): Bescheid {
bescheidDocument: faker.internet.url(),
attachments: [faker.internet.url(), faker.internet.url()],
sendBy: BescheidSendBy.NACHRICHT,
nachrichtSubject: faker.lorem.text(),
nachrichtText: faker.lorem.text(),
};
}
......
......@@ -185,6 +185,8 @@ describe('BescheidenFormService', () => {
[BescheidenFormService.FIELD_BEWILLIGT]: String(bescheidResource.bewilligt),
[BescheidenFormService.FIELD_BESCHEID_DOCUMENT]: null,
[BescheidenFormService.FIELD_SEND_BY]: String(bescheidResource.sendBy),
[BescheidenFormService.FIELD_NACHRICHT_SUBJECT]: bescheidResource.nachrichtSubject,
[BescheidenFormService.FIELD_NACHRICHT_TEXT]: bescheidResource.nachrichtText,
});
});
......@@ -205,7 +207,7 @@ describe('BescheidenFormService', () => {
[BescheidenFormService.FIELD_SEND_BY]: BescheidSendBy.NACHRICHT,
[BescheidenFormService.FIELD_BESCHEID_DOCUMENT]: bescheidDocumentUri,
[BescheidenFormService.FIELD_NACHRICHT_SUBJECT]: bescheidResource.nachrichtSubject,
[BescheidenFormService.FIELD_NACHRICHT_TEXT]: bescheidResource.nachrichtSubject,
[BescheidenFormService.FIELD_NACHRICHT_TEXT]: bescheidResource.nachrichtText,
});
});
......@@ -340,12 +342,6 @@ describe('BescheidenFormService', () => {
expect(service.getValue().nachrichtSubject).toEqual(documentResource.nachrichtSubject);
});
it('should patch nachrichtSubject with default value if document not exists', () => {
service.patchNachricht(null);
expect(service.getValue().nachrichtSubject).toEqual(BescheidenFormService.BETREFF_DEFAULT);
});
it.each([EMPTY_STRING, null, undefined])(
'should patch nachrichtSubject with default value if subject not defined',
(subject: string) => {
......@@ -360,20 +356,22 @@ describe('BescheidenFormService', () => {
},
);
it('should patch nachrichtText with value from document', () => {
it('should not patch nachrichtSubject if given', () => {
const documentResource: DocumentResource = createDocumentResource();
const bescheidResource: BescheidResource = createBescheidResource();
service.patchValues(bescheidResource);
service.patchNachricht(documentResource);
expect(service.getValue().nachrichtText).toEqual(documentResource.nachrichtText);
expect(service.getValue().nachrichtSubject).toEqual(bescheidResource.nachrichtSubject);
});
it('should build Nachricht Text if document not exists', () => {
service.buildNachrichtentext = jest.fn();
it('should patch nachrichtText with value from document', () => {
const documentResource: DocumentResource = createDocumentResource();
service.patchNachricht(null);
service.patchNachricht(documentResource);
expect(service.buildNachrichtentext).toHaveBeenCalled();
expect(service.getValue().nachrichtText).toEqual(documentResource.nachrichtText);
});
it.each([EMPTY_STRING, null, undefined])(
......@@ -391,15 +389,6 @@ describe('BescheidenFormService', () => {
},
);
it('should patch nachrichtText with default value if document not exists', () => {
const nachrichtText = faker.lorem.text();
service.buildNachrichtentext = jest.fn().mockReturnValue(nachrichtText);
service.patchNachricht(null);
expect(service.getValue().nachrichtText).toEqual(nachrichtText);
});
it.each([EMPTY_STRING, null, undefined])(
'should patch nachrichtText with default value if text not defined',
(text: string) => {
......@@ -415,6 +404,16 @@ describe('BescheidenFormService', () => {
expect(service.getValue().nachrichtText).toEqual(nachrichtText);
},
);
it('should not patch nachrichtText if given', () => {
const documentResource: DocumentResource = createDocumentResource();
const bescheidResource: BescheidResource = createBescheidResource();
service.patchValues(bescheidResource);
service.patchNachricht(documentResource);
expect(service.getValue().nachrichtText).toEqual(bescheidResource.nachrichtText);
});
});
describe('clearNachricht', () => {
......
......@@ -267,19 +267,24 @@ export class BescheidenFormService extends AbstractFormService implements OnDest
return this.sendByManual.asObservable();
}
public patchNachricht(documentResource?: DocumentResource): void {
if (documentResource && isNotEmpty(documentResource.nachrichtSubject)) {
public patchNachricht(documentResource: DocumentResource): void {
const value = this.getValue();
if (isEmpty(value.nachrichtSubject)) {
if (isNotEmpty(documentResource.nachrichtSubject)) {
this.setNachrichtSubject(documentResource.nachrichtSubject);
} else {
this.setNachrichtSubject(BescheidenFormService.BETREFF_DEFAULT);
}
}
if (documentResource && isNotEmpty(documentResource.nachrichtText)) {
if (isEmpty(value.nachrichtText)) {
if (isNotEmpty(documentResource.nachrichtText)) {
this.setNachrichtText(documentResource.nachrichtText);
} else {
this.setNachrichtText(this.buildNachrichtentext());
}
}
}
public clearNachricht(): void {
this.setNachrichtSubject(EMPTY_STRING);
......
......@@ -14,9 +14,14 @@ import {
ButtonCardComponent,
SpinnerIconComponent,
} from '@ods/system';
import { createBescheidResource } from 'libs/bescheid-shared/src/test/bescheid';
import {
createBescheidResource,
createUploadFileInProgress,
} from 'libs/bescheid-shared/src/test/bescheid';
import { getDataTestIdOf } from 'libs/tech-shared/test/data-test';
import { MockComponent } from 'ng-mocks';
import { of } from 'rxjs';
import { BescheidenFormService } from '../../../../bescheiden.formservice';
import { VorgangDetailBescheidenBescheidAutomatischErstellenComponent } from './vorgang-detail-bescheiden-bescheid-automatisch-erstellen.component';
describe('VorgangDetailBescheidenBescheidAutomatischErstellenComponent', () => {
......@@ -26,9 +31,11 @@ describe('VorgangDetailBescheidenBescheidAutomatischErstellenComponent', () => {
const createBescheidDocumentButton: string = getDataTestIdOf('create-bescheid-document-button');
let bescheidService: Mock<BescheidService>;
let formService: Mock<BescheidenFormService>;
beforeEach(async () => {
bescheidService = mock(BescheidService);
formService = mock(BescheidenFormService);
await TestBed.configureTestingModule({
imports: [HasLinkPipe],
......@@ -44,6 +51,10 @@ describe('VorgangDetailBescheidenBescheidAutomatischErstellenComponent', () => {
provide: BescheidService,
useValue: bescheidService,
},
{
provide: BescheidenFormService,
useValue: formService,
},
],
}).compileComponents();
......@@ -87,5 +98,38 @@ describe('VorgangDetailBescheidenBescheidAutomatischErstellenComponent', () => {
existsAsHtmlElement(fixture, createBescheidDocumentButton);
});
it('should clear nachricht', () => {
bescheidService.createBescheidDocument.mockReturnValue(
of({ ...createUploadFileInProgress(), loading: false, error: null }),
);
component.createBescheidDocument();
component.createBescheidDocumentInProgress$.subscribe();
expect(formService.clearNachricht).toHaveBeenCalled();
});
it('should not clear nachricht when loading', () => {
bescheidService.createBescheidDocument.mockReturnValue(
of({ ...createUploadFileInProgress(), error: null }),
);
component.createBescheidDocument();
component.createBescheidDocumentInProgress$.subscribe();
expect(formService.clearNachricht).not.toHaveBeenCalled();
});
it('should not clear nachricht when error', () => {
bescheidService.createBescheidDocument.mockReturnValue(
of({ ...createUploadFileInProgress(), loading: false }),
);
component.createBescheidDocument();
component.createBescheidDocumentInProgress$.subscribe();
expect(formService.clearNachricht).not.toHaveBeenCalled();
});
});
});
......@@ -2,11 +2,14 @@ import {
BescheidLinkRel,
BescheidResource,
BescheidService,
hasUploadNoError,
isUploadFinished,
UploadFileInProgress,
} from '@alfa-client/bescheid-shared';
import { StateResource } from '@alfa-client/tech-shared';
import { Component, Input } from '@angular/core';
import { Observable, of } from 'rxjs';
import { Observable, of, tap } from 'rxjs';
import { BescheidenFormService } from '../../../../bescheiden.formservice';
@Component({
selector: 'alfa-vorgang-detail-bescheiden-bescheid-automatisch-erstellen',
......@@ -21,9 +24,18 @@ export class VorgangDetailBescheidenBescheidAutomatischErstellenComponent {
public readonly bescheidLinkRel = BescheidLinkRel;
constructor(private readonly bescheidService: BescheidService) {}
constructor(
private readonly bescheidService: BescheidService,
private readonly formService: BescheidenFormService,
) {}
public createBescheidDocument(): void {
this.createBescheidDocumentInProgress$ = this.bescheidService.createBescheidDocument();
this.createBescheidDocumentInProgress$ = this.bescheidService.createBescheidDocument().pipe(
tap((uploadFileInProgress: UploadFileInProgress) => {
if (isUploadFinished(uploadFileInProgress) && hasUploadNoError(uploadFileInProgress)) {
this.formService.clearNachricht();
}
}),
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment