From 33c8c2259b55e0d4ac6cdf8cdba17196ca22fe74 Mon Sep 17 00:00:00 2001 From: OZGCloud <ozgcloud@mgm-tp.com> Date: Tue, 29 Oct 2024 11:15:52 +0100 Subject: [PATCH] OZG-6720 CR Kommentare --- ...tionseinheit-form-container.component.html | 14 +++---- ...nseinheit-form-container.component.spec.ts | 42 +++++++++++++------ 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-form-container/organisationseinheit-form-container.component.html b/alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-form-container/organisationseinheit-form-container.component.html index f31e92e3c5..002d809c41 100644 --- a/alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-form-container/organisationseinheit-form-container.component.html +++ b/alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-form-container/organisationseinheit-form-container.component.html @@ -1,8 +1,8 @@ -<h1 class="heading-1" data-test-id="organisations-form-container-headline"> - {{ (organisationsEinheitStateResource$ | async)?.resource?.name }} -</h1> +<ng-container *ngIf="organisationsEinheitStateResource$ | async as organisationsEinheitStateResource"> + <h1 class="heading-1" data-test-id="organisations-form-container-headline">{{ organisationsEinheitStateResource.resource?.name }}</h1> -<admin-organisationseinheit-form - [organisationsEinheitStateResource]="organisationsEinheitStateResource$ | async" - data-test-id="organisations-form" -/> \ No newline at end of file + <admin-organisationseinheit-form + [organisationsEinheitStateResource]="organisationsEinheitStateResource" + data-test-id="organisations-form" + ></admin-organisationseinheit-form> +</ng-container> \ No newline at end of file diff --git a/alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-form-container/organisationseinheit-form-container.component.spec.ts b/alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-form-container/organisationseinheit-form-container.component.spec.ts index c0854bf531..a315bac9c5 100644 --- a/alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-form-container/organisationseinheit-form-container.component.spec.ts +++ b/alfa-client/libs/admin/settings/src/lib/organisationseinheit/organisationseinheit-form-container/organisationseinheit-form-container.component.spec.ts @@ -1,6 +1,6 @@ import { AdminOrganisationsEinheitResource, OrganisationsEinheitFormContainerComponent } from '@admin-client/admin-settings'; import { StateResource, createStateResource } from '@alfa-client/tech-shared'; -import { Mock, existsAsHtmlElement, mock } from '@alfa-client/test-utils'; +import { Mock, existsAsHtmlElement, getElementFromFixture, getMockComponent, mock } from '@alfa-client/test-utils'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { MockComponent } from 'ng-mocks'; import { of } from 'rxjs'; @@ -12,12 +12,16 @@ import { OrganisationsEinheitFormComponent } from './organisationseinheit-form/o describe('OrganisationsEinheitFormContainerComponent', () => { let component: OrganisationsEinheitFormContainerComponent; let fixture: ComponentFixture<OrganisationsEinheitFormContainerComponent>; + let organisationsEinheitService: Mock<OrganisationsEinheitService>; - const organisationsEinheitService: Mock<OrganisationsEinheitService> = mock(OrganisationsEinheitService); - - const organisationsEinheitStateResource = createStateResource(createAdminOrganisationsEinheitResource()); + const organisationsEinheitResource: AdminOrganisationsEinheitResource = createAdminOrganisationsEinheitResource(); + const organisationsEinheitStateResource: StateResource<AdminOrganisationsEinheitResource> = + createStateResource(organisationsEinheitResource); beforeEach(async () => { + organisationsEinheitService = mock(OrganisationsEinheitService); + organisationsEinheitService.get = jest.fn().mockReturnValue(of(organisationsEinheitStateResource)); + await TestBed.configureTestingModule({ declarations: [OrganisationsEinheitFormContainerComponent, MockComponent(OrganisationsEinheitFormComponent)], providers: [{ provide: OrganisationsEinheitService, useValue: organisationsEinheitService }], @@ -25,9 +29,6 @@ describe('OrganisationsEinheitFormContainerComponent', () => { fixture = TestBed.createComponent(OrganisationsEinheitFormContainerComponent); component = fixture.componentInstance; - - organisationsEinheitService.get = jest.fn().mockReturnValue(of(organisationsEinheitStateResource)); - fixture.detectChanges(); }); @@ -37,20 +38,22 @@ describe('OrganisationsEinheitFormContainerComponent', () => { describe('component', () => { describe('ngOnInit', () => { - it('should call organisationsEinheitService get', () => { + it('should call organisationsEinheitService get', (done) => { component.ngOnInit(); component.organisationsEinheitStateResource$.subscribe(() => { expect(organisationsEinheitService.get).toHaveBeenCalled(); + done(); }); }); - it('should set organisationsEinheitStateResource', () => { + it('should set organisationsEinheitStateResource', (done) => { component.ngOnInit(); component.organisationsEinheitStateResource$.subscribe( (organisationsEinheitStateResource: StateResource<AdminOrganisationsEinheitResource>) => { expect(organisationsEinheitStateResource).toEqual(organisationsEinheitStateResource); + done(); }, ); }); @@ -59,14 +62,29 @@ describe('OrganisationsEinheitFormContainerComponent', () => { describe('template', () => { describe('headline', () => { + const headline: string = getDataTestIdOf('organisations-form-container-headline'); + + it('should show headline', () => { + existsAsHtmlElement(fixture, headline); + }); + it('should show organisationsEinheit name', () => { - existsAsHtmlElement(fixture, getDataTestIdOf('organisations-form-container-headline')); + const headlineElement: HTMLElement = getElementFromFixture(fixture, headline); + + expect(headlineElement.textContent).toBe(organisationsEinheitResource.name); }); }); describe('organisationsEinheit form', () => { - it('should show organisationsEinheit form', () => { - existsAsHtmlElement(fixture, getDataTestIdOf('organisations-form')); + const form: string = getDataTestIdOf('organisations-form'); + + it('should show form', () => { + existsAsHtmlElement(fixture, form); + }); + + it('should have organisationsEinheitStateResource', () => { + const formComponent: OrganisationsEinheitFormComponent = getMockComponent(fixture, OrganisationsEinheitFormComponent); + expect(formComponent.organisationsEinheitStateResource).toBe(organisationsEinheitStateResource); }); }); }); -- GitLab