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

OZG-5717: override nachricht subject and text only if new document automatically created

parent bf71de33
No related branches found
No related tags found
No related merge requests found
Showing with 95 additions and 12 deletions
...@@ -21,6 +21,8 @@ export function createBescheid(): Bescheid { ...@@ -21,6 +21,8 @@ export function createBescheid(): Bescheid {
bescheidDocument: faker.internet.url(), bescheidDocument: faker.internet.url(),
attachments: [faker.internet.url(), faker.internet.url()], attachments: [faker.internet.url(), faker.internet.url()],
sendBy: BescheidSendBy.NACHRICHT, sendBy: BescheidSendBy.NACHRICHT,
nachrichtSubject: faker.lorem.text(),
nachrichtText: faker.lorem.text(),
}; };
} }
......
...@@ -360,6 +360,16 @@ describe('BescheidenFormService', () => { ...@@ -360,6 +360,16 @@ describe('BescheidenFormService', () => {
}, },
); );
it('should not patch nachrichtSubject if given', () => {
const documentResource: DocumentResource = createDocumentResource();
const bescheidResource: BescheidResource = createBescheidResource();
service.patchValues(bescheidResource);
service.patchNachricht(documentResource);
expect(service.getValue().nachrichtSubject).toEqual(bescheidResource.nachrichtSubject);
});
it('should patch nachrichtText with value from document', () => { it('should patch nachrichtText with value from document', () => {
const documentResource: DocumentResource = createDocumentResource(); const documentResource: DocumentResource = createDocumentResource();
...@@ -415,6 +425,16 @@ describe('BescheidenFormService', () => { ...@@ -415,6 +425,16 @@ describe('BescheidenFormService', () => {
expect(service.getValue().nachrichtText).toEqual(nachrichtText); 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', () => { describe('clearNachricht', () => {
......
...@@ -268,18 +268,23 @@ export class BescheidenFormService extends AbstractFormService implements OnDest ...@@ -268,18 +268,23 @@ export class BescheidenFormService extends AbstractFormService implements OnDest
} }
public patchNachricht(documentResource?: DocumentResource): void { public patchNachricht(documentResource?: DocumentResource): void {
const value = this.getValue();
if (isEmpty(value.nachrichtSubject)) {
if (documentResource && isNotEmpty(documentResource.nachrichtSubject)) { if (documentResource && isNotEmpty(documentResource.nachrichtSubject)) {
this.setNachrichtSubject(documentResource.nachrichtSubject); this.setNachrichtSubject(documentResource.nachrichtSubject);
} else { } else {
this.setNachrichtSubject(BescheidenFormService.BETREFF_DEFAULT); this.setNachrichtSubject(BescheidenFormService.BETREFF_DEFAULT);
} }
}
if (isEmpty(value.nachrichtText)) {
if (documentResource && isNotEmpty(documentResource.nachrichtText)) { if (documentResource && isNotEmpty(documentResource.nachrichtText)) {
this.setNachrichtText(documentResource.nachrichtText); this.setNachrichtText(documentResource.nachrichtText);
} else { } else {
this.setNachrichtText(this.buildNachrichtentext()); this.setNachrichtText(this.buildNachrichtentext());
} }
} }
}
public clearNachricht(): void { public clearNachricht(): void {
this.setNachrichtSubject(EMPTY_STRING); this.setNachrichtSubject(EMPTY_STRING);
......
...@@ -14,9 +14,14 @@ import { ...@@ -14,9 +14,14 @@ import {
ButtonCardComponent, ButtonCardComponent,
SpinnerIconComponent, SpinnerIconComponent,
} from '@ods/system'; } 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 { getDataTestIdOf } from 'libs/tech-shared/test/data-test';
import { MockComponent } from 'ng-mocks'; import { MockComponent } from 'ng-mocks';
import { of } from 'rxjs';
import { BescheidenFormService } from '../../../../bescheiden.formservice';
import { VorgangDetailBescheidenBescheidAutomatischErstellenComponent } from './vorgang-detail-bescheiden-bescheid-automatisch-erstellen.component'; import { VorgangDetailBescheidenBescheidAutomatischErstellenComponent } from './vorgang-detail-bescheiden-bescheid-automatisch-erstellen.component';
describe('VorgangDetailBescheidenBescheidAutomatischErstellenComponent', () => { describe('VorgangDetailBescheidenBescheidAutomatischErstellenComponent', () => {
...@@ -26,9 +31,11 @@ describe('VorgangDetailBescheidenBescheidAutomatischErstellenComponent', () => { ...@@ -26,9 +31,11 @@ describe('VorgangDetailBescheidenBescheidAutomatischErstellenComponent', () => {
const createBescheidDocumentButton: string = getDataTestIdOf('create-bescheid-document-button'); const createBescheidDocumentButton: string = getDataTestIdOf('create-bescheid-document-button');
let bescheidService: Mock<BescheidService>; let bescheidService: Mock<BescheidService>;
let formService: Mock<BescheidenFormService>;
beforeEach(async () => { beforeEach(async () => {
bescheidService = mock(BescheidService); bescheidService = mock(BescheidService);
formService = mock(BescheidenFormService);
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
imports: [HasLinkPipe], imports: [HasLinkPipe],
...@@ -44,6 +51,10 @@ describe('VorgangDetailBescheidenBescheidAutomatischErstellenComponent', () => { ...@@ -44,6 +51,10 @@ describe('VorgangDetailBescheidenBescheidAutomatischErstellenComponent', () => {
provide: BescheidService, provide: BescheidService,
useValue: bescheidService, useValue: bescheidService,
}, },
{
provide: BescheidenFormService,
useValue: formService,
},
], ],
}).compileComponents(); }).compileComponents();
...@@ -87,5 +98,38 @@ describe('VorgangDetailBescheidenBescheidAutomatischErstellenComponent', () => { ...@@ -87,5 +98,38 @@ describe('VorgangDetailBescheidenBescheidAutomatischErstellenComponent', () => {
existsAsHtmlElement(fixture, createBescheidDocumentButton); 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 { ...@@ -2,11 +2,14 @@ import {
BescheidLinkRel, BescheidLinkRel,
BescheidResource, BescheidResource,
BescheidService, BescheidService,
hasUploadNoError,
isUploadFinished,
UploadFileInProgress, UploadFileInProgress,
} from '@alfa-client/bescheid-shared'; } from '@alfa-client/bescheid-shared';
import { StateResource } from '@alfa-client/tech-shared'; import { StateResource } from '@alfa-client/tech-shared';
import { Component, Input } from '@angular/core'; import { Component, Input } from '@angular/core';
import { Observable, of } from 'rxjs'; import { Observable, of, tap } from 'rxjs';
import { BescheidenFormService } from '../../../../bescheiden.formservice';
@Component({ @Component({
selector: 'alfa-vorgang-detail-bescheiden-bescheid-automatisch-erstellen', selector: 'alfa-vorgang-detail-bescheiden-bescheid-automatisch-erstellen',
...@@ -21,9 +24,18 @@ export class VorgangDetailBescheidenBescheidAutomatischErstellenComponent { ...@@ -21,9 +24,18 @@ export class VorgangDetailBescheidenBescheidAutomatischErstellenComponent {
public readonly bescheidLinkRel = BescheidLinkRel; public readonly bescheidLinkRel = BescheidLinkRel;
constructor(private readonly bescheidService: BescheidService) {} constructor(
private readonly bescheidService: BescheidService,
private readonly formService: BescheidenFormService,
) {}
public createBescheidDocument(): void { 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