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 f31e92e3c557900090fce127c00d206ce8f19d51..002d809c41380f05f6e34704fef67943b671aace 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 c0854bf5313ee7fc349c7049dc8f7befe498c869..a315bac9c5d6d14c29eb3eb02963ba9157b5dc9f 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); }); }); });