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