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

OZG-6499 OZG-6620 add newline to mail body

parent dbf067ef
No related branches found
No related tags found
No related merge requests found
......@@ -83,6 +83,10 @@ export function createPostfachSettings(): PostfachSettings {
return { signatur: 'Best regards' };
}
export function createEmptyPostfachSettings(): PostfachSettings {
return { signatur: '' };
}
export class PostfachTestFactory {
public static POSTFACH_NACHRICHT: PostfachMail = {
subject: faker.random.words(3),
......
......@@ -28,6 +28,7 @@ import { Mock, mock, useFromMock } from '@alfa-client/test-utils';
import { UntypedFormBuilder } from '@angular/forms';
import { createCommandResource } from 'libs/command-shared/test/command';
import {
createEmptyPostfachSettings,
createPostfachMailResource,
createPostfachSettings,
} from 'libs/postfach-shared/test/postfach';
......@@ -36,15 +37,13 @@ import { PostfachMailFormservice } from './postfach-mail.formservice';
describe('PostfachMailFormservice', () => {
let formService: PostfachMailFormservice;
let service: Mock<any>;
let service: Mock<any> = mock(PostfachService);
const formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
const postfachSettings: PostfachSettings = createPostfachSettings();
beforeEach(() => {
service = mock(PostfachService);
service.getSettings.mockReturnValue(of(postfachSettings));
formService = new PostfachMailFormservice(formBuilder, useFromMock(service));
});
......@@ -97,12 +96,21 @@ describe('PostfachMailFormservice', () => {
expect(service.getSettings).toHaveBeenCalled();
});
it('should init mail body with signatur', () => {
it('should set field mail body with signatur and newline if signatur is not empty', () => {
formService.initMailBody();
const mailBodyValue = formService.form.get(PostfachMailFormservice.FIELD_MAIL_BODY).value;
expect(mailBodyValue).toBe(`\n${postfachSettings.signatur}`);
});
it('should not set field mail body if signatur is empty', () => {
service.getSettings.mockReturnValue(of(createEmptyPostfachSettings()));
formService = new PostfachMailFormservice(formBuilder, useFromMock(service));
expect(mailBodyValue).toBe(postfachSettings.signatur);
formService.initMailBody();
const mailBodyValue = formService.form.get(PostfachMailFormservice.FIELD_MAIL_BODY).value;
expect(mailBodyValue).toBe(null);
});
});
});
......@@ -66,11 +66,23 @@ export class PostfachMailFormservice extends AbstractFormService {
this.loadPostfachSettingsSubscription = this.postfachService
.getSettings()
.subscribe((settings: PostfachSettings) => {
this.form.get(PostfachMailFormservice.FIELD_MAIL_BODY)?.setValue(settings.signatur);
if (settings.signatur) {
this.patchMailBodyWithSignaturAndNewline(settings.signatur);
}
this.loadPostfachSettingsSubscription.unsubscribe();
});
}
private patchMailBodyWithSignaturAndNewline(signatur: string) {
this.form
.get(PostfachMailFormservice.FIELD_MAIL_BODY)
.setValue(this.addNewlineAtBeginning(signatur));
}
private addNewlineAtBeginning(value: string): string {
return `\n${value}`;
}
protected getPathPrefix(): string {
return PostfachMailFormservice.FIELD_PATH_PREFIX;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment