Skip to content

Commit

Permalink
AC04 AC05 AC06 and unit test covered
Browse files Browse the repository at this point in the history
  • Loading branch information
OgunyemiO committed Aug 21, 2024
1 parent 7a342a2 commit 13c2092
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,36 @@ describe('ServiceMessagesComponent', () => {
index: 2,
message_en: 'Happy birthday.',
message_cy: 'Anyyu',
begin: '',
end: ''
}
];
component['createFilteredMessages'](serviceMessagesFake);
fixture.autoDetectChanges();
expect(component.filteredMessages.length).toBe(1);
});

it('should show message when no start date provided', () => {
const serviceMessagesFake: ServiceMessages[] = [
{
roles: 'caseworker-divorce',
index: 2,
message_en: 'Happy birthday.',
message_cy: 'Anyyu',
end: '2044-04-20T00:00:00'
}
];
component['createFilteredMessages'](serviceMessagesFake);
fixture.autoDetectChanges();
expect(component.filteredMessages.length).toBe(1);
});

it('should show message when no end date provided', () => {
const serviceMessagesFake: ServiceMessages[] = [
{
roles: 'caseworker-divorce',
index: 12,
message_en: 'Happy birthday.',
message_cy: 'Anyyu',
begin: '2024-04-20T00:00:00'
}
];
component['createFilteredMessages'](serviceMessagesFake);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,35 @@ export class ServiceMessagesComponent implements OnInit {
let endDate = null;
const findUnique = this.bannerErrorMsgs.filter(rst => rst.index === msg.index);

if (!isNaN(Date.parse(msg.begin))) {
if (msg.begin !== undefined && !isNaN(Date.parse(msg.begin))) {
beginDate = new Date(msg.begin);
}

if (!isNaN(Date.parse(msg.end))) {
if (msg.end !== undefined && !isNaN(Date.parse(msg.end))) {
endDate = new Date(msg.end);
}

if (!isNaN(Date.parse(msg.begin)) && !isNaN(Date.parse(msg.end)) && !(beginDate > endDate)) {
this.bannerErrorMsgs = this.bannerErrorMsgs.filter(ind => ind.index !== msg.index);
}
}

if ((!isNaN(Date.parse(msg.begin)) && !isNaN(Date.parse(msg.end)) && beginDate > endDate)
|| (isNaN(Date.parse(msg.begin)) || isNaN(Date.parse(msg.end)))) {
if ((msg.begin || msg.end) && (
(!isNaN(Date.parse(msg.begin)) && !isNaN(Date.parse(msg.end)) && beginDate > endDate)
|| (msg.begin && isNaN(Date.parse(msg.begin)))
|| (msg.end && isNaN(Date.parse(msg.end)))
)) {
this.isBannerError = true;
if(findUnique.length === 0) {
this.bannerErrorMsgs = [...this.bannerErrorMsgs, {message:`Invalid start/end date OR The start date is greater than the end date. Message index: ${msg.index}`, index: msg.index}];
}
} else {
this.isBannerError = false;
}

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

return beginDateOK && endDateOK;
}

public hideMessage(msg: ServiceMessages): void {
this.filteredMessages = this.filteredMessages.filter(f => f.index !== msg.index)
Expand Down

0 comments on commit 13c2092

Please sign in to comment.