Skip to content
Snippets Groups Projects
Commit 806ef0d3 authored by OZGCloud's avatar OZGCloud
Browse files

Merge branch 'master' into OZG-7078-a11y-button-in-alfa

parents 7deaa687 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 { ...@@ -9,6 +9,7 @@ import {
notExistsAsHtmlElement, notExistsAsHtmlElement,
useFromMock, useFromMock,
} from '@alfa-client/test-utils'; } from '@alfa-client/test-utils';
import { SnackBarService } from '@alfa-client/ui';
import { VorgangWithEingangLinkRel, VorgangWithEingangResource } from '@alfa-client/vorgang-shared'; import { VorgangWithEingangLinkRel, VorgangWithEingangResource } from '@alfa-client/vorgang-shared';
import { SearchExterneFachstelleContainerComponent } from '@alfa-client/zustaendige-stelle'; import { SearchExterneFachstelleContainerComponent } from '@alfa-client/zustaendige-stelle';
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
...@@ -40,7 +41,11 @@ describe('ExterneFachstelleContainerComponent', () => { ...@@ -40,7 +41,11 @@ describe('ExterneFachstelleContainerComponent', () => {
const collaborationListResource: CollaborationListResource = createCollaborationListResource(); const collaborationListResource: CollaborationListResource = createCollaborationListResource();
beforeEach(async () => { beforeEach(async () => {
formService = new CollaborationRequestFormService(new FormBuilder(), useFromMock(mock(CollaborationService))); formService = new CollaborationRequestFormService(
new FormBuilder(),
useFromMock(mock(CollaborationService)),
useFromMock(mock(SnackBarService)),
);
service = mock(CollaborationService); service = mock(CollaborationService);
TestBed.overrideComponent(CollaborationRequestFormComponent, { TestBed.overrideComponent(CollaborationRequestFormComponent, {
set: { set: {
......
...@@ -9,6 +9,7 @@ import { ...@@ -9,6 +9,7 @@ import {
notExistsAsHtmlElement, notExistsAsHtmlElement,
useFromMock, useFromMock,
} from '@alfa-client/test-utils'; } from '@alfa-client/test-utils';
import { SnackBarService } from '@alfa-client/ui';
import { VorgangWithEingangLinkRel, VorgangWithEingangResource } from '@alfa-client/vorgang-shared'; import { VorgangWithEingangLinkRel, VorgangWithEingangResource } from '@alfa-client/vorgang-shared';
import { SearchOrganisationsEinheitContainerComponent } from '@alfa-client/zustaendige-stelle'; import { SearchOrganisationsEinheitContainerComponent } from '@alfa-client/zustaendige-stelle';
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
...@@ -40,7 +41,11 @@ describe('OrganisationsEinheitContainerComponent', () => { ...@@ -40,7 +41,11 @@ describe('OrganisationsEinheitContainerComponent', () => {
const collaborationListResource: CollaborationListResource = createCollaborationListResource(); const collaborationListResource: CollaborationListResource = createCollaborationListResource();
beforeEach(async () => { beforeEach(async () => {
formService = new CollaborationRequestFormService(new FormBuilder(), useFromMock(mock(CollaborationService))); formService = new CollaborationRequestFormService(
new FormBuilder(),
useFromMock(mock(CollaborationService)),
useFromMock(mock(SnackBarService)),
);
service = mock(CollaborationService); service = mock(CollaborationService);
TestBed.overrideComponent(CollaborationRequestFormComponent, { TestBed.overrideComponent(CollaborationRequestFormComponent, {
set: { set: {
......
...@@ -2,6 +2,7 @@ import { CollaborationListResource } from '@alfa-client/collaboration-shared'; ...@@ -2,6 +2,7 @@ import { CollaborationListResource } from '@alfa-client/collaboration-shared';
import { CommandLinkRel, CommandResource } from '@alfa-client/command-shared'; import { CommandLinkRel, CommandResource } from '@alfa-client/command-shared';
import { StateResource, createStateResource } from '@alfa-client/tech-shared'; import { StateResource, createStateResource } from '@alfa-client/tech-shared';
import { dispatchEventFromFixture, getMockComponent, mock, useFromMock } from '@alfa-client/test-utils'; import { dispatchEventFromFixture, getMockComponent, mock, useFromMock } from '@alfa-client/test-utils';
import { SnackBarService } from '@alfa-client/ui';
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormBuilder, ReactiveFormsModule } from '@angular/forms'; import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
import { ButtonWithSpinnerComponent, TextEditorComponent, TextareaEditorComponent } from '@ods/component'; import { ButtonWithSpinnerComponent, TextEditorComponent, TextareaEditorComponent } from '@ods/component';
...@@ -28,7 +29,11 @@ describe('CollaborationRequestFormComponent', () => { ...@@ -28,7 +29,11 @@ describe('CollaborationRequestFormComponent', () => {
const stateCommandResource: StateResource<CommandResource> = createStateResource(createCommandResource()); const stateCommandResource: StateResource<CommandResource> = createStateResource(createCommandResource());
beforeEach(async () => { beforeEach(async () => {
formService = new CollaborationRequestFormService(new FormBuilder(), useFromMock(mock(CollaborationService))); formService = new CollaborationRequestFormService(
new FormBuilder(),
useFromMock(mock(CollaborationService)),
useFromMock(mock(SnackBarService)),
);
TestBed.overrideComponent(CollaborationRequestFormComponent, { TestBed.overrideComponent(CollaborationRequestFormComponent, {
set: { set: {
providers: [ providers: [
...@@ -132,14 +137,6 @@ describe('CollaborationRequestFormComponent', () => { ...@@ -132,14 +137,6 @@ describe('CollaborationRequestFormComponent', () => {
expect(formService.submit).toHaveBeenCalled(); 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', () => { it('should return value', () => {
formService.submit = jest.fn().mockReturnValue(of(stateCommandResource)); formService.submit = jest.fn().mockReturnValue(of(stateCommandResource));
......
import { Collaboration, CollaborationListResource } from '@alfa-client/collaboration-shared'; import { CollaborationListResource } from '@alfa-client/collaboration-shared';
import { CommandResource, tapOnCommandSuccessfullyDone } from '@alfa-client/command-shared'; import { CommandResource } from '@alfa-client/command-shared';
import { StateResource, createEmptyStateResource } from '@alfa-client/tech-shared'; import { StateResource, createEmptyStateResource } from '@alfa-client/tech-shared';
import { Component, EventEmitter, Input, Output } from '@angular/core'; import { Component, EventEmitter, Input, Output } from '@angular/core';
import { Observable, of } from 'rxjs'; import { Observable, of } from 'rxjs';
...@@ -11,7 +11,6 @@ import { CollaborationRequestFormService } from './collaboration.request.formser ...@@ -11,7 +11,6 @@ import { CollaborationRequestFormService } from './collaboration.request.formser
}) })
export class CollaborationRequestFormComponent { export class CollaborationRequestFormComponent {
@Output() public abbrechen: EventEmitter<void> = new EventEmitter<void>(); @Output() public abbrechen: EventEmitter<void> = new EventEmitter<void>();
@Output() public showResult: EventEmitter<Collaboration> = new EventEmitter<Collaboration>();
@Input() public set collaborationListResource(collaborationListResource: CollaborationListResource) { @Input() public set collaborationListResource(collaborationListResource: CollaborationListResource) {
this.formService.setListResource(collaborationListResource); this.formService.setListResource(collaborationListResource);
...@@ -28,8 +27,6 @@ export class CollaborationRequestFormComponent { ...@@ -28,8 +27,6 @@ export class CollaborationRequestFormComponent {
} }
doSubmit(): Observable<StateResource<CommandResource>> { doSubmit(): Observable<StateResource<CommandResource>> {
return this.formService return this.formService.submit();
.submit()
.pipe(tapOnCommandSuccessfullyDone(() => this.showResult.emit(this.formService.getFormValue())));
} }
} }
import { CollaborationListResource } from '@alfa-client/collaboration-shared'; import { CollaborationListResource } from '@alfa-client/collaboration-shared';
import { CommandResource } from '@alfa-client/command-shared'; import { CommandResource } from '@alfa-client/command-shared';
import { StateResource, createStateResource } from '@alfa-client/tech-shared'; import { StateResource, createEmptyStateResource, createStateResource } from '@alfa-client/tech-shared';
import { Mock, mock, useFromMock } from '@alfa-client/test-utils'; 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 { UntypedFormBuilder } from '@angular/forms';
import { CollaborationService } from 'libs/collaboration-shared/src/lib/collaboration.service'; import { CollaborationService } from 'libs/collaboration-shared/src/lib/collaboration.service';
import { createCollaborationListResource } from 'libs/collaboration-shared/test/collaboration'; 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 { singleColdCompleted } from 'libs/tech-shared/test/marbles';
import { Observable, of } from 'rxjs'; import { Observable, of } from 'rxjs';
import { CollaborationRequestFormService } from './collaboration.request.formservice'; import { CollaborationRequestFormService } from './collaboration.request.formservice';
...@@ -14,15 +16,25 @@ describe('CollaborationRequestFormService', () => { ...@@ -14,15 +16,25 @@ describe('CollaborationRequestFormService', () => {
let formService: CollaborationRequestFormService; let formService: CollaborationRequestFormService;
let service: Mock<CollaborationService>; let service: Mock<CollaborationService>;
let snackBarService: Mock<SnackBarService>;
const formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
const collaborationListResource: CollaborationListResource = createCollaborationListResource(); const collaborationListResource: CollaborationListResource = createCollaborationListResource();
beforeEach(() => { beforeEach(() => {
service = mock(CollaborationService); 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', () => { it('should create', () => {
...@@ -57,6 +69,14 @@ describe('CollaborationRequestFormService', () => { ...@@ -57,6 +69,14 @@ describe('CollaborationRequestFormService', () => {
expect(service.create).toHaveBeenCalledWith(collaborationListResource, formService.form.value); 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', () => { it('should return stateCommandResource', () => {
const response$: Observable<StateResource<CommandResource>> = formService.submit(); const response$: Observable<StateResource<CommandResource>> = formService.submit();
...@@ -64,6 +84,41 @@ describe('CollaborationRequestFormService', () => { ...@@ -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', () => { describe('set list resource', () => {
it('should set given list resource', () => { it('should set given list resource', () => {
formService.listResource = undefined; formService.listResource = undefined;
......
import { CollaborationListResource } from '@alfa-client/collaboration-shared'; 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 { AbstractFormService, StateResource } from '@alfa-client/tech-shared';
import { SnackBarService } from '@alfa-client/ui';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { FormBuilder, FormControl, FormGroup } from '@angular/forms'; import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
import { ResourceUri } from '@ngxp/rest'; import { ResourceUri } from '@ngxp/rest';
import { CollaborationService } from 'libs/collaboration-shared/src/lib/collaboration.service'; 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() @Injectable()
export class CollaborationRequestFormService extends AbstractFormService<CommandResource> { export class CollaborationRequestFormService extends AbstractFormService<CommandResource> {
...@@ -13,6 +15,8 @@ export class CollaborationRequestFormService extends AbstractFormService<Command ...@@ -13,6 +15,8 @@ export class CollaborationRequestFormService extends AbstractFormService<Command
public static readonly FIELD_TITEL: string = 'titel'; public static readonly FIELD_TITEL: string = 'titel';
public static readonly FIELD_BESCHREIBUNG: string = 'beschreibung'; 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'; private static readonly PATH_PREFIX: string = 'command.body';
listResource: CollaborationListResource; listResource: CollaborationListResource;
...@@ -20,6 +24,7 @@ export class CollaborationRequestFormService extends AbstractFormService<Command ...@@ -20,6 +24,7 @@ export class CollaborationRequestFormService extends AbstractFormService<Command
constructor( constructor(
formBuilder: FormBuilder, formBuilder: FormBuilder,
private service: CollaborationService, private service: CollaborationService,
private snackBarService: SnackBarService,
) { ) {
super(formBuilder); super(formBuilder);
} }
...@@ -33,7 +38,23 @@ export class CollaborationRequestFormService extends AbstractFormService<Command ...@@ -33,7 +38,23 @@ export class CollaborationRequestFormService extends AbstractFormService<Command
} }
protected doSubmit(): Observable<StateResource<CommandResource>> { 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 { protected getPathPrefix(): string {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment