Skip to content

Commit

Permalink
error handling message added
Browse files Browse the repository at this point in the history
  • Loading branch information
OgunyemiO committed Jul 23, 2024
1 parent 0cdd0fb commit ea48f00
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hmcts/rpx-xui-common-lib",
"version": "2.0.24",
"version": "2.0.24-banner-message-date-error-handling",
"engines": {
"node": ">=18.19.0"
},
Expand Down
2 changes: 1 addition & 1 deletion projects/exui-common-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hmcts/rpx-xui-common-lib",
"version": "2.0.24",
"version": "2.0.24-banner-message-date-error-handling",
"peerDependencies": {
"launchdarkly-js-client-sdk": "^3.3.0",
"ngx-pagination": "^3.2.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
<div *ngIf="filteredMessages?.length > 0" class="govuk-width-container govuk-!-margin-top-6">
<div *ngIf="isBannerError" class="hmcts-banner hmcts-banner--warning">
<svg class="hmcts-banner__icon" fill="currentColor" role="presentation" focusable="false"
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 25 25" height="25" width="25">
<path d="M13.6,15.4h-2.3v-4.5h2.3V15.4z M13.6,19.8h-2.3v-2.2h2.3V19.8z M0,23.2h25L12.5,2L0,23.2z" />
</svg>
<div class="hmcts-banner__message">
<span class="hmcts-banner__assistive">{{'Warning' | rpxTranslate}}</span>
<h2 class="govuk-heading-s">Error:</h2>
<p>{{bannerErrorMsg}}</p>
</div>
</div>

<xuilib-service-message *ngFor="let message of filteredMessages" [key]="message"
[message_en]="message?.message_en | rpxTranslate"
[message_cy]="message?.message_cy | rpxTranslate"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,41 @@ describe('ServiceMessagesComponent', () => {
expect((component.hiddenBanners).length).toBe(1);
});
});

it('should show error message if start date is greater than the end date', () => {
const serviceMessagesFake: ServiceMessages[] = [
{
roles: 'caseworker-divorce',
index: 2,
message_en: 'Judiciary experience required',
message_cy: 'Anyyu',
begin: '2024-04-25T00:00:00',
end: '2024-04-24T00:00:00'
}
];
component['createFilteredMessages'](serviceMessagesFake);
fixture.autoDetectChanges();
expect(component.filteredMessages.length).toBe(0);
fixture.detectChanges();
expect(component.isBannerError).toBeTruthy();
expect(component.bannerErrorMsg).toContain(`The start date is greater than the end date for message index: ${serviceMessagesFake[0].index}`);
});
it('should show error message if start date or end date is not well formed', () => {
const serviceMessagesFake: ServiceMessages[] = [
{
roles: 'caseworker-divorce',
index: 10,
message_en: 'Malformed start or end date',
message_cy: 'Incorrect date',
begin: '2024-04-25 T00:00:00',
end: '2024-04-24T00:00:00'
}
];
component['createFilteredMessages'](serviceMessagesFake);
fixture.autoDetectChanges();
expect(component.filteredMessages.length).toBe(0);
fixture.detectChanges();
expect(component.isBannerError).toBeTruthy();
expect(component.bannerErrorMsg).toContain(`Invalid start or end date for message index: 10`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { ServiceMessages } from '../../models/service-message.model';
export class ServiceMessagesComponent implements OnInit {
public hiddenBanners: string[];
public filteredMessages: ServiceMessages[] = [];
public isBannerError: boolean;
public bannerErrorMsg: string = '';

@Input() public userRoles: string[];
@Input() public featureToggleKey: string;
Expand Down Expand Up @@ -53,6 +55,14 @@ export class ServiceMessagesComponent implements OnInit {
if (!isNaN(Date.parse(msg.end))) {
endDate = new Date(msg.end);
}
if (!isNaN(Date.parse(msg.begin)) && !isNaN(Date.parse(msg.end)) && beginDate > endDate) {
this.isBannerError = true;
this.bannerErrorMsg = `The start date is greater than the end date for message index: ${msg.index}`;
}
if (isNaN(Date.parse(msg.begin)) || isNaN(Date.parse(msg.end))) {
this.isBannerError = true;
this.bannerErrorMsg = `Invalid start or end date for message index: ${msg.index}`;
}

const beginDateOK = !msg.begin || (beginDate && beginDate < currentDateTime);
const endDateOK = !msg.end || (endDate && endDate >= currentDateTime);
Expand Down

0 comments on commit ea48f00

Please sign in to comment.