Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
@if (selectedOffenceConfirmation) {
@if (offenceCode.count === 1) {
<ng-container
*ngTemplateOutlet="offenceCodeHint; context: { found: true, offenceTitle: offenceCode.refData[0].offence_title }"
></ng-container>
@if (matchedOffenceTitle; as offenceTitle) {
<ng-container *ngTemplateOutlet="offenceCodeHint; context: { found: true, offenceTitle: offenceTitle }"></ng-container>
} @else {
<ng-container *ngTemplateOutlet="offenceCodeHint; context: { found: false }"></ng-container>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe('FinesMacOffenceCodeHintComponent', () => {

it('should render component with both inputs provided', () => {
fixture.componentRef.setInput('offenceCode', mockOffenceCode);
fixture.componentRef.setInput('searchedOffenceCode', 'AK123456');
fixture.componentRef.setInput('selectedOffenceConfirmation', true);
fixture.detectChanges();

Expand All @@ -70,6 +71,7 @@ describe('FinesMacOffenceCodeHintComponent', () => {
it('should maintain component state through input changes', () => {
// Initial state
fixture.componentRef.setInput('offenceCode', mockOffenceCode);
fixture.componentRef.setInput('searchedOffenceCode', 'AK123456');
fixture.componentRef.setInput('selectedOffenceConfirmation', false);
fixture.detectChanges();

Expand All @@ -82,4 +84,76 @@ describe('FinesMacOffenceCodeHintComponent', () => {
expect(component.selectedOffenceConfirmation).toBe(true);
expect(component.offenceCode).toEqual(mockOffenceCode);
});

it('should render Offence found when the searched code matches one result exactly', () => {
const multipleMatchResponse: IOpalFinesOffencesRefData = {
count: 4,
refData: [
{
offence_id: 41799,
get_cjs_code: 'CD71039',
business_unit_id: 52,
offence_title: 'Criminal damage to property valued under £5000',
offence_title_cy: null,
date_used_from: '1997-11-16T00:00:00Z',
date_used_to: null,
offence_oas: 'Contrary to sections 1(1) and 4 of the Criminal Damage Act 1971.',
offence_oas_cy: null,
},
{
offence_id: 30733,
get_cjs_code: 'CD71039A',
business_unit_id: 52,
offence_title: 'Attempt criminal damage to property valued under £5000',
offence_title_cy: null,
date_used_from: '1971-01-01T00:00:00Z',
date_used_to: null,
offence_oas: 'Contrary to section 1(1) of the Criminal Attempts Act 1981.',
offence_oas_cy: null,
},
{
offence_id: 30734,
get_cjs_code: 'CD71039B',
business_unit_id: 52,
offence_title: 'Aid, abet, counsel and procure damage under £5000',
offence_title_cy: null,
date_used_from: '1971-01-01T00:00:00Z',
date_used_to: null,
offence_oas: 'Contrary to sections 1(1) and 4 of the Criminal Damage Act 1971.',
offence_oas_cy: null,
},
{
offence_id: 30735,
get_cjs_code: 'CD71039C',
business_unit_id: 52,
offence_title: 'Conspiracy to destroy or damage property under £5000',
offence_title_cy: null,
date_used_from: '1971-01-01T00:00:00Z',
date_used_to: '2004-12-25T00:00:00Z',
offence_oas: 'Contrary to section 1 of the Criminal Law Act 1977.',
offence_oas_cy: null,
},
],
};

fixture.componentRef.setInput('offenceCode', multipleMatchResponse);
fixture.componentRef.setInput('searchedOffenceCode', 'CD71039');
fixture.componentRef.setInput('selectedOffenceConfirmation', true);
fixture.detectChanges();

const textContent = fixture.nativeElement.textContent;
expect(textContent).toContain('Offence found');
expect(textContent).toContain('Criminal damage to property valued under £5000');
});

it('should render Offence not found when there is no exact code match', () => {
fixture.componentRef.setInput('offenceCode', mockOffenceCode);
fixture.componentRef.setInput('searchedOffenceCode', 'AK12345');
fixture.componentRef.setInput('selectedOffenceConfirmation', true);
fixture.detectChanges();

const textContent = fixture.nativeElement.textContent;
expect(textContent).toContain('Offence not found');
expect(textContent).toContain('Enter a valid offence code');
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { NgTemplateOutlet } from '@angular/common';
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { ChangeDetectionStrategy, Component, Input, inject } from '@angular/core';
import { MojTicketPanelComponent } from '@hmcts/opal-frontend-common/components/moj/moj-ticket-panel';
import { IOpalFinesOffencesRefData } from '@services/fines/opal-fines-service/interfaces/opal-fines-offences-ref-data.interface';
import { FinesMacOffenceDetailsService } from '../../fines-mac-offence-details/services/fines-mac-offence-details.service';

@Component({
selector: 'app-fines-mac-offence-code-hint',
Expand All @@ -10,6 +11,13 @@ import { IOpalFinesOffencesRefData } from '@services/fines/opal-fines-service/in
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class FinesMacOffenceCodeHintComponent {
private readonly offenceDetailsService = inject(FinesMacOffenceDetailsService);

@Input() public offenceCode!: IOpalFinesOffencesRefData;
@Input() public searchedOffenceCode: string | null = null;
@Input() public selectedOffenceConfirmation!: boolean;

public get matchedOffenceTitle(): string | null {
return this.offenceDetailsService.findExactOffenceMatch(this.offenceCode, this.searchedOffenceCode)?.offence_title ?? null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ <h2 class="govuk-heading-m govuk-!-margin-0">Offence Details</h2>
@if (offenceCode$ | async; as offenceCode) {
<app-fines-mac-offence-code-hint
[offenceCode]="offenceCode"
[searchedOffenceCode]="form.controls['fm_fp_offence_details_offence_cjs_code'].value"
[selectedOffenceConfirmation]="selectedOffenceConfirmation"
></app-fines-mac-offence-code-hint>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ <h2 class="govuk-label-wrapper">
@if (offenceCode$ | async; as offenceCode) {
<app-fines-mac-offence-code-hint
[offenceCode]="offenceCode"
[searchedOffenceCode]="form.get('fm_offence_details_offence_cjs_code')?.value"
[selectedOffenceConfirmation]="selectedOffenceConfirmation"
></app-fines-mac-offence-code-hint>
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { FinesMacOffenceDetailsReviewOffenceHeadingTitleComponent } from './fines-mac-offence-details-review-offence-heading-title.component';
import { IOpalFinesOffencesRefData } from '@services/fines/opal-fines-service/interfaces/opal-fines-offences-ref-data.interface';
import { OPAL_FINES_OFFENCES_REF_DATA_SINGULAR_MOCK } from '@services/fines/opal-fines-service/mocks/opal-fines-offences-ref-data-singular.mock';
import { beforeEach, describe, expect, it, vi } from 'vitest';

Expand All @@ -16,6 +17,7 @@ describe('FinesMacOffenceDetailsReviewOffenceHeadingTitleComponent', () => {
fixture = TestBed.createComponent(FinesMacOffenceDetailsReviewOffenceHeadingTitleComponent);
component = fixture.componentInstance;

component.offenceCode = OPAL_FINES_OFFENCES_REF_DATA_SINGULAR_MOCK.refData[0].get_cjs_code;
component.offenceRefData = OPAL_FINES_OFFENCES_REF_DATA_SINGULAR_MOCK;

fixture.detectChanges();
Expand All @@ -40,4 +42,63 @@ describe('FinesMacOffenceDetailsReviewOffenceHeadingTitleComponent', () => {

expect(component.offenceTitle).toEqual(component.offenceRefData.refData[0].offence_title);
});

it('should use the exact code match when multiple offences are returned', () => {
const multiResultResponse: IOpalFinesOffencesRefData = {
count: 4,
refData: [
{
offence_id: 41799,
get_cjs_code: 'CD71039',
business_unit_id: 52,
offence_title: 'Criminal damage to property valued under £5000',
offence_title_cy: null,
date_used_from: '1997-11-16T00:00:00Z',
date_used_to: null,
offence_oas: 'Contrary to sections 1(1) and 4 of the Criminal Damage Act 1971.',
offence_oas_cy: null,
},
{
offence_id: 30733,
get_cjs_code: 'CD71039A',
business_unit_id: 52,
offence_title: 'Attempt criminal damage to property valued under £5000',
offence_title_cy: null,
date_used_from: '1971-01-01T00:00:00Z',
date_used_to: null,
offence_oas: 'Contrary to section 1(1) of the Criminal Attempts Act 1981.',
offence_oas_cy: null,
},
{
offence_id: 30734,
get_cjs_code: 'CD71039B',
business_unit_id: 52,
offence_title: 'Aid, abet, counsel and procure damage under £5000',
offence_title_cy: null,
date_used_from: '1971-01-01T00:00:00Z',
date_used_to: null,
offence_oas: 'Contrary to sections 1(1) and 4 of the Criminal Damage Act 1971.',
offence_oas_cy: null,
},
{
offence_id: 30735,
get_cjs_code: 'CD71039C',
business_unit_id: 52,
offence_title: 'Conspiracy to destroy or damage property under £5000',
offence_title_cy: null,
date_used_from: '1971-01-01T00:00:00Z',
date_used_to: '2004-12-25T00:00:00Z',
offence_oas: 'Contrary to section 1 of the Criminal Law Act 1977.',
offence_oas_cy: null,
},
],
};

component.offenceCode = 'CD71039';
component.offenceRefData = multiResultResponse;

component.getOffenceTitle();

expect(component.offenceTitle).toEqual('Criminal damage to property valued under £5000');
});
});
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { CommonModule } from '@angular/common';
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output, inject } from '@angular/core';
import { GovukHeadingWithCaptionComponent } from '@hmcts/opal-frontend-common/components/govuk/govuk-heading-with-caption';
import {
GovukSummaryListRowActionItemComponent,
GovukSummaryListRowActionsComponent,
} from '@hmcts/opal-frontend-common/components/govuk/govuk-summary-list';
import { IOpalFinesOffencesRefData } from '@services/fines/opal-fines-service/interfaces/opal-fines-offences-ref-data.interface';
import { FinesMacOffenceDetailsService } from '../../../services/fines-mac-offence-details.service';

@Component({
selector: 'app-fines-mac-offence-details-review-offence-heading-title',
Expand All @@ -20,6 +21,8 @@ import { IOpalFinesOffencesRefData } from '@services/fines/opal-fines-service/in
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class FinesMacOffenceDetailsReviewOffenceHeadingTitleComponent implements OnInit {
private readonly offenceDetailsService = inject(FinesMacOffenceDetailsService);

@Input({ required: true }) public offenceCode!: string;
@Input({ required: true }) public offenceRefData!: IOpalFinesOffencesRefData;
@Input({ required: false }) public showActions!: boolean;
Expand All @@ -41,7 +44,8 @@ export class FinesMacOffenceDetailsReviewOffenceHeadingTitleComponent implements
* Retrieves the offence title from the offence reference data and assigns it to the `offenceTitle` property.
*/
public getOffenceTitle(): void {
this.offenceTitle = this.offenceRefData.refData[0].offence_title;
const exactMatch = this.offenceDetailsService.findExactOffenceMatch(this.offenceRefData, this.offenceCode);
this.offenceTitle = exactMatch?.offence_title ?? this.offenceRefData.refData[0]?.offence_title ?? '';
}

public ngOnInit(): void {
Expand Down
Loading
Loading