Skip to content
Snippets Groups Projects
Commit 63b1c220 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-6301 OZG-6525 Prevent default behavior on enter key down

parent 8dee6c10
No related branches found
No related tags found
No related merge requests found
......@@ -8,14 +8,7 @@ import {
ToEmbeddedResourcesPipe,
createStateResource,
} from '@alfa-client/tech-shared';
import {
EventData,
Mock,
dialogRefMock,
getMockComponent,
mock,
triggerEvent,
} from '@alfa-client/test-utils';
import { EventData, Mock, getMockComponent, mock, triggerEvent } from '@alfa-client/test-utils';
import { DialogRef } from '@angular/cdk/dialog';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import faker from '@faker-js/faker';
......@@ -27,7 +20,7 @@ import {
} from 'libs/collaboration-shared/test/organisations-einheit';
import { getDataTestIdOf } from 'libs/tech-shared/test/data-test';
import { MockComponent } from 'ng-mocks';
import { of } from 'rxjs';
import { Subscription, of } from 'rxjs';
import { SearchOrganisationsEinheitContainerComponent } from './search-organisations-einheit-container.component';
import { SearchOrganisationsEinheitFormComponent } from './search-organisations-einheit-form/search-organisations-einheit-form.component';
......@@ -64,7 +57,7 @@ describe('SearchOrganisationsEinheitContainerComponent', () => {
},
{
provide: DialogRef,
useValue: dialogRefMock,
useValue: { keydownEvents: of(KeyboardEvent), close: jest.fn() },
},
],
}).compileComponents();
......@@ -85,6 +78,23 @@ describe('SearchOrganisationsEinheitContainerComponent', () => {
expect(service.getSearchResultList).toHaveBeenCalled();
});
it('should subscribe to dialogRef.keydownEvents', () => {
component.ngOnInit();
expect(component.keydownEventsSubscription).toBeInstanceOf(Subscription);
});
});
describe('ngOnDestroy', () => {
it('should unsubscribe keydownEventsSubscription', () => {
component.keydownEventsSubscription = new Subscription();
jest.spyOn(component.keydownEventsSubscription, 'unsubscribe');
component.ngOnDestroy();
expect(component.keydownEventsSubscription.unsubscribe).toHaveBeenCalled();
});
});
describe('search organisationsEinheit component', () => {
......@@ -169,7 +179,7 @@ describe('SearchOrganisationsEinheitContainerComponent', () => {
it('should close dialog', () => {
component.selectSearchResult(organisationsEinheitResource);
expect(dialogRefMock.close).toHaveBeenCalledWith(organisationsEinheitResource);
expect(component.dialogRef.close).toHaveBeenCalled();
});
});
......@@ -193,7 +203,7 @@ describe('SearchOrganisationsEinheitContainerComponent', () => {
it('should close dialog', () => {
component.closeDialog();
expect(dialogRefMock.close).toHaveBeenCalled();
expect(component.dialogRef.close).toHaveBeenCalled();
});
});
});
......@@ -4,31 +4,41 @@ import {
} from '@alfa-client/collaboration-shared';
import { StateResource } from '@alfa-client/tech-shared';
import { DialogRef } from '@angular/cdk/dialog';
import { Component, OnInit } from '@angular/core';
import { Component, OnDestroy, OnInit } from '@angular/core';
import {
OrganisationsEinheitListResource,
OrganisationsEinheitResource,
} from 'libs/collaboration-shared/src/lib/organisations-einheit.model';
import { Observable } from 'rxjs';
import { Observable, Subscription, filter } from 'rxjs';
@Component({
selector: 'alfa-search-organisations-einheit-container',
templateUrl: './search-organisations-einheit-container.component.html',
})
export class SearchOrganisationsEinheitContainerComponent implements OnInit {
export class SearchOrganisationsEinheitContainerComponent implements OnInit, OnDestroy {
public organisationsEinheitStateListResource$: Observable<
StateResource<OrganisationsEinheitListResource>
>;
public readonly organisationsEinheitListLinkRel = OrganisationsEinheitListLinkRel;
keydownEventsSubscription: Subscription;
constructor(
private readonly service: OrganisationsEinheitService,
private readonly dialogRef: DialogRef,
readonly dialogRef: DialogRef,
) {}
ngOnInit(): void {
this.organisationsEinheitStateListResource$ = this.service.getSearchResultList();
this.keydownEventsSubscription = this.dialogRef.keydownEvents
.pipe(filter((e: KeyboardEvent) => e.key === 'Enter'))
.subscribe((e: KeyboardEvent) => {
e.preventDefault();
});
}
ngOnDestroy(): void {
this.keydownEventsSubscription.unsubscribe();
}
public search(searchBy: string): void {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment