-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
475 additions
and
47 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...components/requisition/requisition-reject-dialog/requisition-reject-dialog.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<ng-template #modal let-rejectModal> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h2 class="modal-title">{{ 'approval.rejectform.reject_order.heading' | translate }}</h2> | ||
<button class="close" (click)="hide()" [title]="'application.overlay.close.text' | translate" aria-label="Close"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
|
||
<form [formGroup]="rejectForm" (ngSubmit)="submitForm()"> | ||
<div class="modal-body"> | ||
<div class="form-group clearfix"> | ||
<ish-textarea | ||
[form]="rejectForm" | ||
controlName="comment" | ||
label="approval.rejectform.add_a_comment.label" | ||
labelClass="col-12" | ||
inputClass="col-12" | ||
[errorMessages]="{ required: 'approval.rejectform.invalid_comment.error' }" | ||
markRequiredLabel="off" | ||
maxlength="1000" | ||
rows="4" | ||
></ish-textarea> | ||
</div> | ||
</div> | ||
|
||
<div class="modal-footer"> | ||
<button class="btn btn-primary" type="submit" (click)="submitForm()" [disabled]="formDisabled"> | ||
{{ 'approval.rejectform.button.reject.label' | translate }} | ||
</button> | ||
<button class="btn btn-secondary" type="button" (click)="rejectModal.close('')"> | ||
{{ 'approval.rejectform.button.cancel.label' | translate }} | ||
</button> | ||
</div> | ||
</form> | ||
</div> | ||
</ng-template> |
57 changes: 57 additions & 0 deletions
57
...ponents/requisition/requisition-reject-dialog/requisition-reject-dialog.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { ComponentFixture, TestBed, async } from '@angular/core/testing'; | ||
import { ReactiveFormsModule } from '@angular/forms'; | ||
import { NgbModalModule } from '@ng-bootstrap/ng-bootstrap'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
import { MockComponent } from 'ng-mocks'; | ||
import { spy, verify } from 'ts-mockito'; | ||
|
||
import { TextareaComponent } from 'ish-shared/forms/components/textarea/textarea.component'; | ||
|
||
import { RequisitionRejectDialogComponent } from './requisition-reject-dialog.component'; | ||
|
||
describe('Requisition Reject Dialog Component', () => { | ||
let component: RequisitionRejectDialogComponent; | ||
let fixture: ComponentFixture<RequisitionRejectDialogComponent>; | ||
let element: HTMLElement; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [MockComponent(TextareaComponent), RequisitionRejectDialogComponent], | ||
imports: [NgbModalModule, ReactiveFormsModule, TranslateModule.forRoot()], | ||
}).compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(RequisitionRejectDialogComponent); | ||
component = fixture.componentInstance; | ||
element = fixture.nativeElement; | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(component).toBeTruthy(); | ||
expect(element).toBeTruthy(); | ||
expect(() => fixture.detectChanges()).not.toThrow(); | ||
}); | ||
|
||
it('should emit approval comment when submit form was called and the form was valid', done => { | ||
fixture.detectChanges(); | ||
component.rejectForm.setValue({ | ||
comment: 'test comment', | ||
}); | ||
|
||
component.submit.subscribe(emit => { | ||
expect(emit).toEqual('test comment'); | ||
done(); | ||
}); | ||
|
||
component.submitForm(); | ||
}); | ||
|
||
it('should not emit new approval comment when submit form was called and the form was invalid', () => { | ||
fixture.detectChanges(); | ||
const emitter = spy(component.submit); | ||
component.submitForm(); | ||
|
||
verify(emitter.emit()).never(); | ||
}); | ||
}); |
77 changes: 77 additions & 0 deletions
77
...p/components/requisition/requisition-reject-dialog/requisition-reject-dialog.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { ChangeDetectionStrategy, Component, EventEmitter, Output, TemplateRef, ViewChild } from '@angular/core'; | ||
import { FormControl, FormGroup, Validators } from '@angular/forms'; | ||
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; | ||
|
||
import { markAsDirtyRecursive } from 'ish-shared/forms/utils/form-utils'; | ||
|
||
/** | ||
* The Wishlist Reject Approval Dialog shows the modal to reject a requisition. | ||
* | ||
* @example | ||
* <ish-requisition-reject-dialog | ||
(submit)="rejectRequisition($event)"> | ||
</ish-requisition-reject-dialog> | ||
*/ | ||
@Component({ | ||
selector: 'ish-requisition-reject-dialog', | ||
templateUrl: './requisition-reject-dialog.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class RequisitionRejectDialogComponent { | ||
/** | ||
* Emits the reject event with the reject comment. | ||
*/ | ||
@Output() submit = new EventEmitter<string>(); | ||
|
||
rejectForm: FormGroup; | ||
submitted = false; | ||
|
||
/** | ||
* A reference to the current modal. | ||
*/ | ||
modal: NgbModalRef; | ||
|
||
@ViewChild('modal') modalTemplate: TemplateRef<unknown>; | ||
|
||
constructor(private ngbModal: NgbModal) { | ||
this.initForm(); | ||
} | ||
|
||
initForm() { | ||
this.rejectForm = new FormGroup({ | ||
comment: new FormControl('', Validators.required), | ||
}); | ||
} | ||
|
||
/** Emits the reject comment data, when the form was valid. */ | ||
submitForm() { | ||
if (this.rejectForm.valid) { | ||
this.submit.emit(this.rejectForm.get('comment').value); | ||
|
||
this.hide(); | ||
} else { | ||
this.submitted = true; | ||
markAsDirtyRecursive(this.rejectForm); | ||
} | ||
} | ||
|
||
/** Opens the modal. */ | ||
show() { | ||
this.modal = this.ngbModal.open(this.modalTemplate); | ||
} | ||
|
||
/** Close the modal. */ | ||
hide() { | ||
this.rejectForm.reset({ | ||
comment: '', | ||
}); | ||
this.submitted = false; | ||
if (this.modal) { | ||
this.modal.close(); | ||
} | ||
} | ||
|
||
get formDisabled() { | ||
return this.rejectForm.invalid && this.submitted; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
9ce9991
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Azure Demo Servers are available: