Skip to content

Commit

Permalink
14080 Fixed missing address IDs (#409)
Browse files Browse the repository at this point in the history
* - added missing code to retain original address IDs
- added unit tests
- app version = 3.8.14

* - fixed unit test
  • Loading branch information
severinbeauvais authored Oct 31, 2022
1 parent 9a66633 commit 0b7231e
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 7 deletions.
19 changes: 15 additions & 4 deletions src/components/common/YourCompany/OfficeAddresses.vue
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ export default class OfficeAddresses extends Mixins(CommonMixin) {
// compare valid addresses to set the "inherit mailing" flag
// ignore Address Type since it's different
// ignore Address Country Description since it's not always present
// ignore ID since it's different
this.inheritMailingAddress = (
this.mailingAddressValid &&
this.deliveryAddressValid &&
Expand All @@ -616,6 +617,7 @@ export default class OfficeAddresses extends Mixins(CommonMixin) {
/**
* When "same as (registry) mailing address" checkbox is changed,
* sets the Registered Delivery Address to the Registered Mailing Address.
* NB: retain original address IDs
*/
protected setDeliveryAddressToMailingAddress (): void {
if (this.inheritMailingAddress) {
Expand All @@ -634,6 +636,7 @@ export default class OfficeAddresses extends Mixins(CommonMixin) {
/**
* When "same as registered address" checkbox is changed,
* sets the Records office addresses to the Registered office addresses.
* NB: retain original address IDs
*/
protected setRecordOfficeToRegisteredOffice (): void {
if (this.inheritRegisteredAddress) {
Expand All @@ -650,6 +653,7 @@ export default class OfficeAddresses extends Mixins(CommonMixin) {
/**
* When "same as (records) mailing address" checkbox is changed,
* sets the Records Delivery Address to Records Mailing Address.
* NB: retain original address IDs
*/
protected setRecordDeliveryAddressToMailingAddress (): void {
if (this.inheritRecMailingAddress) {
Expand All @@ -662,13 +666,20 @@ export default class OfficeAddresses extends Mixins(CommonMixin) {
/**
* Handles update events from address sub-components.
* NB: addresses must keep their original IDs
* NB: retain original address IDs
*/
protected updateAddress (addressToUpdate: AddressTypes, newAddress: AddressIF): void {
// BaseAddress component returns empty Delivery Instructions as ''
// but Legal API returns empty Delivery Instructions as null
// so nullify empty Delivery Instructions for future comparisons.
if (!newAddress.deliveryInstructions) newAddress.deliveryInstructions = null
switch (addressToUpdate) {
case AddressTypes.MAILING_ADDRESS:
// only update if not equal
if (!isEqual(this.mailingAddress, newAddress)) {
this.mailingAddress = { ...newAddress }
this.mailingAddress = { ...newAddress, id: this.mailingAddress.id }
if (this.inheritMailingAddress) {
this.deliveryAddress = { ...newAddress, addressType: 'delivery', id: this.deliveryAddress.id }
}
Expand All @@ -683,7 +694,7 @@ export default class OfficeAddresses extends Mixins(CommonMixin) {
case AddressTypes.DELIVERY_ADDRESS:
// only update if not equal
if (!isEqual(this.deliveryAddress, newAddress)) {
this.deliveryAddress = { ...newAddress }
this.deliveryAddress = { ...newAddress, id: this.deliveryAddress.id }
if (this.inheritRegisteredAddress) {
this.recDeliveryAddress = { ...newAddress, addressType: 'delivery', id: this.recDeliveryAddress.id }
}
Expand All @@ -693,7 +704,7 @@ export default class OfficeAddresses extends Mixins(CommonMixin) {
case AddressTypes.REC_MAILING_ADDRESS:
// only update if not equal
if (!isEqual(this.recMailingAddress, newAddress)) {
this.recMailingAddress = { ...newAddress }
this.recMailingAddress = { ...newAddress, id: this.recMailingAddress.id }
if (this.inheritRecMailingAddress) {
this.recDeliveryAddress = { ...newAddress, addressType: 'delivery', id: this.recDeliveryAddress.id }
}
Expand All @@ -703,7 +714,7 @@ export default class OfficeAddresses extends Mixins(CommonMixin) {
case AddressTypes.REC_DELIVERY_ADDRESS:
// only update if not equal
if (!isEqual(this.recDeliveryAddress, newAddress)) {
this.recDeliveryAddress = { ...newAddress }
this.recDeliveryAddress = { ...newAddress, id: this.recDeliveryAddress.id }
}
break
Expand Down
111 changes: 108 additions & 3 deletions tests/unit/OfficeAddresses.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const store = getVuexStore()
*/
function getAddressX (x: number): AddressIF {
return {
id: x,
addressCity: `addressCity${x}`,
addressCountry: 'CA',
addressRegion: 'BC',
Expand Down Expand Up @@ -797,7 +798,7 @@ describe('"same as" checkboxes', () => {
expect(address.find('.v-input.address-region').props('value')).toBe('BC')
expect(address.find('.v-input.postal-code').props('value')).toBe('')
expect(address.find('.v-input.address-country').props('value')).toBe('CA')
expect(address.find('.v-input.delivery-instructions').props('value')).toBe('')
expect(address.find('.v-input.delivery-instructions').props('value')).toBeNull()

// re-check and verify the checkbox
await checkbox.trigger('click')
Expand Down Expand Up @@ -836,7 +837,7 @@ describe('"same as" checkboxes', () => {
expect(address.find('.v-input.address-region').props('value')).toBe('BC')
expect(address.find('.v-input.postal-code').props('value')).toBe('')
expect(address.find('.v-input.address-country').props('value')).toBe('CA')
expect(address.find('.v-input.delivery-instructions').props('value')).toBe('')
expect(address.find('.v-input.delivery-instructions').props('value')).toBeNull()

// re-check and verify the checkbox
await checkbox.trigger('click')
Expand Down Expand Up @@ -887,7 +888,7 @@ describe('"same as" checkboxes', () => {
expect(address.find('.v-input.address-region').props('value')).toBe('BC')
expect(address.find('.v-input.postal-code').props('value')).toBe('')
expect(address.find('.v-input.address-country').props('value')).toBe('CA')
expect(address.find('.v-input.delivery-instructions').props('value')).toBe('')
expect(address.find('.v-input.delivery-instructions').props('value')).toBeNull()

// re-check and verify the checkbox
await checkbox.trigger('click')
Expand Down Expand Up @@ -1118,3 +1119,107 @@ describe('For Special resolution', () => {
expect(wrapper.find('.actions').exists()).toBe(false)
})
})

describe('verify updateAddress()', () => {
let wrapper: any = null
let vm: any = null

/** Returns True if address IDs and types are unchanged and contents are as specified. */
function verifyAddressChanges (vals: Array<number>): boolean {
// verify IDs (should be same as original)
if (vm.$data.mailingAddress.id !== 1) return false
if (vm.$data.deliveryAddress.id !== 2) return false
if (vm.$data.recMailingAddress.id !== 3) return false
if (vm.$data.recDeliveryAddress.id !== 4) return false

// verify address types (should be same as original)
if (vm.$data.mailingAddress.addressType !== 'mailing') return false
if (vm.$data.deliveryAddress.addressType !== 'delivery') return false
if (vm.$data.recMailingAddress.addressType !== 'mailing') return false
if (vm.$data.recDeliveryAddress.addressType !== 'delivery') return false

// verify address contents (checking only City is sufficient)
if (vm.$data.mailingAddress.addressCity !== `addressCity${vals[0]}`) return false
if (vm.$data.deliveryAddress.addressCity !== `addressCity${vals[1]}`) return false
if (vm.$data.recMailingAddress.addressCity !== `addressCity${vals[2]}`) return false
if (vm.$data.recDeliveryAddress.addressCity !== `addressCity${vals[3]}`) return false

return true
}

beforeEach(async () => {
wrapper = mount(OfficeAddresses, { store, vuetify })
vm = wrapper.vm

// set original addresses
wrapper.setData({ mailingAddress: getAddressX(1) })
wrapper.setData({ deliveryAddress: getAddressX(2) })
wrapper.setData({ recMailingAddress: getAddressX(3) })
wrapper.setData({ recDeliveryAddress: getAddressX(4) })
})

afterEach(() => {
wrapper.destroy()
})

const tests = [
{
inherit: false,
address: 1, // MAILING_ADDRESS
expected: [5, 2, 3, 4]
},
{
inherit: true,
address: 1, // MAILING_ADDRESS
expected: [5, 5, 5, 5]
},
{
inherit: false,
address: 2, // DELIVERY_ADDRESS
expected: [1, 5, 3, 4]
},
{
inherit: true,
address: 2, // DELIVERY_ADDRESS
expected: [1, 5, 3, 5]
},
{
inherit: false,
address: 3, // REC_MAILING_ADDRESS
expected: [1, 2, 5, 4]
},
{
inherit: true,
address: 3, // REC_MAILING_ADDRESS
expected: [1, 2, 5, 5]
},
{
inherit: false,
address: 4, // REC_DELIVERY_ADDRESS
expected: [1, 2, 3, 5]
},
{
inherit: true,
address: 4, // REC_DELIVERY_ADDRESS
expected: [1, 2, 3, 5]
}
]

for (const test of tests) {
it(`updates address: ${test.address} with inherit flags: ${test.inherit}`, () => {
// set inherit state
wrapper.setData({
inheritMailingAddress: test.inherit,
inheritRegisteredAddress: test.inherit
})

// verify unchanged address
vm.updateAddress(test.address, getAddressX(test.address))
verifyAddressChanges([1, 2, 3, 4])

// verify changed address
vm.updateAddress(test.address, getAddressX(5))
verifyAddressChanges(test.expected)
})
}
})

0 comments on commit 0b7231e

Please sign in to comment.