Skip to content
Snippets Groups Projects
Commit dee9aa9b authored by Martin's avatar Martin
Browse files

OZG-7501 implement button function

parent 16a7d706
No related branches found
No related tags found
1 merge request!100Ozg 7501 weiterleitung vorbereiten
Showing
with 175 additions and 33 deletions
<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"
/>
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();
});
});
});
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();
}),
);
}
}
<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>
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();
});
});
});
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();
}
......@@ -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>
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,7 +72,6 @@ describe('ForwardingDialogComponent', () => {
fixture.detectChanges();
});
describe('template', () => {
describe('forwarding item', () => {
it('should render if selectedSearchResult is NOT null', () => {
component.selectedSearchResult = organisationsEinheitResource;
......@@ -82,7 +89,6 @@ describe('ForwardingDialogComponent', () => {
notExistsAsHtmlElement(fixture, forwardingItem);
});
});
});
describe('forwarding button', () => {
it('should be disabled if selectedSearchResult is null', () => {
......@@ -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));
});
});
});
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));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment