diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-nachricht-reply-editor-container/postfach-nachricht-reply-editor-container.component.html b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-nachricht-reply-editor-container/postfach-nachricht-reply-editor-container.component.html index 4d6b60475269f0c8fea1aadf4917c03875d01581..0ccbd9290216d23a3fa240714d1e72f27b98ad86 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-nachricht-reply-editor-container/postfach-nachricht-reply-editor-container.component.html +++ b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-nachricht-reply-editor-container/postfach-nachricht-reply-editor-container.component.html @@ -1,10 +1,6 @@ <ng-container *ngIf="postfachFeatures$ | async as postfachFeatures"> - <ozgcloud-enum-editor - *ngIf="postfachFeatures.reply" - data-test-id="postfach-reply-option" - [formControlName]="formServiceClass.FIELD_REPLY_OPTION" - [defaultItem]="defaultItem" - [itemList]="itemList" - > + <ozgcloud-enum-editor *ngIf="postfachFeatures.reply" data-test-id="postfach-reply-option" + label="Antwort vom Antragsteller benötigt" [formControlName]="formServiceClass.FIELD_REPLY_OPTION" + [defaultItem]="uncheckedItem" [checkedItem]="checkedItem" [uncheckedItem]="uncheckedItem"> </ozgcloud-enum-editor> -</ng-container> +</ng-container> \ No newline at end of file diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-nachricht-reply-editor-container/postfach-nachricht-reply-editor-container.component.spec.ts b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-nachricht-reply-editor-container/postfach-nachricht-reply-editor-container.component.spec.ts index ef6570a027fa28d5536b40d0474788aba82608a3..a11f31b4139cbc6477cfd538d4e3637074753010 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-nachricht-reply-editor-container/postfach-nachricht-reply-editor-container.component.spec.ts +++ b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-nachricht-reply-editor-container/postfach-nachricht-reply-editor-container.component.spec.ts @@ -1,5 +1,5 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { FormControl, FormGroup, FormGroupDirective, ReactiveFormsModule } from '@angular/forms'; +import { FormControl, FormGroup, FormGroupDirective, NG_VALUE_ACCESSOR, ReactiveFormsModule } from '@angular/forms'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { FORBIDDEN_REPLY_OPTION_ITEM, @@ -19,6 +19,7 @@ import { MockComponent } from 'ng-mocks'; import { of } from 'rxjs'; import { PostfachMailFormservice } from '../postfach-mail.formservice'; import { PostfachNachrichtReplyEditorContainerComponent } from './postfach-nachricht-reply-editor-container.component'; +import { forwardRef } from '@angular/core'; describe('PostfachNachrichtReplyEditorContainerComponent', () => { let component: PostfachNachrichtReplyEditorContainerComponent; @@ -39,7 +40,7 @@ describe('PostfachNachrichtReplyEditorContainerComponent', () => { await TestBed.configureTestingModule({ declarations: [ PostfachNachrichtReplyEditorContainerComponent, - MockComponent(EnumEditorComponent), + MockComponent(EnumEditorComponent) ], providers: [ { @@ -49,7 +50,7 @@ describe('PostfachNachrichtReplyEditorContainerComponent', () => { { provide: FormGroupDirective, useValue: formGroupDirective, - }, + } ], imports: [ReactiveFormsModule, BrowserAnimationsModule], }).compileComponents(); @@ -94,18 +95,22 @@ describe('PostfachNachrichtReplyEditorContainerComponent', () => { fixture.detectChanges(); const enumEditor: EnumEditorComponent = getMockComponent(fixture, EnumEditorComponent); - expect(enumEditor.defaultItem).toBe(POSSIBLE_REPLY_OPTION_ITEM); + expect(enumEditor.defaultItem).toBe(FORBIDDEN_REPLY_OPTION_ITEM); }); - it('should be called wirh itemList', () => { + it('should be called with checked item', () => { fixture.detectChanges(); const enumEditor: EnumEditorComponent = getMockComponent(fixture, EnumEditorComponent); - expect(enumEditor.itemList).toEqual([ - POSSIBLE_REPLY_OPTION_ITEM, - FORBIDDEN_REPLY_OPTION_ITEM, - ]); + expect(enumEditor.checkedItem).toBe(POSSIBLE_REPLY_OPTION_ITEM); }); + + it('should be called with unchecked item', () => { + fixture.detectChanges(); + + const enumEditor: EnumEditorComponent = getMockComponent(fixture, EnumEditorComponent); + expect(enumEditor.uncheckedItem).toBe(FORBIDDEN_REPLY_OPTION_ITEM); + }) }); describe('on unavailable feature', () => { diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-nachricht-reply-editor-container/postfach-nachricht-reply-editor-container.component.ts b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-nachricht-reply-editor-container/postfach-nachricht-reply-editor-container.component.ts index dff70f9872dcaf71b52d57f44894a9a443f6c15d..22743dab120f94048d78191c04a5b2aacf1c49e5 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-nachricht-reply-editor-container/postfach-nachricht-reply-editor-container.component.ts +++ b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-nachricht-reply-editor-container/postfach-nachricht-reply-editor-container.component.ts @@ -17,17 +17,16 @@ import { PostfachMailFormservice } from '../postfach-mail.formservice'; viewProviders: [FormProvider], }) export class PostfachNachrichtReplyEditorContainerComponent implements OnInit { - public readonly itemList: EnumEditorItem[] = [ - POSSIBLE_REPLY_OPTION_ITEM, - FORBIDDEN_REPLY_OPTION_ITEM, - ]; - public readonly defaultItem: EnumEditorItem = POSSIBLE_REPLY_OPTION_ITEM; + public readonly defaultItem: EnumEditorItem = FORBIDDEN_REPLY_OPTION_ITEM; public readonly formServiceClass = PostfachMailFormservice; public postfachFeatures$: Observable<Features>; - constructor(private postfachService: PostfachService) {} + public checkedItem: EnumEditorItem = POSSIBLE_REPLY_OPTION_ITEM; + public uncheckedItem: EnumEditorItem = FORBIDDEN_REPLY_OPTION_ITEM; + + constructor(private postfachService: PostfachService) { } ngOnInit(): void { this.postfachFeatures$ = this.postfachService.getFeatures(); diff --git a/alfa-client/libs/ui/src/lib/ui/editor/enum-editor/enum-editor.component.html b/alfa-client/libs/ui/src/lib/ui/editor/enum-editor/enum-editor.component.html index 6425e1981f23a3da1574b2b3e35af4c723c5e693..3195ae545fc84b615825b642dfc81473d3064510 100644 --- a/alfa-client/libs/ui/src/lib/ui/editor/enum-editor/enum-editor.component.html +++ b/alfa-client/libs/ui/src/lib/ui/editor/enum-editor/enum-editor.component.html @@ -23,33 +23,4 @@ unter der Lizenz sind dem Lizenztext zu entnehmen. --> -<ozgcloud-icon-button-with-spinner - [icon]="selectedItem.icon" - [svgIcon]="selectedItem.svgIcon" - [matMenuTriggerFor]="menu.matMenu" - toolTip="Antworten erlauben/unterbinden" - class="reply-toggle" -> -</ozgcloud-icon-button-with-spinner> - -<ozgcloud-menu #menu class="reply-option-menu"> - <button - *ngFor="let item of itemList" - mat-menu-item - (click)="setSelectedEnumItem(item)" - [attr.data-test-id]="(item.type | convertForDataTest) + '-enum-item'" - [attr.aria-label]="item.text" - > - <mat-icon *ngIf="item.svgIcon" [svgIcon]="item.svgIcon"></mat-icon> - <mat-icon *ngIf="!item.svgIcon">{{ item.icon }}</mat-icon> - <span> {{ item.text }}</span> - </button> -</ozgcloud-menu> - -<mat-label>{{ label }}</mat-label> -<input - [formControl]="fieldControl" - [attr.data-test-id]="(label | convertForDataTest) + '-enum-input'" - type="hidden" - (blur)="touch()" -/> +<mat-checkbox [checked]="selected" (change)="setSelection($event)">{{ label }}</mat-checkbox> \ No newline at end of file diff --git a/alfa-client/libs/ui/src/lib/ui/editor/enum-editor/enum-editor.component.spec.ts b/alfa-client/libs/ui/src/lib/ui/editor/enum-editor/enum-editor.component.spec.ts index ebde58c7f1f2ec23c6e1ae272b409eb10355e2de..02810003ee048b988dbb1405bc0fb55fb6be82a2 100644 --- a/alfa-client/libs/ui/src/lib/ui/editor/enum-editor/enum-editor.component.spec.ts +++ b/alfa-client/libs/ui/src/lib/ui/editor/enum-editor/enum-editor.component.spec.ts @@ -30,6 +30,8 @@ import { ConvertForDataTestPipe } from '@alfa-client/tech-shared'; import { IconButtonWithSpinnerComponent, UiModule } from '@alfa-client/ui'; import { MockComponent } from 'ng-mocks'; import { EnumEditorComponent } from './enum-editor.component'; +import { Mock, mock, useFromMock } from '@alfa-client/test-utils'; +import { MatCheckboxChange } from '@angular/material/checkbox'; describe('EnumEditorComponent', () => { let component: EnumEditorComponent; @@ -51,6 +53,8 @@ describe('EnumEditorComponent', () => { fixture = TestBed.createComponent(EnumEditorComponent); component = fixture.componentInstance; component.defaultItem = { type: 'enumType', icon: 'x', text: 'y' }; + component.checkedItem = { type: 'positive', icon: 'x', text: 'y' }; + component.uncheckedItem = { type: 'negative', icon: 'x', text: 'y' } component.itemList = [{ type: 'enumType', icon: 'x', text: 'y' }]; fixture.detectChanges(); }); @@ -58,4 +62,24 @@ describe('EnumEditorComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); + + describe('setSelection', () => { + const writeMethodMock = jest.fn(); + + beforeEach(() => { + component.writeValue = writeMethodMock; + }) + + it('should write checked value on selected', () => { + component.setSelection({ source: null, checked: true }); + + expect(writeMethodMock).toHaveBeenCalledWith('positive'); + }) + + it('should write unchecked value on selected', () => { + component.setSelection({ source: null, checked: false }); + + expect(writeMethodMock).toHaveBeenCalledWith('negative'); + }) + }) }); diff --git a/alfa-client/libs/ui/src/lib/ui/editor/enum-editor/enum-editor.component.ts b/alfa-client/libs/ui/src/lib/ui/editor/enum-editor/enum-editor.component.ts index 58a4a6f3413d95da58da14ec6b0cf0126eecfa76..e5d1324fb0f9fecf90a5d3c3f0116da5ba00e126 100644 --- a/alfa-client/libs/ui/src/lib/ui/editor/enum-editor/enum-editor.component.ts +++ b/alfa-client/libs/ui/src/lib/ui/editor/enum-editor/enum-editor.component.ts @@ -24,6 +24,7 @@ import { Component, Input, OnInit } from '@angular/core'; import { FormControlEditorAbstractComponent } from '../formcontrol-editor.abstract.component'; import { EnumEditorItem } from './enum-editor.model'; +import { MatCheckboxChange } from '@angular/material/checkbox'; @Component({ selector: 'ozgcloud-enum-editor', @@ -33,16 +34,19 @@ import { EnumEditorItem } from './enum-editor.model'; export class EnumEditorComponent extends FormControlEditorAbstractComponent implements OnInit { @Input() label: string; @Input() itemList: EnumEditorItem[]; + @Input() defaultItem: EnumEditorItem; + @Input() checkedItem: EnumEditorItem; + @Input() uncheckedItem: EnumEditorItem; - selectedItem: EnumEditorItem; + public selected: boolean; override ngOnInit(): void { - this.selectedItem = this.defaultItem; + this.selected = this.defaultItem === this.checkedItem; + this.writeValue(this.defaultItem.type); } - setSelectedEnumItem(item: EnumEditorItem): void { - this.selectedItem = item; - this.writeValue(item.type); + setSelection(event: MatCheckboxChange): void { + this.writeValue(event.checked ? this.checkedItem.type : this.uncheckedItem.type); } } diff --git a/alfa-client/libs/ui/src/lib/ui/editor/formcontrol-editor.abstract.component.ts b/alfa-client/libs/ui/src/lib/ui/editor/formcontrol-editor.abstract.component.ts index 345cf7de9e8bc26499a742b344023b7b0ec018d2..8d81d9235d938924927e382601b2d7000547a759 100644 --- a/alfa-client/libs/ui/src/lib/ui/editor/formcontrol-editor.abstract.component.ts +++ b/alfa-client/libs/ui/src/lib/ui/editor/formcontrol-editor.abstract.component.ts @@ -89,7 +89,7 @@ export abstract class FormControlEditorAbstractComponent implements ControlValue get issues(): Issue[] { return this.fieldControl.errors ? - Object.keys(this.fieldControl.errors).map((key) => <Issue>this.fieldControl.errors[key]) + Object.keys(this.fieldControl.errors).map((key) => <Issue>this.fieldControl.errors[key]) : []; } } diff --git a/alfa-client/libs/ui/src/lib/ui/ui.module.ts b/alfa-client/libs/ui/src/lib/ui/ui.module.ts index 61c0bd7440b5187519bb0b8397c35f88bc7f7678..f0db9b3749bfd8f9a0e32d3d35a4dd9f596de1da 100644 --- a/alfa-client/libs/ui/src/lib/ui/ui.module.ts +++ b/alfa-client/libs/ui/src/lib/ui/ui.module.ts @@ -117,7 +117,6 @@ import { OzgcloudPasteTextButtonComponent } from './ozgcloud-paste-text-button/o ValidationErrorComponent, AutocompleteEditorComponent, FixedDialogComponent, - EnumEditorComponent, InternalServerErrorDialogComponent, FileUploadEditorComponent, MatTooltipDirective, @@ -218,7 +217,6 @@ import { OzgcloudPasteTextButtonComponent } from './ozgcloud-paste-text-button/o ValidationErrorComponent, AutocompleteEditorComponent, FixedDialogComponent, - EnumEditorComponent, InternalServerErrorDialogComponent, FileUploadEditorComponent, MatTooltipDirective, @@ -268,4 +266,4 @@ import { OzgcloudPasteTextButtonComponent } from './ozgcloud-paste-text-button/o }, ], }) -export class UiModule {} +export class UiModule { }