Skip to content
Snippets Groups Projects
Commit 2c228c30 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-6720 CR Kommentare

parent 14535461
No related branches found
No related tags found
No related merge requests found
Showing
with 52 additions and 50 deletions
......@@ -21,9 +21,13 @@ describe('OrganisationsEinheitContainerComponent', () => {
createAdminOrganisationsEinheitListResource(),
);
const listSelector: string = getDataTestIdOf('organisations-einheit-list');
beforeEach(async () => {
organisationsEinheitService = mock(OrganisationsEinheitService);
organisationsEinheitService.getList = jest.fn().mockReturnValue(of(organisationsEinheitListStateResource));
organisationsEinheitService = {
...mock(OrganisationsEinheitService),
getList: jest.fn().mockReturnValue(of(organisationsEinheitListStateResource)),
};
await TestBed.configureTestingModule({
declarations: [
......@@ -71,8 +75,6 @@ describe('OrganisationsEinheitContainerComponent', () => {
describe('template', () => {
describe('organisationsEinheiten list', () => {
const listSelector: string = getDataTestIdOf('organisations-einheit-list');
it('should show list', () => {
existsAsHtmlElement(fixture, listSelector);
});
......
......@@ -12,11 +12,11 @@ import { OrganisationsEinheitService } from '../organisationseinheit.service';
export class OrganisationsEinheitContainerComponent implements OnInit {
organisationsEinheitListStateResource$: Observable<StateResource<AdminOrganisationsEinheitListResource>>;
public readonly organisationsEinheitListLinkRel = OrganisationsEinheitListLinkRel;
constructor(private organisationsEinheitService: OrganisationsEinheitService) {}
ngOnInit(): void {
this.organisationsEinheitListStateResource$ = this.organisationsEinheitService.getList();
}
public readonly organisationsEinheitListLinkRel = OrganisationsEinheitListLinkRel;
}
<ods-list *ngIf="organisationsEinheitResources.length > 0" data-test-id="organisations-einheit-list">
<ods-list-item
*ngFor="let organisationsEinheitResource of organisationsEinheitResources"
[routerLink]="organisationsEinheitResource | toResourceUri: OrganisationsEinheitLinkRel.SELF"
[routerLink]="organisationsEinheitResource | toResourceUri"
[class.text-red-500]="
organisationsEinheitResource.syncResult === AdminOrganisationsEinheitSyncResult.NOT_FOUND_IN_PVOG ||
organisationsEinheitResource.syncResult === AdminOrganisationsEinheitSyncResult.ORGANISATIONSEINHEIT_ID_NOT_UNIQUE
......
......@@ -3,6 +3,7 @@ import { ConvertForDataTestPipe, ToResourceUriPipe } from '@alfa-client/tech-sha
import {
existsAsHtmlElement,
getElementFromFixture,
getElementFromFixtureByType,
getElementsFromFixture,
mock,
notExistsAsHtmlElement,
......@@ -22,9 +23,13 @@ describe('OrganisationsEinheitListComponent', () => {
const listSelector: string = getDataTestIdOf('organisations-einheit-list');
const listItemSelector: string = getDataTestIdOf('organisations-einheit-list-item');
const organisationsEinheitNameSelector: string = getDataTestIdOf('organisations-einheit-name');
const organisationsEinheitIdSelector: string = getDataTestIdOf('organisations-einheit-id');
const organisationsEinheitResource: AdminOrganisationsEinheitResource = createAdminOrganisationsEinheitResource();
organisationsEinheitResource.syncResult = AdminOrganisationsEinheitSyncResult.NOT_FOUND_IN_PVOG;
const organisationsEinheitResource: AdminOrganisationsEinheitResource = {
...createAdminOrganisationsEinheitResource(),
syncResult: AdminOrganisationsEinheitSyncResult.NOT_FOUND_IN_PVOG,
};
beforeEach(async () => {
await TestBed.configureTestingModule({
......@@ -49,30 +54,26 @@ describe('OrganisationsEinheitListComponent', () => {
describe('input', () => {
describe('organisationsEinheitResources', () => {
let listItemElement: HTMLElement;
let nameElement: Element;
let idElement: Element;
let iconElement: Element;
beforeEach(() => {
component.organisationsEinheitResources = [organisationsEinheitResource];
fixture.detectChanges();
listItemElement = getElementFromFixture(fixture, listItemSelector);
nameElement = listItemElement.querySelector('[data-test-id="organisations-einheit-name"]');
idElement = listItemElement.querySelector('[data-test-id="organisations-einheit-id"]');
iconElement = listItemElement.querySelector('ods-exclamation-icon');
});
it('should set organisationsEinheitResource name', () => {
const nameElement: HTMLElement = getElementFromFixture(fixture, organisationsEinheitNameSelector);
expect(nameElement.textContent).toBe(organisationsEinheitResource.name);
});
it('should set organisationsEinheitResource organisationsEinheitId', () => {
const idElement: HTMLElement = getElementFromFixture(fixture, organisationsEinheitIdSelector);
expect(idElement.textContent).toBe(organisationsEinheitResource.organisationsEinheitId);
});
it('should set exclamation icon', () => {
const iconElement: ExclamationIconComponent = getElementFromFixtureByType(fixture, ExclamationIconComponent);
expect(iconElement).toBeTruthy();
});
});
......
import { AdminOrganisationsEinheitResource, AdminOrganisationsEinheitSyncResult } from '@admin-client/admin-settings';
import { Component, Input } from '@angular/core';
import { OrganisationsEinheitLinkRel } from '../../organisations-einheit.linkrel';
@Component({
selector: 'admin-organisationseinheit-list',
......@@ -18,6 +17,8 @@ export class OrganisationsEinheitListComponent {
this.moveChildrenIntoParentLevel(list);
}
public readonly AdminOrganisationsEinheitSyncResult = AdminOrganisationsEinheitSyncResult;
moveChildrenIntoParentLevel(list: AdminOrganisationsEinheitResource[]): void {
list.forEach((parent: AdminOrganisationsEinheitResource) => {
this._organisationsEinheitResources.push(parent);
......@@ -30,7 +31,4 @@ export class OrganisationsEinheitListComponent {
}
});
}
public readonly AdminOrganisationsEinheitSyncResult = AdminOrganisationsEinheitSyncResult;
public readonly OrganisationsEinheitLinkRel = OrganisationsEinheitLinkRel;
}
......@@ -18,9 +18,14 @@ describe('OrganisationsEinheitFormContainerComponent', () => {
const organisationsEinheitStateResource: StateResource<AdminOrganisationsEinheitResource> =
createStateResource(organisationsEinheitResource);
const headlineSelector: string = getDataTestIdOf('organisations-form-container-headline');
const formSelector: string = getDataTestIdOf('organisations-form');
beforeEach(async () => {
organisationsEinheitService = mock(OrganisationsEinheitService);
organisationsEinheitService.get = jest.fn().mockReturnValue(of(organisationsEinheitStateResource));
organisationsEinheitService = {
...mock(OrganisationsEinheitService),
get: jest.fn().mockReturnValue(of(organisationsEinheitStateResource)),
};
await TestBed.configureTestingModule({
declarations: [OrganisationsEinheitFormContainerComponent, MockComponent(OrganisationsEinheitFormComponent)],
......@@ -62,8 +67,6 @@ describe('OrganisationsEinheitFormContainerComponent', () => {
describe('template', () => {
describe('headline', () => {
const headlineSelector: string = getDataTestIdOf('organisations-form-container-headline');
it('should show headline', () => {
existsAsHtmlElement(fixture, headlineSelector);
});
......@@ -76,8 +79,6 @@ describe('OrganisationsEinheitFormContainerComponent', () => {
});
describe('organisationsEinheit form', () => {
const formSelector: string = getDataTestIdOf('organisations-form');
it('should show form', () => {
existsAsHtmlElement(fixture, formSelector);
});
......
......@@ -21,6 +21,10 @@ describe('OrganisationsEinheitFormComponent', () => {
let formService: OrganisationsEinheitFormService;
let organisationsEinheitService: Mock<OrganisationsEinheitService>;
const signaturComponentSelector: string = getDataTestIdOf('organisations-einheit-signatur-component');
const saveButtonSelector: string = getDataTestIdOf('save-button');
const invalidMessageSpanSelector: string = getDataTestIdOf('invalid-empty-message-span');
beforeEach(async () => {
organisationsEinheitService = mock(OrganisationsEinheitService);
......@@ -84,24 +88,18 @@ describe('OrganisationsEinheitFormComponent', () => {
describe('template', () => {
describe('organisationsEinheit signatur component', () => {
const signaturComponentSelector: string = getDataTestIdOf('organisations-einheit-signatur-component');
it('should show signatur component', () => {
existsAsHtmlElement(fixture, signaturComponentSelector);
});
});
describe('save button', () => {
const saveButtonSelector: string = getDataTestIdOf('save-button');
it('should show save button', () => {
existsAsHtmlElement(fixture, saveButtonSelector);
});
});
describe('invalid message', () => {
const invalidMessageSpanSelector: string = getDataTestIdOf('invalid-empty-message-span');
it('should show if form is invalid', () => {
const problemDetail: ProblemDetail = {
...createProblemDetail(),
......
......@@ -16,6 +16,8 @@ describe('OrganisationsEinheitSignaturComponent', () => {
let fixture: ComponentFixture<OrganisationsEinheitSignaturComponent>;
let formService: OrganisationsEinheitFormService;
const signaturTextareaSelector: string = getDataTestIdOf('signatur-text');
beforeEach(async () => {
formService = new OrganisationsEinheitFormService(new FormBuilder(), useFromMock(mock(OrganisationsEinheitService)));
......@@ -42,8 +44,6 @@ describe('OrganisationsEinheitSignaturComponent', () => {
describe('template', () => {
describe('ods-textarea-editor', () => {
describe('input', () => {
const signaturTextareaSelector: string = getDataTestIdOf('signatur-text');
it('should set signatur field', () => {
const textAreaEditor: HTMLElement = getElementFromFixture(fixture, signaturTextareaSelector);
......
......@@ -57,12 +57,12 @@ describe('PostfachFormComponent', () => {
describe('set postfachStateResource', () => {
it('should return resource', () => {
const updatePostfachResourceFn: jest.SpyInstance = jest.spyOn(component, 'updatePostfachResource');
const postfachResource: PostfachResource = createPostfachResource();
component.updatePostfachResource = jest.fn();
const postfachResource: PostfachResource = createPostfachResource();
component.postfachStateResource = createStateResource(postfachResource);
expect(updatePostfachResourceFn).toHaveBeenCalledWith(postfachResource);
expect(component.updatePostfachResource).toHaveBeenCalledWith(postfachResource);
});
});
......
......@@ -120,19 +120,17 @@ export abstract class ResourceService<B extends Resource, T extends Resource> {
}
public save(toSave: unknown): Observable<StateResource<T>> {
return this.persist(this.doSave.bind(this), toSave);
const previousResource: T = this.stateResource.value.resource;
return this.handleSave(this.doSave(previousResource, toSave));
}
public patch(toPatch: unknown): Observable<StateResource<T>> {
return this.persist(this.doPatch.bind(this), toPatch);
const previousResource: T = this.stateResource.value.resource;
return this.handleSave(this.doPatch(previousResource, toPatch));
}
private persist(
action: (previousResource: T, payload: unknown) => Observable<T>,
payload: unknown,
): Observable<StateResource<T>> {
const previousResource: T = this.stateResource.value.resource;
return action(previousResource, payload).pipe(
private handleSave(response$: Observable<T>): Observable<StateResource<T>> {
return response$.pipe(
tap((loadedResource: T) => this.stateResource.next(createStateResource(loadedResource))),
map(() => this.stateResource.value),
catchError((errorResponse: HttpErrorResponse) => this.handleError(errorResponse)),
......
......@@ -167,13 +167,17 @@ describe('AbstractFormService', () => {
describe('isInvalid', () => {
it('should return false on valid state', () => {
expect(formService.isInvalid()).toBeFalsy();
const isInvalid: boolean = formService.isInvalid();
expect(isInvalid).toBeFalsy();
});
it('should return true on invalid state', () => {
formService.form.controls[TestFormService.FIELD].setErrors({ required: true });
expect(formService.isInvalid()).toBeTruthy();
const isInvalid: boolean = formService.isInvalid();
expect(isInvalid).toBeTruthy();
});
});
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment