Skip to content

Commit

Permalink
97 revised plan year end date display (#98)
Browse files Browse the repository at this point in the history
* working on end dates for prior years

* update coverage end date showing for previous year policies

* Remove unused pipe

* Update operator to be less than current year

* update template to use new pipe for policyEndDate check and format

* add unit test for policy-end-date format

* update pipe with performance improvement
  • Loading branch information
bbodine1 authored Oct 30, 2023
1 parent eafd1d6 commit 12e558c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,19 @@ <h3>Enrollment Group</h3>
</td>
<td>{{ t('relationships.' + enrollee.relationship) | titlecase }}</td>
<td>
{{ enrollee.coverage_start | date : 'M/d/yy' }}
- {{ (enrollee.coverage_end | date : 'M/d/yy') ?? '' }}
{{ enrollee.coverage_start | date : 'M/d/yy' }} -
<ng-container
*ngIf="enrollee.coverage_end; then endGiven; else noEndGiven"
>
</ng-container>

<ng-template #endGiven>
{{ enrollee.coverage_end | date : 'M/d/yy' }}
</ng-template>

<ng-template #noEndGiven>
{{ enrollee.coverage_start | policyEndDate }}
</ng-template>
</td>
<td>{{ enrollee.carrier_member_id }}</td>
<td>{{ enrollee.carrier_policy_id }}</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { TranslocoModule } from '@ngneat/transloco';

import { Policy } from '@enroll/carrier-portal/types';

import { SortByDatePipe } from '../pipes';
import { SortByDatePipe, PolicyEndDatePipe } from '../pipes';

@Component({
selector: 'enroll-member-policy',
Expand All @@ -23,6 +23,7 @@ import { SortByDatePipe } from '../pipes';
DatePipe,
CurrencyPipe,
SortByDatePipe,
PolicyEndDatePipe,
TranslocoModule,
TitleCasePipe,
],
Expand Down
1 change: 1 addition & 0 deletions libs/carrier-portal/ui/src/lib/pipes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './phone-number.pipe';
export * from './sort-by-date.pipe';
export * from './sort-by-status.pipe';
export * from './sort-by-policy-start.pipe';
export * from './policy-end-date.pipe';
31 changes: 31 additions & 0 deletions libs/carrier-portal/ui/src/lib/pipes/policy-end-date.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { PolicyEndDatePipe } from './policy-end-date.pipe';

describe('PolicyEndDatePipe', () => {
let pipe: PolicyEndDatePipe;
const currentYear = new Date();
const thisYear = currentYear.toString();
const futureYear = (currentYear.getFullYear() + 1).toString();
const previousYear = (currentYear.getFullYear() - 1).toString();

beforeEach(() => {
pipe = new PolicyEndDatePipe();
});

it('returns an empty string if the current year is equal to the given year', () => {
const policyStartDate = thisYear;
expect(pipe.transform(policyStartDate)).toBe('');
});

it('returns an empty string if the current year is greater than the given year', () => {
const policyStartDate = futureYear;
expect(pipe.transform(policyStartDate)).toBe('');
});

it('returns the last day of the year for the given date if the given year is less than the current year', () => {
// const policyStartDate = '2021-03-01';
const policyStartDate = previousYear;
expect(pipe.transform(policyStartDate)).toBe(
`12/31/${previousYear.substring(2, 4)}`
);
});
});
17 changes: 17 additions & 0 deletions libs/carrier-portal/ui/src/lib/pipes/policy-end-date.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { Pipe, PipeTransform } from '@angular/core';

type DateString = string;

@Pipe({
name: 'policyEndDate',
standalone: true,
})
export class PolicyEndDatePipe implements PipeTransform {
currentYear = new Date().getFullYear().toString().substring(2, 4);
transform(value: DateString) {
const policyStartYear = value.substring(2, 4);

return policyStartYear < this.currentYear ? `12/31/${policyStartYear}` : '';
}
}

0 comments on commit 12e558c

Please sign in to comment.