Modal outputs as EventEmitters instead of Subjects

This commit is contained in:
Yura Bondarenko
2022-05-20 10:53:50 +02:00
parent f3e2a7a6f1
commit 383485b16d
5 changed files with 29 additions and 32 deletions

View File

@@ -46,27 +46,27 @@ describe('ConfirmationModalComponent', () => {
describe('confirmPressed', () => {
beforeEach(() => {
spyOn(component.response, 'next');
spyOn(component.response, 'emit');
component.confirmPressed();
});
it('should call the close method on the active modal', () => {
expect(modalStub.close).toHaveBeenCalled();
});
it('behaviour subject should have true as next', () => {
expect(component.response.next).toHaveBeenCalledWith(true);
it('behaviour subject should emit true', () => {
expect(component.response.emit).toHaveBeenCalledWith(true);
});
});
describe('cancelPressed', () => {
beforeEach(() => {
spyOn(component.response, 'next');
spyOn(component.response, 'emit');
component.cancelPressed();
});
it('should call the close method on the active modal', () => {
expect(modalStub.close).toHaveBeenCalled();
});
it('behaviour subject should have false as next', () => {
expect(component.response.next).toHaveBeenCalledWith(false);
it('behaviour subject should emit false', () => {
expect(component.response.emit).toHaveBeenCalledWith(false);
});
});
@@ -88,7 +88,7 @@ describe('ConfirmationModalComponent', () => {
describe('when the click method emits on cancel button', () => {
beforeEach(fakeAsync(() => {
spyOn(component, 'close');
spyOn(component.response, 'next');
spyOn(component.response, 'emit');
debugElement.query(By.css('button.cancel')).triggerEventHandler('click', {
preventDefault: () => {/**/
}
@@ -99,15 +99,15 @@ describe('ConfirmationModalComponent', () => {
it('should call the close method on the component', () => {
expect(component.close).toHaveBeenCalled();
});
it('behaviour subject should have false as next', () => {
expect(component.response.next).toHaveBeenCalledWith(false);
it('behaviour subject should emit false', () => {
expect(component.response.emit).toHaveBeenCalledWith(false);
});
});
describe('when the click method emits on confirm button', () => {
beforeEach(fakeAsync(() => {
spyOn(component, 'close');
spyOn(component.response, 'next');
spyOn(component.response, 'emit');
debugElement.query(By.css('button.confirm')).triggerEventHandler('click', {
preventDefault: () => {/**/
}
@@ -118,8 +118,8 @@ describe('ConfirmationModalComponent', () => {
it('should call the close method on the component', () => {
expect(component.close).toHaveBeenCalled();
});
it('behaviour subject should have true as next', () => {
expect(component.response.next).toHaveBeenCalledWith(true);
it('behaviour subject should emit false', () => {
expect(component.response.emit).toHaveBeenCalledWith(true);
});
});

View File

@@ -1,6 +1,5 @@
import { Component, Input, Output } from '@angular/core';
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { Subject } from 'rxjs';
import { DSpaceObject } from '../../core/shared/dspace-object.model';
@Component({
@@ -24,7 +23,7 @@ export class ConfirmationModalComponent {
* An event fired when the cancel or confirm button is clicked, with respectively false or true
*/
@Output()
response: Subject<boolean> = new Subject();
response = new EventEmitter<boolean>();
constructor(protected activeModal: NgbActiveModal) {
}
@@ -33,7 +32,7 @@ export class ConfirmationModalComponent {
* Confirm the action that led to the modal
*/
confirmPressed() {
this.response.next(true);
this.response.emit(true);
this.close();
}
@@ -41,7 +40,7 @@ export class ConfirmationModalComponent {
* Cancel the action that led to the modal and close modal
*/
cancelPressed() {
this.response.next(false);
this.response.emit(false);
this.close();
}

View File

@@ -46,7 +46,7 @@ describe('IdleModalComponent', () => {
describe('extendSessionPressed', () => {
beforeEach(fakeAsync(() => {
spyOn(component.response, 'next');
spyOn(component.response, 'emit');
component.extendSessionPressed();
}));
it('should set idle to false', () => {
@@ -55,8 +55,8 @@ describe('IdleModalComponent', () => {
it('should close the modal', () => {
expect(modalStub.close).toHaveBeenCalled();
});
it('response \'closed\' should have true as next', () => {
expect(component.response.next).toHaveBeenCalledWith(true);
it('response \'closed\' should emit true', () => {
expect(component.response.emit).toHaveBeenCalledWith(true);
});
});
@@ -74,7 +74,7 @@ describe('IdleModalComponent', () => {
describe('closePressed', () => {
beforeEach(fakeAsync(() => {
spyOn(component.response, 'next');
spyOn(component.response, 'emit');
component.closePressed();
}));
it('should set idle to false', () => {
@@ -83,8 +83,8 @@ describe('IdleModalComponent', () => {
it('should close the modal', () => {
expect(modalStub.close).toHaveBeenCalled();
});
it('response \'closed\' should have true as next', () => {
expect(component.response.next).toHaveBeenCalledWith(true);
it('response \'closed\' should emit true', () => {
expect(component.response.emit).toHaveBeenCalledWith(true);
});
});

View File

@@ -1,8 +1,7 @@
import { Component, OnInit, Output } from '@angular/core';
import { Component, EventEmitter, OnInit, Output } from '@angular/core';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { environment } from '../../../environments/environment';
import { AuthService } from '../../core/auth/auth.service';
import { Subject } from 'rxjs';
import { hasValue } from '../empty.util';
import { Store } from '@ngrx/store';
import { AppState } from '../../app.reducer';
@@ -29,7 +28,7 @@ export class IdleModalComponent implements OnInit {
* An event fired when the modal is closed
*/
@Output()
response: Subject<boolean> = new Subject();
response = new EventEmitter<boolean>();
constructor(private activeModal: NgbActiveModal,
private authService: AuthService,
@@ -84,6 +83,6 @@ export class IdleModalComponent implements OnInit {
*/
closeModal() {
this.activeModal.close();
this.response.next(true);
this.response.emit(true);
}
}

View File

@@ -1,6 +1,5 @@
import { Component, Output } from '@angular/core';
import { Component, EventEmitter, Output } from '@angular/core';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { Subject } from 'rxjs';
@Component({
selector: 'ds-item-versions-delete-modal',
@@ -12,7 +11,7 @@ export class ItemVersionsDeleteModalComponent {
* An event fired when the cancel or confirm button is clicked, with respectively false or true
*/
@Output()
response: Subject<boolean> = new Subject();
response = new EventEmitter<boolean>();
versionNumber: number;
@@ -21,12 +20,12 @@ export class ItemVersionsDeleteModalComponent {
}
onModalClose() {
this.response.next(false);
this.response.emit(false);
this.activeModal.dismiss();
}
onModalSubmit() {
this.response.next(true);
this.response.emit(true);
this.activeModal.close();
}