Skip to content

Commit

Permalink
refactor codebase to get data from event data (#1774)
Browse files Browse the repository at this point in the history
* refactor codebase to get data from  event data

* code tidy

* code tidy

* GUID added to caseMessage ID
  • Loading branch information
olusegz07 authored Sep 27, 2024
1 parent 12aeecf commit 3f49f15
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 117 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<!-- Error message summary -->
<div *ngIf="errorMessages.length > 0" class="govuk-error-summary"
aria-labelledby="error-summary-title" role="alert" tabindex="-1"
data-module="govuk-error-summary">
<h2 class="govuk-error-summary__title" id="error-summary-title">
{{ 'There is a problem' | rpxTranslate }}
</h2>
<div class="govuk-error-summary__body">
<ul class="govuk-list govuk-error-summary__list">
<li *ngFor="let errorMessage of errorMessages">
<a [id]="'error-' + errorMessage.fieldId" href="javascript:void(0)"
class="validation-error">{{ errorMessage.description | rpxTranslate }}</a>
</li>
</ul>
</div>
</div>

<ng-container *ngIf="queryCreateContext === queryCreateContextEnum.NEW_QUERY">
<div class="govuk-caption-l">{{ 'Raise a query' | rpxTranslate }}</div>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { FormControl, FormGroup, Validators } from '@angular/forms';
import { By } from '@angular/platform-browser';
import { ActivatedRoute, Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { BehaviorSubject, of } from 'rxjs';
import { CaseView, TaskSearchParameter } from '../../../../../../shared/domain';
import { BehaviorSubject, of, throwError } from 'rxjs';
import { CaseField, CaseView, FieldType, TaskSearchParameter } from '../../../../../../shared/domain';
import { SessionStorageService } from '../../../../../services';
import { EventCompletionParams } from '../../../../case-editor/domain/event-completion-params.model';
import { CaseNotifier, CasesService, WorkAllocationService } from '../../../../case-editor/services';
Expand Down Expand Up @@ -317,14 +317,73 @@ describe('QueryCheckYourAnswersComponent', () => {
name: 'Smith Solicitor'
};

const eventData = {
...eventTrigger,
case_fields: [
{
field_type: {
collection_field_type: null,
complex_fields: [],
fixed_list_items: [],
id: 'ComponentLauncher',
max: null,
min: null,
regular_expression: null,
type: 'ComponentLauncher'
} as FieldType,
id: 'QueryManagement1',
label: 'Query management component'
} as CaseField,
{
field_type: {
collection_field_type: null,
complex_fields: [],
fixed_list_items: [],
id: 'CaseQueriesCollection',
max: null,
min: null,
regular_expression: null,
type: 'Complex'
} as FieldType,
id: 'qmCaseQueriesCollection',
label: 'Query management case queries collection',
value: {
caseMessages: [{
id: '42ea7fd3-178c-4584-b48b-f1275bf1804f',
value: {
attachments: [],
body: 'testing by olu',
createdBy: '120b3665-0b8a-4e80-ace0-01d8d63c1005',
createdOn: '2024-08-27T15:44:50.700Z',
hearingDate: '2023-01-10',
id: null,
isHearingRelated: 'Yes',
name: 'Piran Sam',
parentId: 'ca',
subject: 'Review attached document'
}
}],
partyName: '',
roleOnCase: ''
}
} as CaseField
],
wizard_pages: [],
hasFields(): boolean {
return true;
},
hasPages(): boolean {
return false;
}
};

beforeEach(async () => {
router = jasmine.createSpyObj('Router', ['navigate']);
workAllocationService = jasmine.createSpyObj('WorkAllocationService', ['searchTasks']);
workAllocationService.searchTasks.and.returnValue(of(response));
sessionStorageService = jasmine.createSpyObj<SessionStorageService>('sessionStorageService', ['getItem']);
sessionStorageService.getItem.and.returnValue(JSON.stringify(userDetails));
casesService = jasmine.createSpyObj('casesService', ['getEventTrigger', 'createEvent', 'getCaseViewV2']);
casesService.getEventTrigger.and.returnValue(of(eventTrigger));
casesService = jasmine.createSpyObj('casesService', ['createEvent', 'getCaseViewV2']);
casesService.createEvent.and.returnValue(of({ status: 200 }));
caseNotifier = new CaseNotifier(casesService);
caseNotifier.caseView = new BehaviorSubject(CASE_VIEW).asObservable();
Expand Down Expand Up @@ -416,31 +475,42 @@ describe('QueryCheckYourAnswersComponent', () => {
expect(columnHeadings[1].nativeElement.textContent.trim()).toEqual('Document attached');
});

it('should query submission failure navigate to service down page', () => {
it('should navigate to service-down page on event creation error', () => {
component.fieldId = 'validFieldId';
casesService.createEvent.and.returnValue(throwError('Error'));

component.submit();

expect(router.navigate).toHaveBeenCalledWith(['/', 'service-down']);
});

it('should set querySubmitted to true when submit is called', () => {
caseNotifier.caseView = new BehaviorSubject(CASE_VIEW_OTHER).asObservable();
fixture.detectChanges();
component.ngOnInit();
it('should log an error and set errorMessages when fieldId is missing', () => {
component.fieldId = null;
spyOn(console, 'error');

spyOn(component.querySubmitted, 'emit');
component.submit();

expect(component.querySubmitted.emit).toHaveBeenCalledWith(true);
expect(console.error).toHaveBeenCalledWith('Error: Field ID is missing. Cannot proceed with submission.');
expect(component.errorMessages).toEqual([
{
title: 'Error',
description: 'Something unexpected happened. please try again later.',
fieldId: 'field-id'
}
]);
});

it('should set querySubmitted to true when submit is called', () => {
caseNotifier.caseView = new BehaviorSubject(CASE_VIEW_OTHER).asObservable();

component.eventData = eventData;
fixture.detectChanges();
component.ngOnInit();

component.fieldId = null;
spyOn(component.querySubmitted, 'emit');
component.submit();

expect(router.navigate).toHaveBeenCalledWith(['/', 'service-down']);
expect(component.querySubmitted.emit).toHaveBeenCalledWith(true);
});

describe('searchAndCompleteTask', () => {
Expand Down
Loading

0 comments on commit 3f49f15

Please sign in to comment.