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

Merge branch 'master' into ozg-6647-network-policy-for-scraper

parents 8e54b2c2 afb777fe
Branches
Tags
No related merge requests found
Showing
with 211 additions and 148 deletions
<h1 class="heading-1">Postfach</h1>
<postfach-form [postfachStateResource]="postfachStateResource$ | async"></postfach-form>
import { StateResource, createStateResource } from '@alfa-client/tech-shared';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { singleCold, singleHot } from 'libs/tech-shared/test/marbles';
import { Mock, mock } from 'libs/test-utils/src/lib/mocking';
import { MockComponent } from 'ng-mocks';
import { singleCold, singleHot } from '../../../../../tech-shared/test/marbles';
import { Mock, mock } from '../../../../../test-utils/src/lib/mocking';
import { createPostfachResource } from '../../../../test/postfach/postfach';
import { PostfachResource } from '../postfach.model';
import { PostfachService } from '../postfach.service';
......
<form class="form flex-col" [formGroup]="formService.form">
<h1 class="text-2xl font-bold">Absender</h1>
<!--
<h2 class="heading-2">Absender</h1>
<p id="absender-desc" class="p-1">Hinterlegen Sie Absenderinformationen zu Ihrem Postfach.</p>
<div
[formGroupName]="PostfachFormService.ASBSENDER_GROUP"
......@@ -33,26 +34,21 @@
></text-field>
</div>
<div class="h-20"></div>
<h1 class="text-2xl font-bold">Signatur</h1>
<p id="signatur-desc">Erstellen oder ändern Sie die Signatur für Nachrichten.</p>
<textarea
data-test-id="signatur-text"
aria-describedby="signatur-desc"
[formControlName]="PostfachFormService.SIGNATUR_FIELD"
class="mb-2 mt-2 block h-40 w-96 p-1"
></textarea>
-->
<postfach-signatur class="mb-6 block" />
<admin-primary-button
(clickEmitter)="submit()"
[submitInProgress]="this.submitInProgress$ | async"
<ods-button-with-spinner
data-test-id="save-button"
label="Speichern"
></admin-primary-button>
text="Speichern"
[stateResource]="submitInProgress$ | async"
(clickEmitter)="submit()"
></ods-button-with-spinner>
<span
*ngIf="formService.invalidEmpty"
data-test-id="invalid-empty-message-span"
class="m-2 text-red-500"
>*Es müssen alle Felder ausgefüllt sein.</span
>
*Es müssen alle Felder ausgefüllt sein.
</span>
</form>
import { ProblemDetail, createStateResource } from '@alfa-client/tech-shared';
import {
Mock,
createEmptyStateResource,
createStateResource,
ProblemDetail,
} from '@alfa-client/tech-shared';
import {
dispatchEventFromFixture,
existsAsHtmlElement,
getDebugElementFromFixtureByCss,
getElementFromFixture,
Mock,
mock,
notExistsAsHtmlElement,
} from '@alfa-client/test-utils';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ButtonWithSpinnerComponent } from '@ods/component';
import { getDataTestIdOf } from 'libs/tech-shared/test/data-test';
import { MockComponent, ngMocks } from 'ng-mocks';
import { EMPTY, of } from 'rxjs';
import { createInvalidParam, createProblemDetail } from '../../../../../../tech-shared/test/error';
import { singleCold } from '../../../../../../tech-shared/test/marbles';
import { createInvalidParam, createProblemDetail } from 'libs/tech-shared/test/error';
import { singleCold } from 'libs/tech-shared/test/marbles';
import { MockComponent } from 'ng-mocks';
import { EMPTY } from 'rxjs';
import { createPostfachResource } from '../../../../../test/postfach/postfach';
import { PrimaryButtonComponent } from '../../../shared/primary-button/primary-button.component';
import { TextFieldComponent } from '../../../shared/text-field/text-field.component';
import { PostfachResource } from '../../postfach.model';
import { PostfachService } from '../../postfach.service';
import { PostfachFormComponent } from './postfach-form.component';
import { PostfachSignaturComponent } from './postfach-signatur/postfach-signatur.component';
import { PostfachFormService } from './postfach.formservice';
describe('PostfachFormComponent', () => {
......@@ -37,8 +40,9 @@ describe('PostfachFormComponent', () => {
await TestBed.configureTestingModule({
declarations: [
PostfachFormComponent,
MockComponent(PrimaryButtonComponent),
MockComponent(TextFieldComponent),
MockComponent(PostfachSignaturComponent),
MockComponent(ButtonWithSpinnerComponent),
],
imports: [ReactiveFormsModule, FormsModule],
providers: [
......@@ -86,59 +90,43 @@ describe('PostfachFormComponent', () => {
});
});
describe('Absender section', () => {
const fields: string[][] = [
[PostfachFormService.NAME_FIELD, 'Name', 'absender-name'],
[PostfachFormService.ANSCHRIFT_FIELD, 'Anschrift', 'absender-anschrift'],
[PostfachFormService.DIENST_FIELD, 'Dienst', 'absender-dienst'],
[PostfachFormService.MANDANT_FIELD, 'Mandant', 'absender-mandant'],
[
PostfachFormService.GEMEINDESCHLUESSEL_FIELD,
'Gemeindeschlüssel',
'absender-gemeindeschluessel',
],
];
test.each(fields)(
'should bind form for text-field "%s"',
async (fieldName, text, dataTestId) => {
const fieldValue = `some text-field ${text}`;
const absenderGroup = formService.form.get(PostfachFormService.ASBSENDER_GROUP);
const formControl = absenderGroup.get(fieldName);
const textFieldComponent = getDebugElementFromFixtureByCss(
fixture,
getDataTestIdOf(dataTestId),
);
ngMocks.change(textFieldComponent, fieldValue);
expect(formControl.value).toBe(fieldValue);
},
);
test.each(fields)(
'should have label for field "%s" with name "%s"',
(fieldName, text, dataTestId) => {
const textFieldElement = getElementFromFixture(fixture, getDataTestIdOf(dataTestId));
expect(textFieldElement.getAttribute('ng-reflect-label')).toBe(text);
},
);
});
describe('Signatur section', () => {
const signaturTextarea = getDataTestIdOf('signatur-text');
it('should have signatur-text', () => {
existsAsHtmlElement(fixture, signaturTextarea);
});
it('should set form-control-name', () => {
const text = 'some signature text';
formService.form.get(PostfachFormService.SIGNATUR_FIELD).setValue(text);
const textareaElement = getElementFromFixture(fixture, signaturTextarea);
expect(textareaElement.value).toBe(text);
});
});
// describe('Absender section', () => {
// const fields: string[][] = [
// [PostfachFormService.NAME_FIELD, 'Name', 'absender-name'],
// [PostfachFormService.ANSCHRIFT_FIELD, 'Anschrift', 'absender-anschrift'],
// [PostfachFormService.DIENST_FIELD, 'Dienst', 'absender-dienst'],
// [PostfachFormService.MANDANT_FIELD, 'Mandant', 'absender-mandant'],
// [
// PostfachFormService.GEMEINDESCHLUESSEL_FIELD,
// 'Gemeindeschlüssel',
// 'absender-gemeindeschluessel',
// ],
// ];
//
// test.each(fields)(
// 'should bind form for text-field "%s"',
// async (fieldName, text, dataTestId) => {
// const fieldValue = `some text-field ${text}`;
// const absenderGroup = formService.form.get(PostfachFormService.ASBSENDER_GROUP);
// const formControl = absenderGroup.get(fieldName);
//
// const textFieldComponent = getDebugElementFromFixtureByCss(
// fixture,
// getDataTestIdOf(dataTestId),
// );
// ngMocks.change(textFieldComponent, fieldValue);
// expect(formControl.value).toBe(fieldValue);
// },
// );
//
// test.each(fields)(
// 'should have label for field "%s" with name "%s"',
// (fieldName, text, dataTestId) => {
// const textFieldElement = getElementFromFixture(fixture, getDataTestIdOf(dataTestId));
// expect(textFieldElement.getAttribute('ng-reflect-label')).toBe(text);
// },
// );
// });
describe('save button', () => {
it('should call submit on click', () => {
......@@ -150,17 +138,17 @@ describe('PostfachFormComponent', () => {
expect(submitFn).toHaveBeenCalled();
});
it.each([true, false])('should use submit progress "%s"', (progress) => {
component.submitInProgress$ = of(progress);
fixture.detectChanges();
const saveButtonComponent: PrimaryButtonComponent = getDebugElementFromFixtureByCss(
fixture,
saveButtonSelector,
).componentInstance;
expect(saveButtonComponent.submitInProgress).toBe(progress);
});
// it.each([true, false])('should use submit progress "%s"', (progress) => {
// component.submitInProgress$ = of(progress);
//
// fixture.detectChanges();
//
// const saveButtonComponent: ButtonWithSpinnerComponent = getDebugElementFromFixtureByCss(
// fixture,
// saveButtonSelector,
// ).componentInstance;
// expect(saveButtonComponent.loading).toBe(progress);
// });
});
describe('invalid message', () => {
......@@ -190,11 +178,12 @@ describe('PostfachFormComponent', () => {
describe('submit', () => {
it('should assign submit in progress', () => {
formService.submitWithProgress = jest.fn().mockReturnValue(singleCold(true));
const stateResource = createEmptyStateResource();
formService.submit = jest.fn().mockReturnValue(singleCold(stateResource));
component.submit();
expect(component.submitInProgress$).toBeObservable(singleCold(true));
expect(component.submitInProgress$).toBeObservable(singleCold(stateResource));
});
});
});
import { StateResource, isNotNil } from '@alfa-client/tech-shared';
import { createEmptyStateResource, isNotNil, StateResource } from '@alfa-client/tech-shared';
import { Component, Input } from '@angular/core';
import { Resource } from '@ngxp/rest';
import { Observable, of } from 'rxjs';
import { PostfachResource } from '../../postfach.model';
import { PostfachFormService } from './postfach.formservice';
......@@ -10,7 +11,7 @@ import { PostfachFormService } from './postfach.formservice';
providers: [PostfachFormService],
})
export class PostfachFormComponent {
submitInProgress$: Observable<boolean> = of(false);
submitInProgress$: Observable<StateResource<Resource>> = of(createEmptyStateResource<Resource>());
@Input() set postfachStateResource(stateResource: StateResource<PostfachResource>) {
this.updatePostfachResource(stateResource.resource);
......@@ -27,6 +28,6 @@ export class PostfachFormComponent {
constructor(public formService: PostfachFormService) {}
public submit(): void {
this.submitInProgress$ = this.formService.submitWithProgress();
this.submitInProgress$ = this.formService.submit();
}
}
<form [formGroup]="formService.form">
<h2 class="heading-2">Signatur</h2>
<p id="signatur-desc">
Diese Signatur wird bei allen Nachrichten an den Antragsteller angezeigt.
</p>
<ods-textarea-editor
[formControlName]="formServiceClass.SIGNATUR_FIELD"
[isResizable]="false"
data-test-id="signatur-text"
label=""
rows="6"
class="w-full"
aria-describedby="signatur-desc"
/>
</form>
import { getElementFromFixture, mock, useFromMock } from '@alfa-client/test-utils';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
import { TextareaEditorComponent } from '@ods/component';
import { getDataTestIdOf } from 'libs/tech-shared/test/data-test';
import { MockComponent } from 'ng-mocks';
import { PostfachService } from '../../../postfach.service';
import { PostfachFormComponent } from '../postfach-form.component';
import { PostfachFormService } from '../postfach.formservice';
import { PostfachSignaturComponent } from './postfach-signatur.component';
describe('PostfachSignaturComponent', () => {
let component: PostfachSignaturComponent;
let fixture: ComponentFixture<PostfachSignaturComponent>;
const formService: PostfachFormService = new PostfachFormService(
new FormBuilder(),
useFromMock(mock(PostfachService)),
);
const signaturTextarea = getDataTestIdOf('signatur-text');
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ReactiveFormsModule],
declarations: [PostfachFormComponent, MockComponent(TextareaEditorComponent)],
providers: [
{
provide: PostfachFormService,
useValue: formService,
},
],
}).compileComponents();
fixture = TestBed.createComponent(PostfachSignaturComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
describe('template', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
describe('ods-textarea-editor', () => {
describe('input', () => {
it('should set formControlName to Signatur Field', () => {
const textAreaEditor = getElementFromFixture(fixture, signaturTextarea);
expect(textAreaEditor.getAttribute('rows')).toEqual('6');
});
});
});
});
});
import { Component } from '@angular/core';
import { PostfachFormService } from '../postfach.formservice';
@Component({
selector: 'postfach-signatur',
templateUrl: './postfach-signatur.component.html',
})
export class PostfachSignaturComponent {
protected readonly formServiceClass = PostfachFormService;
constructor(public formService: PostfachFormService) {}
}
import {
createEmptyStateResource,
createStateResource,
StateResource,
} from '@alfa-client/tech-shared';
import { createStateResource, StateResource } from '@alfa-client/tech-shared';
import { mock, Mock, useFromMock } from '@alfa-client/test-utils';
import { FormBuilder } from '@angular/forms';
import { cold } from 'jest-marbles';
import { Observable, of } from 'rxjs';
import { of } from 'rxjs';
import { createPostfach, createPostfachResource } from '../../../../../test/postfach/postfach';
import { Postfach, PostfachResource } from '../../postfach.model';
import { PostfachService } from '../../postfach.service';
......@@ -19,7 +14,6 @@ describe('PostfachFormService', () => {
beforeEach(() => {
postfachService = mock(PostfachService);
formService = new PostfachFormService(formBuilder, useFromMock(postfachService));
});
......@@ -93,19 +87,4 @@ describe('PostfachFormService', () => {
});
});
});
describe('submit with progress', () => {
it('should assign submit in progress to state resource loading', () => {
formService.submit = jest.fn().mockReturnValue(
cold('ab', {
a: createEmptyStateResource(true),
b: createEmptyStateResource(false),
}),
);
const progressObservable: Observable<boolean> = formService.submitWithProgress();
expect(progressObservable).toBeObservable(cold('ab', { a: true, b: false }));
});
});
});
import {
AbstractFormService,
EMPTY_STRING,
HttpError,
ProblemDetail,
StateResource,
} from '@alfa-client/tech-shared';
import { AbstractFormService, EMPTY_STRING, StateResource } from '@alfa-client/tech-shared';
import { Injectable } from '@angular/core';
import { FormControl, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
import { isNil } from 'lodash-es';
import { Observable, map } from 'rxjs';
import { Observable } from 'rxjs';
import { Postfach, PostfachResource } from '../../postfach.model';
import { PostfachService } from '../../postfach.service';
......@@ -43,7 +37,7 @@ export class PostfachFormService extends AbstractFormService {
});
}
protected doSubmit(): Observable<StateResource<PostfachResource | HttpError>> {
protected doSubmit(): Observable<StateResource<PostfachResource>> {
const value: Postfach = this.getFormValue();
if (this.shouldSkipAbsender(value)) {
delete value.absender;
......@@ -65,12 +59,4 @@ export class PostfachFormService extends AbstractFormService {
public get invalidEmpty(): boolean {
return this.form.invalid;
}
public submitWithProgress(): Observable<boolean> {
return this.submit().pipe(
map(
(stateResource: StateResource<PostfachResource | ProblemDetail>) => stateResource.loading,
),
);
}
}
import { HttpError, StateResource, createStateResource } from '@alfa-client/tech-shared';
import {
StateResource,
createEmptyStateResource,
createStateResource,
} from '@alfa-client/tech-shared';
import { Mock, mock, useFromMock } from '@alfa-client/test-utils';
import { SnackBarService } from '@alfa-client/ui';
import { Type } from '@angular/core';
import { Observable } from 'rxjs';
import { singleCold, singleHot } from '../../../../tech-shared/test/marbles';
import { fakeAsync, tick } from '@angular/core/testing';
import { cold } from 'jest-marbles';
import { singleCold, singleHot } from 'libs/tech-shared/test/marbles';
import { Observable, of } from 'rxjs';
import { createPostfachResource, createPostfachSettingItem } from '../../../test/postfach/postfach';
import { PostfachResourceService } from './postfach-resource.service';
import { PostfachResource, PostfachSettingsItem } from './postfach.model';
......@@ -11,11 +18,12 @@ import { PostfachService } from './postfach.service';
describe('PostfachService', () => {
let service: PostfachService;
let resourceService: Mock<PostfachResourceService>;
const snackbarService: Mock<SnackBarService> = mock(SnackBarService);
beforeEach(() => {
resourceService = mockResourceService(PostfachResourceService);
service = new PostfachService(useFromMock(resourceService));
service = new PostfachService(useFromMock(resourceService), useFromMock(snackbarService));
});
it('should create', () => {
......@@ -36,8 +44,7 @@ describe('PostfachService', () => {
it('should reurn value', () => {
resourceService.get.mockReturnValue(singleCold(postfachStateResource));
const returnedPostfachResource: Observable<StateResource<PostfachResource | HttpError>> =
service.get();
const returnedPostfachResource: Observable<StateResource<PostfachResource>> = service.get();
expect(returnedPostfachResource).toBeObservable(singleHot(postfachStateResource));
});
......@@ -45,25 +52,48 @@ describe('PostfachService', () => {
describe('save', () => {
const postfachSettingsItem: PostfachSettingsItem = createPostfachSettingItem();
const postfachResource: PostfachResource = createPostfachResource();
const postfachStateResource: StateResource<PostfachResource> =
createStateResource(postfachResource);
beforeEach(() => {});
it('should call resourceService', () => {
resourceService.save.mockReturnValue(of(postfachStateResource));
service.save(postfachSettingsItem.settingBody);
expect(resourceService.save).toHaveBeenCalledWith(postfachSettingsItem);
});
it('should return saved value', () => {
const postfachResource: PostfachResource = createPostfachResource();
const postfachStateResource: StateResource<PostfachResource> =
createStateResource(postfachResource);
resourceService.save.mockReturnValue(singleCold(postfachStateResource));
resourceService.save.mockReturnValue(singleCold(postfachStateResource, '-a'));
const savedPostfach: Observable<StateResource<PostfachResource | HttpError>> = service.save(
const savedPostfach: Observable<StateResource<PostfachResource>> = service.save(
postfachResource.settingBody,
);
expect(savedPostfach).toBeObservable(singleHot(postfachStateResource));
expect(savedPostfach).toBeObservable(
cold('ab', {
a: createEmptyStateResource<PostfachResource>(true),
b: postfachStateResource,
}),
);
});
it('should show message in snackbar', fakeAsync(() => {
resourceService.save.mockReturnValue(of(postfachStateResource));
const savedPostfach: Observable<StateResource<PostfachResource>> = service.save(
postfachResource.settingBody,
);
savedPostfach.subscribe();
tick();
expect(snackbarService.showInfo).toHaveBeenCalledWith(
'Die Signatur wird erfolgreich gespeichert.',
);
}));
});
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment