From 87282a36a405b9c5e3b50d009f74d013395623fb Mon Sep 17 00:00:00 2001 From: David Rajkumar Jayakumar <107850923+DavidJayakumar@users.noreply.github.com> Date: Wed, 23 Aug 2023 13:27:59 +0100 Subject: [PATCH] Move modules (#1549) * Move modules * Fix tests * Remove unwanted changes * Add new test * update version * remove code --- package.json | 2 +- projects/ccd-case-ui-toolkit/package.json | 2 +- .../case-editor/case-editor.module.ts | 8 -- ...ent-completion-task-cancelled.component.ts | 2 +- ...nt-completion-task-reassigned.component.ts | 2 +- .../lib/shared/components/palette/index.ts | 1 + .../components/palette/palette.module.ts | 12 ++- .../query-management/components/index.ts | 5 +- .../query-check-your-answers.component.html | 5 +- ...query-check-your-answers.component.spec.ts | 85 +++++++++++++++++++ .../query-check-your-answers.component.ts | 56 +++++++++++- .../query-details/query-details.component.ts | 2 +- .../query-event-completion.component.html | 3 + .../query-event-completion.component.spec.ts | 25 ++++++ .../query-event-completion.component.ts | 14 +++ 15 files changed, 204 insertions(+), 20 deletions(-) create mode 100644 projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-event-completion/query-event-completion.component.html create mode 100644 projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-event-completion/query-event-completion.component.spec.ts create mode 100644 projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-event-completion/query-event-completion.component.ts diff --git a/package.json b/package.json index d4f14d8e5d..5f33a7ce59 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hmcts/ccd-case-ui-toolkit", - "version": "6.19.3-RetryCaseRetrievals.1", + "version": "6.19.3-qm-respond-event-completion", "engines": { "yarn": "^3.5.0", "npm": "^8.10.0" diff --git a/projects/ccd-case-ui-toolkit/package.json b/projects/ccd-case-ui-toolkit/package.json index 698960c4e5..fc9bd6ad77 100644 --- a/projects/ccd-case-ui-toolkit/package.json +++ b/projects/ccd-case-ui-toolkit/package.json @@ -1,6 +1,6 @@ { "name": "@hmcts/ccd-case-ui-toolkit", - "version": "6.19.3-RetryCaseRetrievals.1", + "version": "6.19.3-qm-respond-event-completion", "engines": { "yarn": "^3.5.0", "npm": "^8.10.0" diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-editor.module.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-editor.module.ts index fb384dedc7..8f534cc384 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-editor.module.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-editor.module.ts @@ -37,11 +37,6 @@ import { CaseEditGenericErrorsComponent } from './case-edit-generic-errors/case- import { CaseEditPageComponent } from './case-edit-page/case-edit-page.component'; import { CaseEditSubmitComponent } from './case-edit-submit/case-edit-submit.component'; import { CaseEditComponent } from './case-edit/case-edit.component'; -import { - CaseEventCompletionComponent, - CaseEventCompletionTaskCancelledComponent, - CaseEventCompletionTaskReassignedComponent -} from './case-event-completion'; import { CaseProgressComponent } from './case-progress/case-progress.component'; import { CaseNotifier, @@ -78,9 +73,6 @@ import { CaseworkerService } from './services/case-worker.service'; CaseEditPageComponent, CaseEditFormComponent, CaseEditSubmitComponent, - CaseEventCompletionComponent, - CaseEventCompletionTaskCancelledComponent, - CaseEventCompletionTaskReassignedComponent, CaseCreateComponent, CaseProgressComponent, CaseEditGenericErrorsComponent diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-event-completion/components/case-event-completion-task-cancelled/case-event-completion-task-cancelled.component.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-event-completion/components/case-event-completion-task-cancelled/case-event-completion-task-cancelled.component.ts index dee1e635b9..1550ecffda 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-event-completion/components/case-event-completion-task-cancelled/case-event-completion-task-cancelled.component.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-event-completion/components/case-event-completion-task-cancelled/case-event-completion-task-cancelled.component.ts @@ -1,5 +1,5 @@ import { Component, Inject } from '@angular/core'; -import { CaseEventCompletionComponent, COMPONENT_PORTAL_INJECTION_TOKEN } from '../../case-event-completion.component'; +import { COMPONENT_PORTAL_INJECTION_TOKEN, CaseEventCompletionComponent } from '../../case-event-completion.component'; @Component({ selector: 'app-case-event-completion-task-cancelled', diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-event-completion/components/case-event-completion-task-reassigned/case-event-completion-task-reassigned.component.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-event-completion/components/case-event-completion-task-reassigned/case-event-completion-task-reassigned.component.ts index ffd9dfe312..a8bfc3213d 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-event-completion/components/case-event-completion-task-reassigned/case-event-completion-task-reassigned.component.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/case-editor/case-event-completion/components/case-event-completion-task-reassigned/case-event-completion-task-reassigned.component.ts @@ -7,7 +7,7 @@ import { SessionStorageService } from '../../../../../services/session/session-s import { CaseworkerService } from '../../../services/case-worker.service'; import { JudicialworkerService } from '../../../services/judicial-worker.service'; import { WorkAllocationService } from '../../../services/work-allocation.service'; -import { CaseEventCompletionComponent, COMPONENT_PORTAL_INJECTION_TOKEN } from '../../case-event-completion.component'; +import { COMPONENT_PORTAL_INJECTION_TOKEN, CaseEventCompletionComponent } from '../../case-event-completion.component'; @Component({ selector: 'app-case-event-completion-task-reassigned', diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/index.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/index.ts index ed4bd8f0e6..416165866c 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/index.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/index.ts @@ -1,3 +1,4 @@ +export * from './../case-editor/case-event-completion'; export * from './address'; export * from './base-field'; export * from './case-file-view'; diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/palette.module.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/palette.module.ts index dbc86f6bd1..b13d1ccda1 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/palette.module.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/palette.module.ts @@ -30,6 +30,7 @@ import { FormValidatorsService } from '../../services/form/form-validators.servi import { JurisdictionService } from '../../services/jurisdiction/jurisdiction.service'; import { LoadingModule } from '../../services/loading/loading.module'; import { WindowService } from '../../services/window'; +import { CaseEventCompletionComponent, CaseEventCompletionTaskCancelledComponent, CaseEventCompletionTaskReassignedComponent } from '../case-editor/case-event-completion'; import { WriteAddressFieldComponent } from './address/write-address-field.component'; import { FieldReadComponent, FieldReadLabelComponent, FieldWriteComponent } from './base-field'; import { CaseFileViewOverlayMenuComponent } from './case-file-view'; @@ -125,6 +126,7 @@ import { QueryCaseDetailsHeaderComponent, QueryCheckYourAnswersComponent, QueryDetailsComponent, + QueryEventCompletionComponent, QueryListComponent, QueryWriteAddDocumentsComponent, QueryWriteDateInputComponent, @@ -263,7 +265,13 @@ const PALETTE_COMPONENTS = [ QueryWriteDateInputComponent, QualifyingQuestionOptionsComponent, QualifyingQuestionDetailComponent, - QueryAttachmentsReadComponent + QueryAttachmentsReadComponent, + QueryEventCompletionComponent, + + // Case event completion + CaseEventCompletionComponent, + CaseEventCompletionTaskCancelledComponent, + CaseEventCompletionTaskReassignedComponent ]; @NgModule({ @@ -313,7 +321,7 @@ const PALETTE_COMPONENTS = [ LanguageInterpreterDisplayPipe, ManageCaseFlagsLabelDisplayPipe, UpdateFlagTitleDisplayPipe, - ...PALETTE_COMPONENTS, + ...PALETTE_COMPONENTS ], exports: [ NgxMatDatetimePickerModule, diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/index.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/index.ts index 19b6cd673c..50b03c4f31 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/index.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/index.ts @@ -1,12 +1,13 @@ export * from './qualifying-questions/qualifying-question-detail/qualifying-question-detail.component'; export * from './qualifying-questions/qualifying-question-options/qualifying-question-options.component'; +export * from './query-attachments-read/query-attachments-read.component'; export * from './query-case-details-header/query-case-details-header.component'; export * from './query-check-your-answers/query-check-your-answers.component'; export * from './query-details/query-details.component'; +export * from './query-event-completion/query-event-completion.component'; export * from './query-list/query-list.component'; -export * from './query-write/query-write-date-input/query-write-date-input.component'; export * from './query-write/query-write-add-documents/query-write-add-documents.component'; export * from './query-write/query-write-date-input/query-write-date-input.component'; export * from './query-write/query-write-raise-query/query-write-raise-query.component'; export * from './query-write/query-write-respond-to-query/query-write-respond-to-query.component'; -export * from './query-attachments-read/query-attachments-read.component'; + diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-check-your-answers/query-check-your-answers.component.html b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-check-your-answers/query-check-your-answers.component.html index 02604a5eff..77f33ee42c 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-check-your-answers/query-check-your-answers.component.html +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-check-your-answers/query-check-your-answers.component.html @@ -114,9 +114,12 @@

(click)="goBack()"> {{ 'Previous' | rpxTranslate }} - + + + diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-check-your-answers/query-check-your-answers.component.spec.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-check-your-answers/query-check-your-answers.component.spec.ts index 6b9f25f284..4ab0a3b83f 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-check-your-answers/query-check-your-answers.component.spec.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-check-your-answers/query-check-your-answers.component.spec.ts @@ -2,6 +2,11 @@ import { CUSTOM_ELEMENTS_SCHEMA, Pipe, PipeTransform } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { FormControl, FormGroup, Validators } from '@angular/forms'; import { By } from '@angular/platform-browser'; +import { ActivatedRoute } from '@angular/router'; +import { BehaviorSubject, of } from 'rxjs'; +import { CaseView, TaskSearchParameter } from '../../../../../../shared/domain'; +import { EventCompletionParams } from '../../../../case-editor/domain/event-completion-params.model'; +import { CaseNotifier, WorkAllocationService } from '../../../../case-editor/services'; import { QueryCreateContext, QueryListItem } from '../../models'; import { QueryCheckYourAnswersComponent } from './query-check-your-answers.component'; @@ -16,6 +21,9 @@ describe('QueryCheckYourAnswersComponent', () => { let component: QueryCheckYourAnswersComponent; let fixture: ComponentFixture; let nativeElement: any; + let casesService: any; + let caseNotifier: any; + let workAllocationService: any; const items = [ { @@ -113,12 +121,69 @@ describe('QueryCheckYourAnswersComponent', () => { ] }); + const snapshotActivatedRoute = { + snapshot: { + params: { + qid: '1' + } + } + }; + + const CASE_VIEW: CaseView = { + case_id: '1', + case_type: { + id: 'TestAddressBookCase', + name: 'Test Address Book Case', + jurisdiction: { + id: 'TEST', + name: 'Test', + } + }, + channels: [], + state: { + id: 'CaseCreated', + name: 'Case created' + }, + tabs: [], + triggers: [], + events: [] + }; + + const response = { + tasks: [{ + additional_properties: { + additionalProp1: '1' + }, + assignee: '12345', + case_id: '1', + case_name: 'Alan Jonson', + created_date: '2021-04-19T14:00:00.000+0000', + due_date: '2021-05-20T16:00:00.000+0000', + id: 'Task_2', + jurisdiction: 'Immigration and Asylum', + case_category: 'asylum', + name: 'Task name', + permissions: null + }] + }; + beforeEach(async () => { + workAllocationService = jasmine.createSpyObj('WorkAllocationService', ['searchTasks']); + workAllocationService.searchTasks.and.returnValue(of(response)); + casesService = jasmine.createSpyObj('casesService', ['getCaseViewV2']); + caseNotifier = new CaseNotifier(casesService); + caseNotifier.caseView = new BehaviorSubject(CASE_VIEW).asObservable(); + await TestBed.configureTestingModule({ schemas: [CUSTOM_ELEMENTS_SCHEMA], declarations: [ QueryCheckYourAnswersComponent, RpxTranslateMockPipe + ], + providers: [ + { provide: ActivatedRoute, useValue: snapshotActivatedRoute }, + { provide: WorkAllocationService, useValue: workAllocationService }, + { provide: CaseNotifier, useValue: caseNotifier } ] }) .compileComponents(); @@ -188,4 +253,24 @@ describe('QueryCheckYourAnswersComponent', () => { expect(columnHeadings[0].nativeElement.textContent.trim()).toEqual('Query detail'); expect(columnHeadings[1].nativeElement.textContent.trim()).toEqual('Document attached'); }); + + describe('submit', () => { + it('should call search task', () => { + component.submit(); + fixture.detectChanges(); + const searchParameter = { ccdId: '1' } as TaskSearchParameter; + expect(workAllocationService.searchTasks).toHaveBeenCalledWith(searchParameter); + }); + + it('should trigger event completion', () => { + component.submit(); + fixture.detectChanges(); + const eventCompletionParams: EventCompletionParams = { + caseId: '1', + eventId: 'respondToQuery', + task: response.tasks[0] + }; + expect(component.eventCompletionParams).toEqual(eventCompletionParams); + }); + }); }); diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-check-your-answers/query-check-your-answers.component.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-check-your-answers/query-check-your-answers.component.ts index ef76183034..b2e59f4027 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-check-your-answers/query-check-your-answers.component.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-check-your-answers/query-check-your-answers.component.ts @@ -1,5 +1,11 @@ -import { Component, EventEmitter, Input, Output } from '@angular/core'; +import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core'; import { FormGroup } from '@angular/forms'; +import { ActivatedRoute } from '@angular/router'; +import { Subscription } from 'rxjs'; +import { take } from 'rxjs/operators'; +import { TaskSearchParameter } from '../../../../../../../lib/shared/domain'; +import { EventCompletionParams } from '../../../../case-editor/domain/event-completion-params.model'; +import { CaseNotifier, WorkAllocationService } from '../../../../case-editor/services'; import { QueryCreateContext, QueryListItem } from '../../models'; @Component({ @@ -7,14 +13,60 @@ import { QueryCreateContext, QueryListItem } from '../../models'; templateUrl: './query-check-your-answers.component.html', styleUrls: ['./query-check-your-answers.component.scss'] }) -export class QueryCheckYourAnswersComponent { +export class QueryCheckYourAnswersComponent implements OnInit, OnDestroy { @Input() public formGroup: FormGroup; @Input() public queryItem: QueryListItem; @Input() public queryCreateContext: QueryCreateContext; @Output() public backClicked = new EventEmitter(); public queryCreateContextEnum = QueryCreateContext; + public eventCompletionParams: EventCompletionParams; + private caseId: string; + private eventId: string; + private queryId: string; + private searchTasksSubsciption: Subscription; + + constructor( + private readonly route: ActivatedRoute, + private readonly workAllocationService: WorkAllocationService, + private readonly caseNotifier: CaseNotifier) { } + + public ngOnInit(): void { + this.queryId = this.route.snapshot.params.qid; + this.caseNotifier.caseView.pipe(take(1)).subscribe(caseDetails => { + this.caseId = caseDetails.case_id; + // To be set after integration + this.eventId = 'respondToQuery'; + }); + } + + public ngOnDestroy(): void { + this.searchTasksSubsciption?.unsubscribe(); + } + public goBack(): void { this.backClicked.emit(true); } + + public submit(): void { + // Search Task + const searchParameter = { ccdId: this.caseId } as TaskSearchParameter; + this.searchTasksSubsciption = this.workAllocationService.searchTasks(searchParameter) + .subscribe((response: any) => { + // Filter task by query id + const filteredtask = response.tasks?.find((task) => { + return Object.values(task.additional_properties).some((value) => { + if (value === this.queryId) { + return task; + } + }); + }); + // Trigger event completion + this.eventCompletionParams = { + caseId: this.caseId, + eventId: this.eventId, + task: filteredtask + }; + }); + } } diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-details/query-details.component.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-details/query-details.component.ts index ca0a73c612..ab151fb3d6 100644 --- a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-details/query-details.component.ts +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-details/query-details.component.ts @@ -22,6 +22,6 @@ export class QueryDetailsComponent { const userDetails = JSON.parse(this.sessionStorage.getItem('userDetails')); return userDetails && userDetails.roles && !(userDetails.roles.includes('pui-case-manager') - || userDetails.roles.some((role) => role.toLowerCase().includes('judge'))) + || userDetails.roles.some((role) => role.toLowerCase().includes('judge'))); } } diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-event-completion/query-event-completion.component.html b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-event-completion/query-event-completion.component.html new file mode 100644 index 0000000000..89cc4ce0b9 --- /dev/null +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-event-completion/query-event-completion.component.html @@ -0,0 +1,3 @@ + + \ No newline at end of file diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-event-completion/query-event-completion.component.spec.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-event-completion/query-event-completion.component.spec.ts new file mode 100644 index 0000000000..ca9c039ef1 --- /dev/null +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-event-completion/query-event-completion.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { QueryEventCompletionComponent } from './query-event-completion.component'; + +describe('QueryEventCompletionComponent', () => { + let component: QueryEventCompletionComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ QueryEventCompletionComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(QueryEventCompletionComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-event-completion/query-event-completion.component.ts b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-event-completion/query-event-completion.component.ts new file mode 100644 index 0000000000..567ede5128 --- /dev/null +++ b/projects/ccd-case-ui-toolkit/src/lib/shared/components/palette/query-management/components/query-event-completion/query-event-completion.component.ts @@ -0,0 +1,14 @@ +import { Component, Input } from '@angular/core'; +import { EventCompletionParams } from '../../../../case-editor/domain/event-completion-params.model'; + +@Component({ + selector: 'ccd-query-event-completion', + templateUrl: './query-event-completion.component.html' +}) +export class QueryEventCompletionComponent { + @Input() public eventCompletionParams: EventCompletionParams; + + public onEventCanBeCompleted(value: boolean): void { + // Submit the query response + } +}