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"/> <alfa-forwarding-dialog
\ No newline at end of file [forwardCommandStateResource]="forwardCommandStateResource$ | async"
[selectedSearchResult]="selectedSearchResult$ | async"
(forward)="forward($event)"
data-test-id="forwarding-dialog"
/>
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { CommandLinkRel, CommandResource } from '@alfa-client/command-shared';
import { ForwardingService } from '@alfa-client/forwarding-shared';
import { mock, Mock } from '@alfa-client/test-utils'; 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 { OrganisationsEinheitService, ZUSTAENDIGE_STELLE_SERVICE } from '@alfa-client/zustaendige-stelle-shared';
import { AsyncPipe } from '@angular/common'; 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 { MockComponent } from 'ng-mocks';
import { of } from 'rxjs';
import { ForwardingDialogContainerComponent } from './forwarding-dialog-container.component'; import { ForwardingDialogContainerComponent } from './forwarding-dialog-container.component';
import { ForwardingDialogComponent } from './forwarding-dialog/forwarding-dialog.component'; import { ForwardingDialogComponent } from './forwarding-dialog/forwarding-dialog.component';
...@@ -11,14 +20,30 @@ describe('ForwardingDialogContainerComponent', () => { ...@@ -11,14 +20,30 @@ describe('ForwardingDialogContainerComponent', () => {
let component: ForwardingDialogContainerComponent; let component: ForwardingDialogContainerComponent;
let fixture: ComponentFixture<ForwardingDialogContainerComponent>; let fixture: ComponentFixture<ForwardingDialogContainerComponent>;
const forwardingDialog: string = getDataTestIdOf('forwarding-dialog');
let service: Mock<ForwardingService>;
let organisationsEinheitService: Mock<OrganisationsEinheitService>; let organisationsEinheitService: Mock<OrganisationsEinheitService>;
let dialogService: Mock<OzgcloudDialogService>;
beforeEach(async () => { beforeEach(async () => {
service = mock(ForwardingService);
organisationsEinheitService = mock(OrganisationsEinheitService); organisationsEinheitService = mock(OrganisationsEinheitService);
dialogService = mock(OzgcloudDialogService);
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
imports: [ForwardingDialogContainerComponent, AsyncPipe], imports: [ForwardingDialogContainerComponent, AsyncPipe],
declarations: [MockComponent(ForwardingDialogComponent)], declarations: [MockComponent(ForwardingDialogComponent)],
providers: [
{
provide: ForwardingService,
useValue: service,
},
{
provide: OzgcloudDialogService,
useValue: dialogService,
},
],
}) })
.overrideComponent(ForwardingDialogContainerComponent, { .overrideComponent(ForwardingDialogContainerComponent, {
set: { set: {
...@@ -40,4 +65,45 @@ describe('ForwardingDialogContainerComponent', () => { ...@@ -40,4 +65,45 @@ describe('ForwardingDialogContainerComponent', () => {
it('should create', () => { it('should create', () => {
expect(component).toBeTruthy(); 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 { VorgangService } from '@alfa-client/vorgang-shared';
import { createOrganisationEinheitService } from '@alfa-client/zustaendige-stelle'; import { createOrganisationEinheitService } from '@alfa-client/zustaendige-stelle';
import { import {
...@@ -6,15 +9,16 @@ import { ...@@ -6,15 +9,16 @@ import {
OrganisationsEinheitService, OrganisationsEinheitService,
ZUSTAENDIGE_STELLE_SERVICE, ZUSTAENDIGE_STELLE_SERVICE,
} from '@alfa-client/zustaendige-stelle-shared'; } 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 { 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'; import { ForwardingDialogComponent } from './forwarding-dialog/forwarding-dialog.component';
@Component({ @Component({
selector: 'alfa-forwarding-dialog-container', selector: 'alfa-forwarding-dialog-container',
standalone: true, standalone: true,
imports: [ForwardingDialogComponent, AsyncPipe], imports: [ForwardingDialogComponent, AsyncPipe, CommonModule],
templateUrl: './forwarding-dialog-container.component.html', templateUrl: './forwarding-dialog-container.component.html',
providers: [ providers: [
{ {
...@@ -26,10 +30,22 @@ import { ForwardingDialogComponent } from './forwarding-dialog/forwarding-dialog ...@@ -26,10 +30,22 @@ import { ForwardingDialogComponent } from './forwarding-dialog/forwarding-dialog
}) })
export class ForwardingDialogContainerComponent implements OnInit { export class ForwardingDialogContainerComponent implements OnInit {
private readonly organisationsEinheitService = inject(ZUSTAENDIGE_STELLE_SERVICE) as OrganisationsEinheitService; private readonly organisationsEinheitService = inject(ZUSTAENDIGE_STELLE_SERVICE) as OrganisationsEinheitService;
private readonly forwardingService = inject(ForwardingService);
private readonly dialogService = inject(OzgcloudDialogService);
public selectedSearchResult$: Observable<OrganisationsEinheitResource>; public selectedSearchResult$: Observable<OrganisationsEinheitResource>;
public forwardCommandStateResource$: Observable<StateResource<CommandResource>> =
of(createEmptyStateResource<CommandResource>());
ngOnInit(): void { ngOnInit(): void {
this.selectedSearchResult$ = this.organisationsEinheitService.getSelectedResult(); 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-forward-vorgang-icon icon class="fill-primary" />
</ods-button-with-spinner> </ods-button-with-spinner>
import { dispatchEventFromFixture, MockEvent } from '@alfa-client/test-utils';
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ButtonWithSpinnerComponent } from '@ods/component'; import { ButtonWithSpinnerComponent } from '@ods/component';
import { ForwardVorgangIconComponent } from '@ods/system'; import { ForwardVorgangIconComponent } from '@ods/system';
import { getDataTestIdOf } from 'libs/tech-shared/test/data-test';
import { MockComponent } from 'ng-mocks'; import { MockComponent } from 'ng-mocks';
import { ForwardingButtonComponent } from './forwarding-button.component'; import { ForwardingButtonComponent } from './forwarding-button.component';
...@@ -9,6 +10,8 @@ describe('ForwardingButtonComponent', () => { ...@@ -9,6 +10,8 @@ describe('ForwardingButtonComponent', () => {
let component: ForwardingButtonComponent; let component: ForwardingButtonComponent;
let fixture: ComponentFixture<ForwardingButtonComponent>; let fixture: ComponentFixture<ForwardingButtonComponent>;
const button: string = getDataTestIdOf('forwarding-button-container');
beforeEach(async () => { beforeEach(async () => {
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
imports: [ForwardingButtonComponent], imports: [ForwardingButtonComponent],
...@@ -23,4 +26,14 @@ describe('ForwardingButtonComponent', () => { ...@@ -23,4 +26,14 @@ describe('ForwardingButtonComponent', () => {
it('should create', () => { it('should create', () => {
expect(component).toBeTruthy(); 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 { ButtonWithSpinnerComponent } from '@ods/component';
import { ForwardVorgangIconComponent } from '@ods/system'; import { ForwardVorgangIconComponent } from '@ods/system';
...@@ -10,4 +12,7 @@ import { ForwardVorgangIconComponent } from '@ods/system'; ...@@ -10,4 +12,7 @@ import { ForwardVorgangIconComponent } from '@ods/system';
}) })
export class ForwardingButtonComponent { export class ForwardingButtonComponent {
@Input() disabled: boolean; @Input() disabled: boolean;
@Input() stateResource: StateResource<CommandResource>;
@Output() clickEmitter: EventEmitter<void> = new EventEmitter();
} }
...@@ -7,14 +7,16 @@ ...@@ -7,14 +7,16 @@
@if (!selectedSearchResult) { @if (!selectedSearchResult) {
<alfa-search-zustaendige-stelle-form-container cdkFocusInitial focusOnSearchField="true" data-test-id="zufi-search" /> <alfa-search-zustaendige-stelle-form-container cdkFocusInitial focusOnSearchField="true" data-test-id="zufi-search" />
} @else { } @else {
<alfa-forwarding-item-in-dialog <alfa-forwarding-item-in-dialog [organisationsEinheitResource]="selectedSearchResult" data-test-id="forwarding-item" />
[organisationsEinheitResource]="selectedSearchResult"
data-test-id="forwarding-item"
/>
} }
<div class="flex gap-4"> <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 /> <ods-cancel-dialog-button />
</div> </div>
</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 { ZustaendigeStelleModule } from '@alfa-client/zustaendige-stelle';
import { OrganisationsEinheitResource } from '@alfa-client/zustaendige-stelle-shared'; import { OrganisationsEinheitResource } from '@alfa-client/zustaendige-stelle-shared';
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { getUrl } from '@ngxp/rest';
import { CancelDialogButtonComponent } from '@ods/component'; import { CancelDialogButtonComponent } from '@ods/component';
import { MockComponent, MockModule } from 'ng-mocks'; import { MockComponent, MockModule } from 'ng-mocks';
import { getDataTestIdOf } from '../../../../../tech-shared/test/data-test'; import { getDataTestIdOf } from '../../../../../tech-shared/test/data-test';
import { createOrganisationsEinheitResource } from '../../../../../zustaendige-stelle-shared/test/organisations-einheit'; import { createOrganisationsEinheitResource } from '../../../../../zustaendige-stelle-shared/test/organisations-einheit';
import { ForwardingButtonComponent } from './forwarding-button/forwarding-button.component'; import { ForwardingButtonComponent } from './forwarding-button/forwarding-button.component';
import { ForwardingItemInDialogComponent } from './forwarding-item/forwarding-item.component';
import { ForwardingDialogComponent } from './forwarding-dialog.component'; import { ForwardingDialogComponent } from './forwarding-dialog.component';
import { ForwardingItemInDialogComponent } from './forwarding-item/forwarding-item.component';
describe('ForwardingDialogComponent', () => { describe('ForwardingDialogComponent', () => {
let component: ForwardingDialogComponent; let component: ForwardingDialogComponent;
...@@ -16,6 +23,7 @@ describe('ForwardingDialogComponent', () => { ...@@ -16,6 +23,7 @@ describe('ForwardingDialogComponent', () => {
const zufiSearch: string = getDataTestIdOf('zufi-search'); const zufiSearch: string = getDataTestIdOf('zufi-search');
const forwardingItem: string = getDataTestIdOf('forwarding-item'); const forwardingItem: string = getDataTestIdOf('forwarding-item');
const forwardButton: string = getDataTestIdOf('foward-dialog-forward-button');
const organisationsEinheitResource: OrganisationsEinheitResource = createOrganisationsEinheitResource(); const organisationsEinheitResource: OrganisationsEinheitResource = createOrganisationsEinheitResource();
beforeEach(async () => { beforeEach(async () => {
...@@ -64,7 +72,6 @@ describe('ForwardingDialogComponent', () => { ...@@ -64,7 +72,6 @@ describe('ForwardingDialogComponent', () => {
fixture.detectChanges(); fixture.detectChanges();
}); });
describe('template', () => {
describe('forwarding item', () => { describe('forwarding item', () => {
it('should render if selectedSearchResult is NOT null', () => { it('should render if selectedSearchResult is NOT null', () => {
component.selectedSearchResult = organisationsEinheitResource; component.selectedSearchResult = organisationsEinheitResource;
...@@ -82,7 +89,6 @@ describe('ForwardingDialogComponent', () => { ...@@ -82,7 +89,6 @@ describe('ForwardingDialogComponent', () => {
notExistsAsHtmlElement(fixture, forwardingItem); notExistsAsHtmlElement(fixture, forwardingItem);
}); });
}); });
});
describe('forwarding button', () => { describe('forwarding button', () => {
it('should be disabled if selectedSearchResult is null', () => { it('should be disabled if selectedSearchResult is null', () => {
...@@ -103,4 +109,15 @@ describe('ForwardingDialogComponent', () => { ...@@ -103,4 +109,15 @@ describe('ForwardingDialogComponent', () => {
expect(forwardingButton.disabled).toBeFalsy(); 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 { ZustaendigeStelleModule } from '@alfa-client/zustaendige-stelle';
import { OrganisationsEinheitResource } from '@alfa-client/zustaendige-stelle-shared'; import { OrganisationsEinheitResource } from '@alfa-client/zustaendige-stelle-shared';
import { A11yModule } from '@angular/cdk/a11y'; 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 { ReactiveFormsModule } from '@angular/forms';
import { getUrl, ResourceUri } from '@ngxp/rest';
import { CancelDialogButtonComponent } from '@ods/component'; import { CancelDialogButtonComponent } from '@ods/component';
import { ForwardingButtonComponent } from './forwarding-button/forwarding-button.component'; import { ForwardingButtonComponent } from './forwarding-button/forwarding-button.component';
import { ForwardingItemInDialogComponent } from './forwarding-item/forwarding-item.component'; import { ForwardingItemInDialogComponent } from './forwarding-item/forwarding-item.component';
...@@ -22,4 +25,11 @@ import { ForwardingItemInDialogComponent } from './forwarding-item/forwarding-it ...@@ -22,4 +25,11 @@ import { ForwardingItemInDialogComponent } from './forwarding-item/forwarding-it
}) })
export class ForwardingDialogComponent { export class ForwardingDialogComponent {
@Input() selectedSearchResult: OrganisationsEinheitResource; @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