diff --git a/ppr-ui/package-lock.json b/ppr-ui/package-lock.json index 5c1a88b73..fa4bfd038 100644 --- a/ppr-ui/package-lock.json +++ b/ppr-ui/package-lock.json @@ -1,12 +1,12 @@ { "name": "ppr-ui", - "version": "3.1.29", + "version": "3.1.30", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "ppr-ui", - "version": "3.1.29", + "version": "3.1.30", "dependencies": { "@bcrs-shared-components/input-field-date-picker": "^1.0.0", "@lemoncode/fonk": "^1.5.1", diff --git a/ppr-ui/package.json b/ppr-ui/package.json index 3652b70d4..5fff5237c 100644 --- a/ppr-ui/package.json +++ b/ppr-ui/package.json @@ -1,6 +1,6 @@ { "name": "ppr-ui", - "version": "3.1.29", + "version": "3.1.30", "private": true, "appName": "Assets UI", "sbcName": "SBC Common Components", diff --git a/ppr-ui/src/composables/mhrInformation/useTransportPermits.ts b/ppr-ui/src/composables/mhrInformation/useTransportPermits.ts index 17540c538..5f94107c3 100644 --- a/ppr-ui/src/composables/mhrInformation/useTransportPermits.ts +++ b/ppr-ui/src/composables/mhrInformation/useTransportPermits.ts @@ -10,8 +10,14 @@ import { useStore } from '@/store/store' import { storeToRefs } from 'pinia' import { locationChangeTypes } from '@/resources/mhr-transport-permits/transport-permits' import { LocationChangeTypes } from '@/enums/transportPermits' -import { MhrRegistrationHomeLocationIF, MhrTransportPermitIF, StaffPaymentIF } from '@/interfaces' -import { APIRegistrationTypes, HomeLocationTypes, MhApiStatusTypes, UnitNoteDocTypes } from '@/enums' +import { MhrRegistrationHomeLocationIF, MhrTransportPermitIF, StaffPaymentIF, UnitNoteIF } from '@/interfaces' +import { + APIRegistrationTypes, + HomeLocationTypes, + MhApiStatusTypes, + UnitNoteDocTypes, + UnitNoteStatusTypes +} from '@/enums' import { cloneDeep, get, isEqual } from 'lodash' // Global constants @@ -149,6 +155,28 @@ export const useTransportPermits = () => { ) ) + /** + * Check if Amend or Cancel Transport Permit is allowed for Exempt MHR based on few conditions. + * + * @returns {boolean} Returns true if: + * - the MHR status is exempt + * - the role is either staff or qualified supplier + * - the registered location is not in BC + * - there is no active exemption registration + * - there is an active transport permit + * - Otherwise, it returns false. + */ + const isExemptMhrTransportPermitChangesEnabled = computed((): boolean => + getMhrInformation.value.statusType === MhApiStatusTypes.EXEMPT && // mhr status is exempt + (isRoleStaffReg.value || isRoleQualifiedSupplier.value) && // only for staff and qs + getMhrRegistrationLocation.value.address.region !== 'BC' && // civic address is not BC + !getMhrUnitNotes.value.some((unitNote: UnitNoteIF) => // has no active exemption registration + [UnitNoteDocTypes.RESIDENTIAL_EXEMPTION_ORDER, UnitNoteDocTypes.NON_RESIDENTIAL_EXEMPTION] + .includes(unitNote.documentType) && + unitNote.status === UnitNoteStatusTypes.ACTIVE) && + hasActiveTransportPermit.value // has active transport permit + ) + const resetTransportPermit = async (shouldResetLocationChange: boolean = false): Promise => { setEmptyMhrTransportPermit(initTransportPermit()) shouldResetLocationChange && setLocationChange(false) @@ -342,6 +370,7 @@ export const useTransportPermits = () => { isRegisteredLocationChange, isTransportPermitDisabled, isActivePermitWithinSamePark, + isExemptMhrTransportPermitChangesEnabled, isValueAmended, hasAmendmentChanges, setLocationChange, diff --git a/ppr-ui/src/views/mhrInformation/MhrInformation.vue b/ppr-ui/src/views/mhrInformation/MhrInformation.vue index dfd5a9acf..f4c1092f4 100644 --- a/ppr-ui/src/views/mhrInformation/MhrInformation.vue +++ b/ppr-ui/src/views/mhrInformation/MhrInformation.vue @@ -826,6 +826,7 @@ export default defineComponent({ isCancelChangeLocationActive, isTransportPermitDisabled, isRegisteredLocationChange, + isExemptMhrTransportPermitChangesEnabled, setLocationChange, getUiFeeSummaryLocationType, getUiLocationType, @@ -833,7 +834,7 @@ export default defineComponent({ setLocationChangeType, initTransportPermit, populateLocationInfoForSamePark, - buildAndSubmitTransportPermit, + buildAndSubmitTransportPermit } = useTransportPermits() // Refs @@ -890,7 +891,7 @@ export default defineComponent({ showCancelTransportPermitDialog: false, isTransportPermitDisabled: computed((): boolean => localState.showTransferType || - isExemptMhr.value || + (isExemptMhr.value && !isExemptMhrTransportPermitChangesEnabled.value) || isTransportPermitDisabled.value || (!isRoleStaffReg.value && isFrozenMhrDueToAffidavit.value) ), diff --git a/ppr-ui/src/views/mhrInformation/MhrTransportPermit.vue b/ppr-ui/src/views/mhrInformation/MhrTransportPermit.vue index 55b2305a9..74983a037 100644 --- a/ppr-ui/src/views/mhrInformation/MhrTransportPermit.vue +++ b/ppr-ui/src/views/mhrInformation/MhrTransportPermit.vue @@ -30,7 +30,7 @@ class="" color="primary" :ripple="false" - :disabled="disable" + :disabled="disable || !getTransportPermitChangeAllowed" data-test-id="amend-transport-permit-btn" @click="toggleAmendLocationChange()" > diff --git a/ppr-ui/tests/unit/MhrInformation.spec.ts b/ppr-ui/tests/unit/MhrInformation.spec.ts index 82fb1b927..42306c969 100644 --- a/ppr-ui/tests/unit/MhrInformation.spec.ts +++ b/ppr-ui/tests/unit/MhrInformation.spec.ts @@ -41,6 +41,10 @@ import { mockedPerson2, mockedExecutor, mockedAdministrator, + mockedAddressOutsideBC, + mockedResidentialExemptionOrder, + mockedUnitNotes, + mockedUnitNotes3, } from './test-data' import { CertifyIF, @@ -52,6 +56,7 @@ import { TransferDetails, TransferDetailsReview, TransferType } from '@/componen import { defaultFlagSet, toDisplayPhone } from '@/utils' import { QualifiedSupplierTransferTypes, StaffTransferTypes, StaffTransferTypesOrg, UnitNotesInfo } from '@/resources' +import { useTransportPermits } from '@/composables' const store = useStore() @@ -1114,7 +1119,7 @@ describe('Mhr Information', async () => { it('should have read only view for exempt MHR (Residential Exemption filed)', async () => { // add unit notes with Residential Exemption - // await store.setMhrUnitNotes([mockedResidentialExemptionOrder, ...mockedUnitNotes3]) + await store.setMhrUnitNotes([mockedResidentialExemptionOrder, ...mockedUnitNotes3]) await store.setAuthRoles([AuthRoles.PPR_STAFF]) await store.setMhrStatusType(MhApiStatusTypes.EXEMPT) wrapper.vm.dataLoaded = true @@ -1160,4 +1165,35 @@ describe('Mhr Information', async () => { await store.setMhrStatusType(MhApiStatusTypes.ACTIVE) }) + it('should enable amend and cancel transport permit', async () => { + defaultFlagSet['mhr-transport-permit-enabled'] = true + + const transportPermitComposable = useTransportPermits() + + // set all conditions to enable the Amend/Cancel Permits + store.setMhrStatusType(MhApiStatusTypes.EXEMPT) + store.setAuthRoles([AuthRoles.PPR_STAFF]) + store.setMhrLocation({ key: 'address', value: mockedAddressOutsideBC }) + store.setMhrUnitNotes(mockedUnitNotes) + transportPermitComposable.setLocationChange(true) // set this flag to prevent side effect + store.setMhrInformationPermitData({ + permitKey: 'Status', + permitData: MhApiStatusTypes.ACTIVE + }) + + await nextTick() + expect(transportPermitComposable.isExemptMhrTransportPermitChangesEnabled.value).toBe(true) + + // set a false condition to disable Amend/Cancel Permit + await store.setMhrInformationPermitData({ + permitKey: 'Status', + permitData: MhApiStatusTypes.CANCELLED + }) + + expect(transportPermitComposable.isExemptMhrTransportPermitChangesEnabled.value).toBe(false) + + // reset exempt status + await store.setAuthRoles([AuthRoles.MHR]) + }) + }) diff --git a/ppr-ui/tests/unit/test-data/mock-mhr-registration.ts b/ppr-ui/tests/unit/test-data/mock-mhr-registration.ts index 3addd5c5f..7990f051e 100644 --- a/ppr-ui/tests/unit/test-data/mock-mhr-registration.ts +++ b/ppr-ui/tests/unit/test-data/mock-mhr-registration.ts @@ -35,6 +35,14 @@ export const mockedAddressAlt: AddressIF = { deliveryInstructions: 'Front Door' } +export const mockedAddressOutsideBC: AddressIF = { + city: 'TORONTO', + country: 'CA', + postalCode: 'M5E1E5', + region: 'ON', + street: '1 YONGE ST, SUITE 100' +} + export const mockedEmptyGroup: MhrRegistrationHomeOwnerGroupIF = { groupId: 100, owners: [], diff --git a/ppr-ui/tests/unit/utils/helper-functions.ts b/ppr-ui/tests/unit/utils/helper-functions.ts index 98050e912..13b41bd29 100644 --- a/ppr-ui/tests/unit/utils/helper-functions.ts +++ b/ppr-ui/tests/unit/utils/helper-functions.ts @@ -131,4 +131,5 @@ export async function setupActiveTransportPermit (): Promise { await store.setMhrTransportPermit({ key: 'newLocation', value: mockTransportPermitNewLocation }) await store.setMhrTransportPermit({ key: 'ownLand', value: true }) await store.setMhrTransportPermitPreviousLocation(mockTransportPermitPreviousLocation) + await store.setTransportPermitChangeAllowed(true) }