Skip to content
Snippets Groups Projects
Commit 9dbb5a54 authored by OZGCloud's avatar OZGCloud
Browse files

Merge branch 'master' into OZG-7021-static-sites-app

parents cbca3c76 61f40f69
No related branches found
No related tags found
No related merge requests found
Showing with 106 additions and 26 deletions
......@@ -9,6 +9,7 @@ import {
notExistsAsHtmlElement,
useFromMock,
} from '@alfa-client/test-utils';
import { SnackBarService } from '@alfa-client/ui';
import { VorgangWithEingangLinkRel, VorgangWithEingangResource } from '@alfa-client/vorgang-shared';
import { SearchExterneFachstelleContainerComponent } from '@alfa-client/zustaendige-stelle';
import { ComponentFixture, TestBed } from '@angular/core/testing';
......@@ -40,7 +41,11 @@ describe('ExterneFachstelleContainerComponent', () => {
const collaborationListResource: CollaborationListResource = createCollaborationListResource();
beforeEach(async () => {
formService = new CollaborationRequestFormService(new FormBuilder(), useFromMock(mock(CollaborationService)));
formService = new CollaborationRequestFormService(
new FormBuilder(),
useFromMock(mock(CollaborationService)),
useFromMock(mock(SnackBarService)),
);
service = mock(CollaborationService);
TestBed.overrideComponent(CollaborationRequestFormComponent, {
set: {
......
......@@ -9,6 +9,7 @@ import {
notExistsAsHtmlElement,
useFromMock,
} from '@alfa-client/test-utils';
import { SnackBarService } from '@alfa-client/ui';
import { VorgangWithEingangLinkRel, VorgangWithEingangResource } from '@alfa-client/vorgang-shared';
import { SearchOrganisationsEinheitContainerComponent } from '@alfa-client/zustaendige-stelle';
import { ComponentFixture, TestBed } from '@angular/core/testing';
......@@ -40,7 +41,11 @@ describe('OrganisationsEinheitContainerComponent', () => {
const collaborationListResource: CollaborationListResource = createCollaborationListResource();
beforeEach(async () => {
formService = new CollaborationRequestFormService(new FormBuilder(), useFromMock(mock(CollaborationService)));
formService = new CollaborationRequestFormService(
new FormBuilder(),
useFromMock(mock(CollaborationService)),
useFromMock(mock(SnackBarService)),
);
service = mock(CollaborationService);
TestBed.overrideComponent(CollaborationRequestFormComponent, {
set: {
......
......@@ -2,6 +2,7 @@ import { CollaborationListResource } from '@alfa-client/collaboration-shared';
import { CommandLinkRel, CommandResource } from '@alfa-client/command-shared';
import { StateResource, createStateResource } from '@alfa-client/tech-shared';
import { dispatchEventFromFixture, getMockComponent, mock, useFromMock } from '@alfa-client/test-utils';
import { SnackBarService } from '@alfa-client/ui';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
import { ButtonWithSpinnerComponent, TextEditorComponent, TextareaEditorComponent } from '@ods/component';
......@@ -28,7 +29,11 @@ describe('CollaborationRequestFormComponent', () => {
const stateCommandResource: StateResource<CommandResource> = createStateResource(createCommandResource());
beforeEach(async () => {
formService = new CollaborationRequestFormService(new FormBuilder(), useFromMock(mock(CollaborationService)));
formService = new CollaborationRequestFormService(
new FormBuilder(),
useFromMock(mock(CollaborationService)),
useFromMock(mock(SnackBarService)),
);
TestBed.overrideComponent(CollaborationRequestFormComponent, {
set: {
providers: [
......@@ -132,14 +137,6 @@ describe('CollaborationRequestFormComponent', () => {
expect(formService.submit).toHaveBeenCalled();
});
it('should emit show result', () => {
component.showResult.emit = jest.fn();
component.doSubmit().subscribe();
expect(component.showResult.emit).toHaveBeenCalledWith(formService.form.value);
});
it('should return value', () => {
formService.submit = jest.fn().mockReturnValue(of(stateCommandResource));
......
import { Collaboration, CollaborationListResource } from '@alfa-client/collaboration-shared';
import { CommandResource, tapOnCommandSuccessfullyDone } from '@alfa-client/command-shared';
import { CollaborationListResource } from '@alfa-client/collaboration-shared';
import { CommandResource } from '@alfa-client/command-shared';
import { StateResource, createEmptyStateResource } from '@alfa-client/tech-shared';
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { Observable, of } from 'rxjs';
......@@ -11,7 +11,6 @@ import { CollaborationRequestFormService } from './collaboration.request.formser
})
export class CollaborationRequestFormComponent {
@Output() public abbrechen: EventEmitter<void> = new EventEmitter<void>();
@Output() public showResult: EventEmitter<Collaboration> = new EventEmitter<Collaboration>();
@Input() public set collaborationListResource(collaborationListResource: CollaborationListResource) {
this.formService.setListResource(collaborationListResource);
......@@ -28,8 +27,6 @@ export class CollaborationRequestFormComponent {
}
doSubmit(): Observable<StateResource<CommandResource>> {
return this.formService
.submit()
.pipe(tapOnCommandSuccessfullyDone(() => this.showResult.emit(this.formService.getFormValue())));
return this.formService.submit();
}
}
import { CollaborationListResource } from '@alfa-client/collaboration-shared';
import { CommandResource } from '@alfa-client/command-shared';
import { StateResource, createStateResource } from '@alfa-client/tech-shared';
import { Mock, mock, useFromMock } from '@alfa-client/test-utils';
import { StateResource, createEmptyStateResource, createStateResource } from '@alfa-client/tech-shared';
import { Mock, mock } from '@alfa-client/test-utils';
import { SnackBarService } from '@alfa-client/ui';
import { TestBed } from '@angular/core/testing';
import { UntypedFormBuilder } from '@angular/forms';
import { CollaborationService } from 'libs/collaboration-shared/src/lib/collaboration.service';
import { createCollaborationListResource } from 'libs/collaboration-shared/test/collaboration';
import { createCommandResource } from 'libs/command-shared/test/command';
import { createCommandErrorResource, createCommandResource } from 'libs/command-shared/test/command';
import { singleColdCompleted } from 'libs/tech-shared/test/marbles';
import { Observable, of } from 'rxjs';
import { CollaborationRequestFormService } from './collaboration.request.formservice';
......@@ -14,15 +16,25 @@ describe('CollaborationRequestFormService', () => {
let formService: CollaborationRequestFormService;
let service: Mock<CollaborationService>;
const formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
let snackBarService: Mock<SnackBarService>;
const collaborationListResource: CollaborationListResource = createCollaborationListResource();
beforeEach(() => {
service = mock(CollaborationService);
snackBarService = mock(SnackBarService);
TestBed.configureTestingModule({
providers: [
CollaborationRequestFormService,
UntypedFormBuilder,
{ provide: CollaborationService, useValue: service },
{ provide: SnackBarService, useValue: snackBarService },
],
});
formService = new CollaborationRequestFormService(formBuilder, useFromMock(service));
formService = TestBed.inject(CollaborationRequestFormService);
TestBed.inject(CollaborationRequestFormService);
});
it('should create', () => {
......@@ -57,6 +69,14 @@ describe('CollaborationRequestFormService', () => {
expect(service.create).toHaveBeenCalledWith(collaborationListResource, formService.form.value);
});
it('should call handleCommandError', () => {
const handleCommanErrorSpy = jest.spyOn(formService as any, 'handleCommandError');
formService.submit().subscribe();
expect(handleCommanErrorSpy).toHaveBeenCalledWith(stateCommandResource.resource);
});
it('should return stateCommandResource', () => {
const response$: Observable<StateResource<CommandResource>> = formService.submit();
......@@ -64,6 +84,41 @@ describe('CollaborationRequestFormService', () => {
});
});
describe('handleCommandError', () => {
let showErrorSpy: jest.SpyInstance;
beforeEach(() => {
showErrorSpy = jest.spyOn(formService as any, 'showError');
});
it('should not do anything if commandResource is nil', () => {
service.create.mockReturnValue(of(createEmptyStateResource()));
formService.submit().subscribe();
expect(showErrorSpy).not.toHaveBeenCalled();
});
it('should call showError if commandResource has error', () => {
service.create.mockReturnValue(of(createStateResource(createCommandErrorResource())));
formService.submit().subscribe();
expect(showErrorSpy).toHaveBeenCalled();
});
});
describe('showError', () => {
it('should call snackBarService.showError with commandResource errorMessage', () => {
const commandResourceWithError: CommandResource = createCommandErrorResource();
service.create.mockReturnValue(of(createStateResource(commandResourceWithError)));
formService.submit().subscribe();
expect(snackBarService.showError).toHaveBeenCalledWith(CollaborationRequestFormService.GENERIC_ERROR_MESSAGE);
});
});
describe('set list resource', () => {
it('should set given list resource', () => {
formService.listResource = undefined;
......
import { CollaborationListResource } from '@alfa-client/collaboration-shared';
import { CommandResource } from '@alfa-client/command-shared';
import { CommandResource, hasCommandError } from '@alfa-client/command-shared';
import { AbstractFormService, StateResource } from '@alfa-client/tech-shared';
import { SnackBarService } from '@alfa-client/ui';
import { Injectable } from '@angular/core';
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
import { ResourceUri } from '@ngxp/rest';
import { CollaborationService } from 'libs/collaboration-shared/src/lib/collaboration.service';
import { Observable } from 'rxjs';
import { isNil } from 'lodash-es';
import { Observable, tap } from 'rxjs';
@Injectable()
export class CollaborationRequestFormService extends AbstractFormService<CommandResource> {
......@@ -13,6 +15,8 @@ export class CollaborationRequestFormService extends AbstractFormService<Command
public static readonly FIELD_TITEL: string = 'titel';
public static readonly FIELD_BESCHREIBUNG: string = 'beschreibung';
public static readonly GENERIC_ERROR_MESSAGE: string = 'Zuarbeit konnte nicht angefragt werden';
private static readonly PATH_PREFIX: string = 'command.body';
listResource: CollaborationListResource;
......@@ -20,6 +24,7 @@ export class CollaborationRequestFormService extends AbstractFormService<Command
constructor(
formBuilder: FormBuilder,
private service: CollaborationService,
private snackBarService: SnackBarService,
) {
super(formBuilder);
}
......@@ -33,7 +38,23 @@ export class CollaborationRequestFormService extends AbstractFormService<Command
}
protected doSubmit(): Observable<StateResource<CommandResource>> {
return this.service.create(this.listResource, this.getFormValue());
return this.service.create(this.listResource, this.getFormValue()).pipe(
tap((commandStateResource: StateResource<CommandResource>) => {
this.handleCommandError(commandStateResource.resource);
}),
);
}
protected handleCommandError(commandResource: CommandResource): void {
if (isNil(commandResource)) return;
if (hasCommandError(commandResource)) {
this.showError();
}
}
protected showError(): void {
this.snackBarService.showError(CollaborationRequestFormService.GENERIC_ERROR_MESSAGE);
}
protected getPathPrefix(): string {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment