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

OZG-6720 CR Kommentare

parent dc391c64
No related branches found
No related tags found
No related merge requests found
<h1 class="heading-1 pb-4">Organisationseinheiten</h1> <h1 class="heading-1 pb-4">Organisationseinheiten</h1>
<ng-container *ngIf="organisationsEinheitListStateResource$ | async as organisationsEinheitListStateResource">
<ozgcloud-spinner [stateResource]="organisationsEinheitListStateResource"/>
<admin-organisationseinheit-list <admin-organisationseinheit-list
*ngIf="organisationsEinheitResources$ | async as organisationsEinheitResources" [organisationsEinheitResources]="organisationsEinheitListStateResource.resource | toEmbeddedResources: organisationsEinheitListLinkRel.LIST"
[organisationsEinheitResources]="organisationsEinheitResources"
data-test-id="organisations-einheit-list" data-test-id="organisations-einheit-list"
/> />
</ng-container>
import { AdminOrganisationsEinheitResource, OrganisationsEinheitContainerComponent } from '@admin-client/admin-settings'; import { AdminOrganisationsEinheitListResource, OrganisationsEinheitContainerComponent } from '@admin-client/admin-settings';
import { createStateResource } from '@alfa-client/tech-shared'; import { StateResource, ToEmbeddedResourcesPipe, createStateResource } from '@alfa-client/tech-shared';
import { Mock, existsAsHtmlElement, mock } from '@alfa-client/test-utils'; import { Mock, existsAsHtmlElement, getMockComponent, mock } from '@alfa-client/test-utils';
import { SpinnerComponent } from '@alfa-client/ui';
import { OrganisationsEinheitListResource } from '@alfa-client/zustaendige-stelle-shared';
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ButtonWithSpinnerComponent } from '@ods/component'; import { ButtonWithSpinnerComponent } from '@ods/component';
import { MockComponent } from 'ng-mocks'; import { MockComponent } from 'ng-mocks';
import { Observable, of } from 'rxjs'; import { of } from 'rxjs';
import { getDataTestIdOf } from '../../../../../../tech-shared/test/data-test'; import { getDataTestIdOf } from '../../../../../../tech-shared/test/data-test';
import { import { createAdminOrganisationsEinheitListResource } from '../../../../test/organisations-einheit/organisations-einheit';
createAdminOrganisationsEinheitListResource,
createAdminOrganisationsEinheitResource,
} from '../../../../test/organisations-einheit/organisations-einheit';
import { OrganisationsEinheitService } from '../organisationseinheit.service'; import { OrganisationsEinheitService } from '../organisationseinheit.service';
import { OrganisationsEinheitListComponent } from './organisationseinheit-list/organisationseinheit-list.component'; import { OrganisationsEinheitListComponent } from './organisationseinheit-list/organisationseinheit-list.component';
...@@ -18,14 +17,21 @@ describe('OrganisationsEinheitContainerComponent', () => { ...@@ -18,14 +17,21 @@ describe('OrganisationsEinheitContainerComponent', () => {
let fixture: ComponentFixture<OrganisationsEinheitContainerComponent>; let fixture: ComponentFixture<OrganisationsEinheitContainerComponent>;
let organisationsEinheitService: Mock<OrganisationsEinheitService>; let organisationsEinheitService: Mock<OrganisationsEinheitService>;
const organisationsEinheitListStateResource: StateResource<AdminOrganisationsEinheitListResource> = createStateResource(
createAdminOrganisationsEinheitListResource(),
);
beforeEach(async () => { beforeEach(async () => {
organisationsEinheitService = mock(OrganisationsEinheitService); organisationsEinheitService = mock(OrganisationsEinheitService);
organisationsEinheitService.getList = jest organisationsEinheitService.getList = jest.fn().mockReturnValue(of(organisationsEinheitListStateResource));
.fn()
.mockReturnValue(of(createStateResource(createAdminOrganisationsEinheitListResource())));
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
declarations: [OrganisationsEinheitContainerComponent, MockComponent(OrganisationsEinheitListComponent)], declarations: [
OrganisationsEinheitContainerComponent,
MockComponent(OrganisationsEinheitListComponent),
MockComponent(SpinnerComponent),
ToEmbeddedResourcesPipe,
],
imports: [ButtonWithSpinnerComponent], imports: [ButtonWithSpinnerComponent],
providers: [{ provide: OrganisationsEinheitService, useValue: organisationsEinheitService }], providers: [{ provide: OrganisationsEinheitService, useValue: organisationsEinheitService }],
}).compileComponents(); }).compileComponents();
...@@ -41,43 +47,26 @@ describe('OrganisationsEinheitContainerComponent', () => { ...@@ -41,43 +47,26 @@ describe('OrganisationsEinheitContainerComponent', () => {
describe('component', () => { describe('component', () => {
describe('ngOnInit', () => { describe('ngOnInit', () => {
beforeEach(() => { it('should call organisationsEinheitService getList', (done) => {
component.loadOrganisationsEinheitResources = jest.fn().mockReturnValue(of([createAdminOrganisationsEinheitResource()])); component.ngOnInit();
});
it('should call loadOrganisationsEinheitResources', () => { component.organisationsEinheitListStateResource$.subscribe(() => {
component.organisationsEinheitResources$.subscribe(() => { expect(organisationsEinheitService.getList).toHaveBeenCalled();
expect(component.loadOrganisationsEinheitResources).toHaveBeenCalled(); done();
}); });
}); });
it('should set organisationsEinheitResources', () => { it('should set organisationsEinheitListStateResource$', (done) => {
component.ngOnInit(); component.ngOnInit();
component.organisationsEinheitResources$.subscribe( component.organisationsEinheitListStateResource$.subscribe(
(organisationsEinheitResources: AdminOrganisationsEinheitResource[]) => { (listStateResource: StateResource<OrganisationsEinheitListResource>) => {
expect(organisationsEinheitResources.length).toBe(1); expect(listStateResource).toBe(organisationsEinheitListStateResource);
done();
}, },
); );
}); });
}); });
describe('loadOrganisationsEinheitResources', () => {
it('should call organisationsEinheitService getList', () => {
component.loadOrganisationsEinheitResources();
expect(organisationsEinheitService.getList).toHaveBeenCalled();
});
it('should set organisationsEinheitResources', () => {
const organisationsEinheitResources$: Observable<AdminOrganisationsEinheitResource[]> =
component.loadOrganisationsEinheitResources();
organisationsEinheitResources$.subscribe((organisationsEinheitResources: AdminOrganisationsEinheitResource[]) => {
expect(organisationsEinheitResources.length).toBe(1);
});
});
});
}); });
describe('template', () => { describe('template', () => {
...@@ -87,6 +76,11 @@ describe('OrganisationsEinheitContainerComponent', () => { ...@@ -87,6 +76,11 @@ describe('OrganisationsEinheitContainerComponent', () => {
it('should show list', () => { it('should show list', () => {
existsAsHtmlElement(fixture, listSelector); existsAsHtmlElement(fixture, listSelector);
}); });
it('should have organisationsEinheitResources', () => {
const listComponent: OrganisationsEinheitListComponent = getMockComponent(fixture, OrganisationsEinheitListComponent);
expect(listComponent.organisationsEinheitResources).toBeTruthy();
});
}); });
}); });
}); });
import { getEmbeddedResources, StateResource } from '@alfa-client/tech-shared'; import { StateResource } from '@alfa-client/tech-shared';
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { map, Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { OrganisationsEinheitListLinkRel } from '../organisations-einheit.linkrel'; import { OrganisationsEinheitListLinkRel } from '../organisations-einheit.linkrel';
import { AdminOrganisationsEinheitListResource, AdminOrganisationsEinheitResource } from '../organisations-einheit.model'; import { AdminOrganisationsEinheitListResource } from '../organisations-einheit.model';
import { OrganisationsEinheitService } from '../organisationseinheit.service'; import { OrganisationsEinheitService } from '../organisationseinheit.service';
@Component({ @Component({
...@@ -10,24 +10,13 @@ import { OrganisationsEinheitService } from '../organisationseinheit.service'; ...@@ -10,24 +10,13 @@ import { OrganisationsEinheitService } from '../organisationseinheit.service';
templateUrl: './organisationseinheit-container.component.html', templateUrl: './organisationseinheit-container.component.html',
}) })
export class OrganisationsEinheitContainerComponent implements OnInit { export class OrganisationsEinheitContainerComponent implements OnInit {
organisationsEinheitResources$: Observable<AdminOrganisationsEinheitResource[]>; organisationsEinheitListStateResource$: Observable<StateResource<AdminOrganisationsEinheitListResource>>;
constructor(private organisationsEinheitService: OrganisationsEinheitService) {} constructor(private organisationsEinheitService: OrganisationsEinheitService) {}
ngOnInit(): void { ngOnInit(): void {
this.organisationsEinheitResources$ = this.loadOrganisationsEinheitResources(); this.organisationsEinheitListStateResource$ = this.organisationsEinheitService.getList();
} }
loadOrganisationsEinheitResources(): Observable<AdminOrganisationsEinheitResource[]> { protected readonly organisationsEinheitListLinkRel = OrganisationsEinheitListLinkRel;
return this.organisationsEinheitService
.getList()
.pipe(
map((organisationsEinheitListResource: StateResource<AdminOrganisationsEinheitListResource>) =>
getEmbeddedResources<AdminOrganisationsEinheitResource>(
organisationsEinheitListResource,
OrganisationsEinheitListLinkRel.LIST,
),
),
);
}
} }
...@@ -102,7 +102,7 @@ describe('OrganisationsEinheitFormComponent', () => { ...@@ -102,7 +102,7 @@ describe('OrganisationsEinheitFormComponent', () => {
describe('invalid message', () => { describe('invalid message', () => {
const invalidMessageSpanSelector: string = getDataTestIdOf('invalid-empty-message-span'); const invalidMessageSpanSelector: string = getDataTestIdOf('invalid-empty-message-span');
it('should show if form invalidEmpty', () => { it('should show if form is invalid', () => {
const problemDetail: ProblemDetail = { const problemDetail: ProblemDetail = {
...createProblemDetail(), ...createProblemDetail(),
invalidParams: [{ ...createInvalidParam(), name: 'settingBody.signatur' }], invalidParams: [{ ...createInvalidParam(), name: 'settingBody.signatur' }],
......
import { import { createEmptyStateResource, createStateResource, ProblemDetail } from '@alfa-client/tech-shared';
createEmptyStateResource, import { dispatchEventFromFixture, existsAsHtmlElement, Mock, mock, notExistsAsHtmlElement } from '@alfa-client/test-utils';
createStateResource,
ProblemDetail,
} from '@alfa-client/tech-shared';
import {
dispatchEventFromFixture,
existsAsHtmlElement,
Mock,
mock,
notExistsAsHtmlElement,
} from '@alfa-client/test-utils';
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ButtonWithSpinnerComponent } from '@ods/component'; import { ButtonWithSpinnerComponent } from '@ods/component';
...@@ -67,10 +57,7 @@ describe('PostfachFormComponent', () => { ...@@ -67,10 +57,7 @@ describe('PostfachFormComponent', () => {
describe('set postfachStateResource', () => { describe('set postfachStateResource', () => {
it('should return resource', () => { it('should return resource', () => {
const updatePostfachResourceFn: jest.SpyInstance = jest.spyOn( const updatePostfachResourceFn: jest.SpyInstance = jest.spyOn(component, 'updatePostfachResource');
component,
'updatePostfachResource',
);
const postfachResource: PostfachResource = createPostfachResource(); const postfachResource: PostfachResource = createPostfachResource();
component.postfachStateResource = createStateResource(postfachResource); component.postfachStateResource = createStateResource(postfachResource);
...@@ -152,7 +139,7 @@ describe('PostfachFormComponent', () => { ...@@ -152,7 +139,7 @@ describe('PostfachFormComponent', () => {
}); });
describe('invalid message', () => { describe('invalid message', () => {
it('should show if form invalidEmpty', () => { it('should show if form is invalid', () => {
formService.setErrorByProblemDetail(createProblemDetailForAbsenderName()); formService.setErrorByProblemDetail(createProblemDetailForAbsenderName());
fixture.detectChanges(); fixture.detectChanges();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment