Skip to content

Commit

Permalink
fix: do not render errors if address has never been filled in (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine authored May 1, 2023
1 parent 907dab1 commit e82edf6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 28 deletions.
18 changes: 15 additions & 3 deletions src/delivery-options/DeliveryOptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ export default {
*/
fakeShowDeliveryOptions: true,
/**
* Whether the delivery options are initialized.
*
* @type {boolean}
*/
initialized: false,
/**
* Whether the delivery options are loading or not.
*
Expand Down Expand Up @@ -140,12 +147,12 @@ export default {
computed: {
/**
* False if address or address.cc is missing.
* False if `address`, `address.cc` or `address.street` is missing.
*
* @returns {boolean}
*/
hasValidAddress() {
return Boolean(this.$configBus.address && this.$configBus.address.cc);
return Boolean(this.$configBus.address && this.$configBus.address.cc && this.$configBus.address.street);
},
/**
Expand Down Expand Up @@ -238,6 +245,8 @@ export default {
},
],
};
this.initialized = true;
},
/**
Expand Down Expand Up @@ -282,8 +291,11 @@ export default {
this.showSelf();
if (!this.hasValidAddress) {
this.showAddressErrors();
if (this.initialized) {
this.showAddressErrors();
}
this.loading = false;
return;
}
Expand Down
25 changes: 0 additions & 25 deletions tests/unit/delivery-options/components/DeliveryOptions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,6 @@ describe('DeliveryOptions.vue', () => {
expect(wrapper.vm.hasValidAddress).toBe(true);
});

it('shows retry button on missing cc', async() => {
expect.assertions(2);

const wrapper = mockDeliveryOptions({
[ADDRESS.KEY]: {},
[CONFIG.KEY]: {
[CONFIG.FEATURE_ALLOW_RETRY]: true,
},
});
wrapper.vm.showAddressErrors = createWaitableMock(wrapper.vm.showAddressErrors);

await wrapper.vm.showAddressErrors.waitToHaveBeenCalled(1);
expect(wrapper.findByTestId('button--retry').exists()).toBe(true);

// Change address to a valid address.
document.dispatchEvent(
new CustomEvent(UPDATE_DELIVERY_OPTIONS, {
detail: configWithValidAddress,
}),
);

await waitForEvent(UPDATED_DELIVERY_OPTIONS);
expect(wrapper.findByTestId('button--retry').exists()).toBe(false);
});

it('shows errors on invalid address response from api', async() => {
expect.assertions(2);
fakeDeliveryOptionsResponse.mockImplementation(deliveryOptionsResponseInvalidPostalCode);
Expand Down

0 comments on commit e82edf6

Please sign in to comment.