From f2eb88be8534f7367857a5ce495242fb6d1d9397 Mon Sep 17 00:00:00 2001 From: Peng Date: Tue, 28 Nov 2023 08:42:25 -0800 Subject: [PATCH] code modification 3 --- ppr-ui/src/components/unitNotes/UnitNoteHeaderInfo.vue | 5 +++-- ppr-ui/src/composables/mhrInformation/useMhrUnitNote.ts | 9 +++++---- ppr-ui/tests/unit/UnitNotePanels.spec.ts | 6 +++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/ppr-ui/src/components/unitNotes/UnitNoteHeaderInfo.vue b/ppr-ui/src/components/unitNotes/UnitNoteHeaderInfo.vue index 749fd4351..13f87e127 100644 --- a/ppr-ui/src/components/unitNotes/UnitNoteHeaderInfo.vue +++ b/ppr-ui/src/components/unitNotes/UnitNoteHeaderInfo.vue @@ -22,7 +22,7 @@ import { defineComponent, reactive, computed, toRefs } from 'vue-demi' import { MhUIStatusTypes, UnitNoteDocTypes, UnitNoteStatusTypes } from '@/enums' import { UnitNotesInfo, cancelledWithRedemptionNote } from '@/resources' import { UnitNoteIF } from '@/interfaces/unit-note-interfaces/unit-note-interface' -import { pacificDate } from '@/utils' +import { localTodayDate, pacificDate } from '@/utils' import { useMhrUnitNote } from '@/composables' export default defineComponent({ @@ -39,6 +39,7 @@ export default defineComponent({ } = useMhrUnitNote() const localState = reactive({ + today: computed(() : string => localTodayDate()), noteHeader: computed(() : string => { let header = [UnitNoteDocTypes.CONTINUED_NOTE_OF_CAUTION, UnitNoteDocTypes.EXTENSION_TO_NOTICE_OF_CAUTION] @@ -46,7 +47,7 @@ export default defineComponent({ ? UnitNotesInfo[props.note.documentType].panelHeader : UnitNotesInfo[props.note.documentType].header - if (isExpiryDatePassed(props.note)) { + if (isExpiryDatePassed(props.note, localState.today)) { header += ` (Expired)` } else if (props.note.status === UnitNoteStatusTypes.CANCELLED && props.note.documentType === UnitNoteDocTypes.NOTICE_OF_TAX_SALE) { diff --git a/ppr-ui/src/composables/mhrInformation/useMhrUnitNote.ts b/ppr-ui/src/composables/mhrInformation/useMhrUnitNote.ts index 79050d189..3554df7d4 100644 --- a/ppr-ui/src/composables/mhrInformation/useMhrUnitNote.ts +++ b/ppr-ui/src/composables/mhrInformation/useMhrUnitNote.ts @@ -1,7 +1,7 @@ import { UnitNoteDocTypes, UnitNoteStatusTypes } from '@/enums/unitNoteDocTypes' import { CancelUnitNoteIF, PartyIF, UnitNoteIF, UnitNotePanelIF, UnitNoteRegistrationIF } from '@/interfaces' import { useStore } from '@/store/store' -import { deleteEmptyProperties, localTodayDate, submitMhrUnitNote } from '@/utils' +import { deleteEmptyProperties, submitMhrUnitNote } from '@/utils' import { storeToRefs } from 'pinia' import { cloneDeep } from 'lodash' import { computed } from 'vue-demi' @@ -114,12 +114,13 @@ export const useMhrUnitNote = () => { const isCancelUnitNote = computed((): boolean => getMhrUnitNoteType.value === UnitNoteDocTypes.NOTE_CANCELLATION) - const isExpiryDatePassed = (note: UnitNoteIF): boolean => { + // Check if the provided Unit Note's Expiry date passed today or not + // parameter 'today' need to be in the format of 'YYYY-MM-DD' + const isExpiryDatePassed = (note: UnitNoteIF, today: string): boolean => { if ((note.documentType === UnitNoteDocTypes.CONTINUED_NOTE_OF_CAUTION || note.documentType === UnitNoteDocTypes.EXTENSION_TO_NOTICE_OF_CAUTION) && - note.expiryDateTime != null && note.expiryDateTime !== '') { + !!note.expiryDateTime) { const expiryDate = note.expiryDateTime.substring(0, 10) - const today = localTodayDate() return new Date(expiryDate) < new Date(today) } return false diff --git a/ppr-ui/tests/unit/UnitNotePanels.spec.ts b/ppr-ui/tests/unit/UnitNotePanels.spec.ts index 45edd63e6..b3f152fd6 100644 --- a/ppr-ui/tests/unit/UnitNotePanels.spec.ts +++ b/ppr-ui/tests/unit/UnitNotePanels.spec.ts @@ -17,7 +17,7 @@ import { mockedUnitNotesCancelled } from './test-data' import { BaseAddress } from '@/composables/address' -import { pacificDate, shortPacificDate } from '@/utils' +import { localTodayDate, pacificDate, shortPacificDate } from '@/utils' import { ResidentialExemptionQSDropDown, ResidentialExemptionStaffDropDown, @@ -58,10 +58,10 @@ function createComponent (otherMockNotes?: Array) const verifyHeaderContent = (note: UnitNotePanelIF, header: Wrapper) => { // Check the unit note type const typeText = header.find('h3').text() - + const today = localTodayDate() let statusText = '' if (note.status === UnitNoteStatusTypes.EXPIRED || - useMhrUnitNote().isExpiryDatePassed(note)) { + useMhrUnitNote().isExpiryDatePassed(note, today)) { statusText = ' (Expired)' } else if (note.status === UnitNoteStatusTypes.CANCELLED) { statusText = ' (Cancelled)'