Skip to content

Commit

Permalink
NEXT-39801 - Fix payment method active toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
lacknere authored and mstegmeyer committed Nov 27, 2024
1 parent 18db357 commit ad03a94
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: Fix payment method active toggle
issue: NEXT-00000
author: Elias Lackner
author_email: [email protected]
author_github: @lacknere
---
# Administration
* Changed `setPaymentMethodActive` method in `sw-payment-card` component to receive the switch field active state and prevent emitting `set-payment-active` event if the active state is unchanged.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export default {
},

methods: {
async setPaymentMethodActive(active) {
setPaymentMethodActive(active) {
if (this.paymentMethod.active === active) {
return;
}

this.paymentMethod.active = active;

this.$emit('set-payment-active', this.paymentMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
:value="paymentMethod.active"
:disabled="!acl.can('payment.editor') || undefined"
:label="$tc('sw-settings-payment.overview.activeToggle')"
@update:value="setPaymentMethodActive(!paymentMethod.active)"
@update:value="setPaymentMethodActive"
/>
{% endblock %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,27 @@ describe('module/sw-settings-payment/component/sw-payment-card', () => {
const activeToggle = wrapper.find('sw-switch-field-stub');
expect(activeToggle.attributes().disabled).toBeFalsy();
});

it('should correctly emit set-payment-active event', async () => {
const wrapper = await createWrapper(['payment.editor']);
await wrapper.vm.$nextTick();

const activeToggle = wrapper.findComponent('sw-switch-field-stub');
await activeToggle.vm.$emit('update:value', false);

const expectedPaymentMethod = {
id: '5e6f7g8h',
translated: {
name: 'Test settings-payment 2',
},
active: false,
};

expect(wrapper.emitted('set-payment-active')).toHaveLength(1);
expect(wrapper.emitted('set-payment-active')[0]).toEqual([expectedPaymentMethod]);

await activeToggle.vm.$emit('update:value', false);

expect(wrapper.emitted('set-payment-active')).toHaveLength(1);
});
});

0 comments on commit ad03a94

Please sign in to comment.