diff --git a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.html b/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.html index b2f802746800eba012216c7670f9ea2d27ad63cf..1d45140a6b337ec1df5164b76216ba8768f9542e 100644 --- a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.html +++ b/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.html @@ -8,11 +8,7 @@ </button> <form [formGroup]="formService.form" class="m-5 grid grid-cols-1 gap-5"> <h1 class="text-2xl" data-test-id="organisationseinheit-form-header"> - {{ - formService.isPatch() ? - 'Organisationseinheit bearbeiten' - : 'Neue Organisationseinheit anlegen' - }} + {{ label }} </h1> <text-field label="Name" diff --git a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.spec.ts b/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.spec.ts index 2d0893b6f270dbcaec4df67938b142659738c3e2..b8ab4fc50084162e18e59d0f50ef4f3b0a95146d 100644 --- a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.spec.ts +++ b/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.spec.ts @@ -242,6 +242,12 @@ describe('OrganisationseinheitFormComponent', () => { form.markAsTouched(); }); + it('should set create label', () => { + component.open(); + + expect(component.label).toEqual(OrganisationseinheitFormComponent.CREATE_LABEL); + }); + it('should open form', () => { component.open(); @@ -260,12 +266,20 @@ describe('OrganisationseinheitFormComponent', () => { describe('open edit', () => { const organisationseinheit: Organisationseinheit = createOrganisationseinheit(); + it('should set edit label', () => { + component.openEdit(organisationseinheit); + + expect(component.label).toEqual(OrganisationseinheitFormComponent.EDIT_LABEL); + }); + it('should open dialog', () => { component.open(); expect(component.dialog.showModal).toHaveBeenCalled(); }); + + it('should patch form', () => { component.formService.patch = jest.fn(); @@ -293,22 +307,14 @@ describe('OrganisationseinheitFormComponent', () => { }); describe('header', () => { - it('should show create-organisationseinheit text if not patch', () => { - component.formService.isPatch = jest.fn().mockReturnValue(false); - - fixture.detectChanges(); - - const headerElement: HTMLElement = getElementFromFixture(fixture, headerSelector); - expect(headerElement.textContent).toContain('Neue'); - }); - - it('should show update-organisationseinheit text if is patch', () => { - component.formService.isPatch = jest.fn().mockReturnValue(true); + it('should show label text', () => { + const text: string = 'test-text'; + component.label = text; fixture.detectChanges(); const headerElement: HTMLElement = getElementFromFixture(fixture, headerSelector); - expect(headerElement.textContent).not.toContain('Neue'); + expect(headerElement.textContent.trim()).toEqual(text); }); }); }); diff --git a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.ts b/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.ts index 45792b023be292c9738bec1237196618ccc66716..20e324636ca313d61ba55987f343268643d84cbf 100644 --- a/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.ts +++ b/alfa-client/libs/admin-settings/src/lib/organisationseinheit/organisationseinheit-container/organisationseinheit-form/organisationseinheit-form.component.ts @@ -9,6 +9,9 @@ import { Organisationseinheit } from '../../../user/user.model'; providers: [OrganisationseinheitFormservice], }) export class OrganisationseinheitFormComponent implements OnInit, AfterViewInit { + static CREATE_LABEL: string = 'Neue Organisationseinheit anlegen'; + static EDIT_LABEL: string = 'Organisationseinheit bearbeiten'; + protected readonly OrganisationseinheitFormService = OrganisationseinheitFormservice; @ViewChild('OrganisationseinheitDialog') private dialogRef: ElementRef<HTMLDialogElement>; @@ -16,6 +19,8 @@ export class OrganisationseinheitFormComponent implements OnInit, AfterViewInit submitInProgress$: Observable<boolean>; + label: string; + constructor(public formService: OrganisationseinheitFormservice) {} ngAfterViewInit(): void { @@ -45,11 +50,13 @@ export class OrganisationseinheitFormComponent implements OnInit, AfterViewInit } public open(): void { + this.label = OrganisationseinheitFormComponent.CREATE_LABEL; this.formService.reset(); this.dialog.showModal(); } public openEdit(organisationseinheit: Organisationseinheit): void { + this.label = OrganisationseinheitFormComponent.EDIT_LABEL; this.formService.patch(organisationseinheit); this.dialog.showModal(); }