diff --git a/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog-container.component.html b/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog-container.component.html index ad97972cd9cc4c7e7f135d96b2b755378f953b3e..e6c65fbf4d123859056d2b834c6b45107a620683 100644 --- a/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog-container.component.html +++ b/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog-container.component.html @@ -1 +1,6 @@ -<alfa-forwarding-dialog [selectedSearchResult]="selectedSearchResult$ | async" data-test-id="forwarding-dialog"/> \ No newline at end of file +<alfa-forwarding-dialog + [forwardCommandStateResource]="forwardCommandStateResource$ | async" + [selectedSearchResult]="selectedSearchResult$ | async" + (forward)="forward($event)" + data-test-id="forwarding-dialog" +/> diff --git a/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog-container.component.spec.ts b/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog-container.component.spec.ts index 355c614cc694333be2f34a629eac5ad5b527035e..8f0eaf9a6ed73b41bc8b87d887144a4b5bedfc8e 100644 --- a/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog-container.component.spec.ts +++ b/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog-container.component.spec.ts @@ -1,9 +1,18 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; - -import { mock, Mock } from '@alfa-client/test-utils'; +import { CommandLinkRel, CommandResource } from '@alfa-client/command-shared'; +import { ForwardingService } from '@alfa-client/forwarding-shared'; +import { StateResource } from '@alfa-client/tech-shared'; +import { mock, Mock, triggerEvent } from '@alfa-client/test-utils'; +import { OzgcloudDialogService } from '@alfa-client/ui'; import { OrganisationsEinheitService, ZUSTAENDIGE_STELLE_SERVICE } from '@alfa-client/zustaendige-stelle-shared'; import { AsyncPipe } from '@angular/common'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { faker } from '@faker-js/faker/.'; +import { ResourceUri } from '@ngxp/rest'; +import { createCommandStateResource } from 'libs/command-shared/test/command'; +import { getDataTestIdOf } from 'libs/tech-shared/test/data-test'; +import { singleColdCompleted } from 'libs/tech-shared/test/marbles'; import { MockComponent } from 'ng-mocks'; +import { of } from 'rxjs'; import { ForwardingDialogContainerComponent } from './forwarding-dialog-container.component'; import { ForwardingDialogComponent } from './forwarding-dialog/forwarding-dialog.component'; @@ -11,14 +20,30 @@ describe('ForwardingDialogContainerComponent', () => { let component: ForwardingDialogContainerComponent; let fixture: ComponentFixture<ForwardingDialogContainerComponent>; + const forwardingDialog: string = getDataTestIdOf('forwarding-dialog'); + + let service: Mock<ForwardingService>; let organisationsEinheitService: Mock<OrganisationsEinheitService>; + let dialogService: Mock<OzgcloudDialogService>; beforeEach(async () => { + service = mock(ForwardingService); organisationsEinheitService = mock(OrganisationsEinheitService); + dialogService = mock(OzgcloudDialogService); await TestBed.configureTestingModule({ imports: [ForwardingDialogContainerComponent, AsyncPipe], declarations: [MockComponent(ForwardingDialogComponent)], + providers: [ + { + provide: ForwardingService, + useValue: service, + }, + { + provide: OzgcloudDialogService, + useValue: dialogService, + }, + ], }) .overrideComponent(ForwardingDialogContainerComponent, { set: { @@ -40,4 +65,45 @@ describe('ForwardingDialogContainerComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); + + describe('forward button', () => { + const forwardingToUri: ResourceUri = faker.internet.url(); + + it('should call forward on click', () => { + component.forward = jest.fn(); + + triggerEvent({ fixture, elementSelector: forwardingDialog, name: 'forward', data: forwardingToUri }); + + expect(component.forward).toHaveBeenCalledWith(forwardingToUri); + }); + }); + + describe('forward', () => { + const forwardingToUri: ResourceUri = faker.internet.url(); + + const commandStateResource: StateResource<CommandResource> = createCommandStateResource([CommandLinkRel.EFFECTED_RESOURCE]); + + beforeEach(() => { + service.forward.mockReturnValue(of(commandStateResource)); + }); + + it('should call service with uri', () => { + component.forward(forwardingToUri); + + expect(service.forward).toHaveBeenCalledWith(forwardingToUri); + }); + + it('should set service response', () => { + component.forward(forwardingToUri); + + expect(component.forwardCommandStateResource$).toBeObservable(singleColdCompleted(commandStateResource)); + }); + + it('should call dialog service to close all if command is done', () => { + component.forward(forwardingToUri); + component.forwardCommandStateResource$.subscribe(); + + expect(dialogService.closeAll).toHaveBeenCalled(); + }); + }); }); diff --git a/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog-container.component.ts b/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog-container.component.ts index afb2a3d5a97213615dcc22a98195e82fd916ed50..4d7dd45c19b2469a8540eb705ac870a374722ba7 100644 --- a/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog-container.component.ts +++ b/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog-container.component.ts @@ -1,4 +1,7 @@ -import { ResourceRepository } from '@alfa-client/tech-shared'; +import { CommandResource, tapOnCommandSuccessfullyDone } from '@alfa-client/command-shared'; +import { ForwardingService } from '@alfa-client/forwarding-shared'; +import { createEmptyStateResource, ResourceRepository, StateResource } from '@alfa-client/tech-shared'; +import { OzgcloudDialogService } from '@alfa-client/ui'; import { VorgangService } from '@alfa-client/vorgang-shared'; import { createOrganisationEinheitService } from '@alfa-client/zustaendige-stelle'; import { @@ -6,15 +9,16 @@ import { OrganisationsEinheitService, ZUSTAENDIGE_STELLE_SERVICE, } from '@alfa-client/zustaendige-stelle-shared'; -import { AsyncPipe } from '@angular/common'; +import { AsyncPipe, CommonModule } from '@angular/common'; import { Component, inject, OnInit } from '@angular/core'; -import { Observable } from 'rxjs'; +import { ResourceUri } from '@ngxp/rest'; +import { Observable, of } from 'rxjs'; import { ForwardingDialogComponent } from './forwarding-dialog/forwarding-dialog.component'; @Component({ selector: 'alfa-forwarding-dialog-container', standalone: true, - imports: [ForwardingDialogComponent, AsyncPipe], + imports: [ForwardingDialogComponent, AsyncPipe, CommonModule], templateUrl: './forwarding-dialog-container.component.html', providers: [ { @@ -26,10 +30,22 @@ import { ForwardingDialogComponent } from './forwarding-dialog/forwarding-dialog }) export class ForwardingDialogContainerComponent implements OnInit { private readonly organisationsEinheitService = inject(ZUSTAENDIGE_STELLE_SERVICE) as OrganisationsEinheitService; + private readonly forwardingService = inject(ForwardingService); + private readonly dialogService = inject(OzgcloudDialogService); public selectedSearchResult$: Observable<OrganisationsEinheitResource>; + public forwardCommandStateResource$: Observable<StateResource<CommandResource>> = + of(createEmptyStateResource<CommandResource>()); ngOnInit(): void { this.selectedSearchResult$ = this.organisationsEinheitService.getSelectedResult(); } + + public forward(forwardingToUri: ResourceUri): void { + this.forwardCommandStateResource$ = this.forwardingService.forward(forwardingToUri).pipe( + tapOnCommandSuccessfullyDone(() => { + this.dialogService.closeAll(); + }), + ); + } } diff --git a/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog/forwarding-button/forwarding-button.component.html b/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog/forwarding-button/forwarding-button.component.html index d0dd3c9c055bfc74030ddd0a0c19ddacafa8976b..1b36245dd262eb85c56fa35d29ba8f4bf1ba53d4 100644 --- a/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog/forwarding-button/forwarding-button.component.html +++ b/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog/forwarding-button/forwarding-button.component.html @@ -1,3 +1,11 @@ -<ods-button-with-spinner [disabled]="disabled" text="Weiterleiten" variant="outline" dataTestId="forwarding-button"> +<ods-button-with-spinner + [stateResource]="stateResource" + [disabled]="disabled" + (clickEmitter)="clickEmitter.emit()" + text="Weiterleiten" + variant="outline" + dataTestId="forwarding-button" + data-test-id="forwarding-button-container" +> <ods-forward-vorgang-icon icon class="fill-primary" /> -</ods-button-with-spinner> \ No newline at end of file +</ods-button-with-spinner> diff --git a/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog/forwarding-button/forwarding-button.component.spec.ts b/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog/forwarding-button/forwarding-button.component.spec.ts index ec3ee8288b888a029f6de545b97636ec3c5aae5d..9e9a9d2118e1a9758f7ba58715f822822ead4cbf 100644 --- a/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog/forwarding-button/forwarding-button.component.spec.ts +++ b/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog/forwarding-button/forwarding-button.component.spec.ts @@ -1,7 +1,8 @@ +import { dispatchEventFromFixture, MockEvent } from '@alfa-client/test-utils'; import { ComponentFixture, TestBed } from '@angular/core/testing'; - import { ButtonWithSpinnerComponent } from '@ods/component'; import { ForwardVorgangIconComponent } from '@ods/system'; +import { getDataTestIdOf } from 'libs/tech-shared/test/data-test'; import { MockComponent } from 'ng-mocks'; import { ForwardingButtonComponent } from './forwarding-button.component'; @@ -9,6 +10,8 @@ describe('ForwardingButtonComponent', () => { let component: ForwardingButtonComponent; let fixture: ComponentFixture<ForwardingButtonComponent>; + const button: string = getDataTestIdOf('forwarding-button-container'); + beforeEach(async () => { await TestBed.configureTestingModule({ imports: [ForwardingButtonComponent], @@ -23,4 +26,14 @@ describe('ForwardingButtonComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); + + describe('on button click', () => { + it('should emit', () => { + component.clickEmitter.emit = jest.fn(); + + dispatchEventFromFixture(fixture, button, MockEvent.CLICK); + + expect(component.clickEmitter.emit).toHaveBeenCalled(); + }); + }); }); diff --git a/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog/forwarding-button/forwarding-button.component.ts b/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog/forwarding-button/forwarding-button.component.ts index 63fec70d17fb549ab13163155fe3ca596446209a..767fe5e4ce40e7589725973d37e9a84c12fd0564 100644 --- a/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog/forwarding-button/forwarding-button.component.ts +++ b/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog/forwarding-button/forwarding-button.component.ts @@ -1,4 +1,6 @@ -import { Component, Input } from '@angular/core'; +import { CommandResource } from '@alfa-client/command-shared'; +import { StateResource } from '@alfa-client/tech-shared'; +import { Component, EventEmitter, Input, Output } from '@angular/core'; import { ButtonWithSpinnerComponent } from '@ods/component'; import { ForwardVorgangIconComponent } from '@ods/system'; @@ -10,4 +12,7 @@ import { ForwardVorgangIconComponent } from '@ods/system'; }) export class ForwardingButtonComponent { @Input() disabled: boolean; + @Input() stateResource: StateResource<CommandResource>; + + @Output() clickEmitter: EventEmitter<void> = new EventEmitter(); } diff --git a/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog/forwarding-dialog.component.html b/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog/forwarding-dialog.component.html index 3d60550c444dcbc34d9f229e91c1133e6a5af9ac..0598624f20e7e68610eefb9a3bc759269d3488f9 100644 --- a/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog/forwarding-dialog.component.html +++ b/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog/forwarding-dialog.component.html @@ -1,5 +1,5 @@ <div class="flex w-[620px] max-w-full flex-col gap-4 bg-background-100 p-8"> - <div class="flex items-center justify-between" > + <div class="flex items-center justify-between"> <h1 class="text-xl font-semibold text-primary">Vorgang weiterleiten</h1> <ods-cancel-dialog-button showAsIconButton="true" /> </div> @@ -7,14 +7,16 @@ @if (!selectedSearchResult) { <alfa-search-zustaendige-stelle-form-container cdkFocusInitial focusOnSearchField="true" data-test-id="zufi-search" /> } @else { - <alfa-forwarding-item-in-dialog - [organisationsEinheitResource]="selectedSearchResult" - data-test-id="forwarding-item" - /> + <alfa-forwarding-item-in-dialog [organisationsEinheitResource]="selectedSearchResult" data-test-id="forwarding-item" /> } <div class="flex gap-4"> - <alfa-forwarding-button [disabled]="!selectedSearchResult"/> + <alfa-forwarding-button + [stateResource]="forwardCommandStateResource" + [disabled]="!selectedSearchResult" + (clickEmitter)="forwarding()" + data-test-id="foward-dialog-forward-button" + /> <ods-cancel-dialog-button /> </div> </div> diff --git a/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog/forwarding-dialog.component.spec.ts b/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog/forwarding-dialog.component.spec.ts index 6d4454c8e37a0bde91a410aeacf6df07087973f6..7e6114236be2ad7d2dddfcdfd309853b32568cdd 100644 --- a/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog/forwarding-dialog.component.spec.ts +++ b/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog/forwarding-dialog.component.spec.ts @@ -1,14 +1,21 @@ -import { existsAsHtmlElement, getMockComponent, notExistsAsHtmlElement } from '@alfa-client/test-utils'; +import { + dispatchEventFromFixture, + existsAsHtmlElement, + getMockComponent, + MockEvent, + notExistsAsHtmlElement, +} from '@alfa-client/test-utils'; import { ZustaendigeStelleModule } from '@alfa-client/zustaendige-stelle'; import { OrganisationsEinheitResource } from '@alfa-client/zustaendige-stelle-shared'; import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { getUrl } from '@ngxp/rest'; import { CancelDialogButtonComponent } from '@ods/component'; import { MockComponent, MockModule } from 'ng-mocks'; import { getDataTestIdOf } from '../../../../../tech-shared/test/data-test'; import { createOrganisationsEinheitResource } from '../../../../../zustaendige-stelle-shared/test/organisations-einheit'; import { ForwardingButtonComponent } from './forwarding-button/forwarding-button.component'; -import { ForwardingItemInDialogComponent } from './forwarding-item/forwarding-item.component'; import { ForwardingDialogComponent } from './forwarding-dialog.component'; +import { ForwardingItemInDialogComponent } from './forwarding-item/forwarding-item.component'; describe('ForwardingDialogComponent', () => { let component: ForwardingDialogComponent; @@ -16,6 +23,7 @@ describe('ForwardingDialogComponent', () => { const zufiSearch: string = getDataTestIdOf('zufi-search'); const forwardingItem: string = getDataTestIdOf('forwarding-item'); + const forwardButton: string = getDataTestIdOf('foward-dialog-forward-button'); const organisationsEinheitResource: OrganisationsEinheitResource = createOrganisationsEinheitResource(); beforeEach(async () => { @@ -64,23 +72,21 @@ describe('ForwardingDialogComponent', () => { fixture.detectChanges(); }); - describe('template', () => { - describe('forwarding item', () => { - it('should render if selectedSearchResult is NOT null', () => { - component.selectedSearchResult = organisationsEinheitResource; + describe('forwarding item', () => { + it('should render if selectedSearchResult is NOT null', () => { + component.selectedSearchResult = organisationsEinheitResource; - fixture.detectChanges(); + fixture.detectChanges(); - existsAsHtmlElement(fixture, forwardingItem); - }); + existsAsHtmlElement(fixture, forwardingItem); + }); - it('should NOT render if selectedSearchResult is null', () => { - component.selectedSearchResult = null; + it('should NOT render if selectedSearchResult is null', () => { + component.selectedSearchResult = null; - fixture.detectChanges(); + fixture.detectChanges(); - notExistsAsHtmlElement(fixture, forwardingItem); - }); + notExistsAsHtmlElement(fixture, forwardingItem); }); }); @@ -103,4 +109,15 @@ describe('ForwardingDialogComponent', () => { expect(forwardingButton.disabled).toBeFalsy(); }); }); + + describe('forward button', () => { + it('should emit on click', () => { + component.selectedSearchResult = organisationsEinheitResource; + component.forward.emit = jest.fn(); + + dispatchEventFromFixture(fixture, forwardButton, MockEvent.CLICK); + + expect(component.forward.emit).toHaveBeenCalledWith(getUrl(organisationsEinheitResource)); + }); + }); }); diff --git a/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog/forwarding-dialog.component.ts b/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog/forwarding-dialog.component.ts index c1695f42a08728b6921b6813694fad2ffb5440fe..b4019a8de9e8db7fc29b9cef2be18ec5bfc1d911 100644 --- a/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog/forwarding-dialog.component.ts +++ b/alfa-client/libs/forwarding/src/lib/forwarding-dialog-container/forwarding-dialog/forwarding-dialog.component.ts @@ -1,8 +1,11 @@ +import { CommandResource } from '@alfa-client/command-shared'; +import { StateResource } from '@alfa-client/tech-shared'; import { ZustaendigeStelleModule } from '@alfa-client/zustaendige-stelle'; import { OrganisationsEinheitResource } from '@alfa-client/zustaendige-stelle-shared'; import { A11yModule } from '@angular/cdk/a11y'; -import { Component, Input } from '@angular/core'; +import { Component, EventEmitter, Input, Output } from '@angular/core'; import { ReactiveFormsModule } from '@angular/forms'; +import { getUrl, ResourceUri } from '@ngxp/rest'; import { CancelDialogButtonComponent } from '@ods/component'; import { ForwardingButtonComponent } from './forwarding-button/forwarding-button.component'; import { ForwardingItemInDialogComponent } from './forwarding-item/forwarding-item.component'; @@ -22,4 +25,11 @@ import { ForwardingItemInDialogComponent } from './forwarding-item/forwarding-it }) export class ForwardingDialogComponent { @Input() selectedSearchResult: OrganisationsEinheitResource; + @Input() forwardCommandStateResource: StateResource<CommandResource>; + + @Output() forward: EventEmitter<ResourceUri> = new EventEmitter(); + + public forwarding(): void { + this.forward.emit(getUrl(this.selectedSearchResult)); + } }