From 38239cb311721564f81abdbd6b72e45eb7c5c509 Mon Sep 17 00:00:00 2001 From: Daniil Bratukhin Date: Thu, 22 Aug 2024 12:13:38 -0300 Subject: [PATCH] feat(foxy-coupon-form): group customer restrictions together --- .../public/CouponForm/CouponForm.stories.ts | 17 ++- .../public/CouponForm/CouponForm.test.ts | 29 ++++- src/elements/public/CouponForm/CouponForm.ts | 43 ++++--- src/static/translations/coupon-form/en.json | 114 +++++++++--------- 4 files changed, 121 insertions(+), 82 deletions(-) diff --git a/src/elements/public/CouponForm/CouponForm.stories.ts b/src/elements/public/CouponForm/CouponForm.stories.ts index 37eb32cc..f7551590 100644 --- a/src/elements/public/CouponForm/CouponForm.stories.ts +++ b/src/elements/public/CouponForm/CouponForm.stories.ts @@ -30,12 +30,21 @@ const summary: Summary = { 'options:exclude-line-item-discounts', 'options:is-taxable', 'options:shared-codes-allowed', - 'options:customer-auto-apply', - 'customer-subscription-restrictions', - 'customer-attribute-restrictions', + 'customer-restrictions:customer-auto-apply', + 'customer-restrictions:customer-subscription-restrictions', + 'customer-restrictions:customer-attribute-restrictions', 'attributes', ], - sections: ['timestamps', 'header', 'general', 'uses', 'timeframe', 'options', 'taxes'], + sections: [ + 'timestamps', + 'header', + 'general', + 'uses', + 'timeframe', + 'options', + 'taxes', + 'customer-restrictions', + ], buttons: [ 'import', 'generate', diff --git a/src/elements/public/CouponForm/CouponForm.test.ts b/src/elements/public/CouponForm/CouponForm.test.ts index f8ad1f88..af599d79 100644 --- a/src/elements/public/CouponForm/CouponForm.test.ts +++ b/src/elements/public/CouponForm/CouponForm.test.ts @@ -597,7 +597,6 @@ describe('CouponForm', () => { 'exclude-line-item-discounts', 'is-taxable', 'shared-codes-allowed', - 'customer-auto-apply', ] as const; for (const prop of props) { @@ -611,13 +610,23 @@ describe('CouponForm', () => { }); } - it('renders editable list control for subscription restrictions', async () => { + it('renders a Customer Restrictions summary control', async () => { const element = await fixture(html``); const control = element.renderRoot.querySelector( - 'foxy-internal-editable-list-control[infer=customer-subscription-restrictions]' + 'foxy-internal-summary-control[infer="customer-restrictions"]' + ); + + expect(control).to.exist; + }); + + it('renders editable list control for subscription restrictions inside of the Customer Restrictions summary', async () => { + const element = await fixture(html``); + const control = element.renderRoot.querySelector( + '[infer=customer-restrictions] foxy-internal-editable-list-control[infer=customer-subscription-restrictions]' ) as InternalEditableListControl; expect(control).to.exist; + expect(control).to.have.attribute('layout', 'summary-item'); expect(control.getValue()).to.deep.equal([]); control.setValue([{ value: 'a' }, { value: 'b' }]); @@ -627,12 +636,22 @@ describe('CouponForm', () => { expect(control.getValue()).to.deep.equal([{ value: 'foo' }, { value: 'bar' }]); }); - it('renders query builder control for customer attribute restrictions', async () => { + it('renders query builder control for customer attribute restrictions inside of the Customer Restrictions summary', async () => { const element = await fixture(html``); const control = element.renderRoot.querySelector( - 'foxy-internal-query-builder-control[infer=customer-attribute-restrictions]' + '[infer=customer-restrictions] foxy-internal-query-builder-control[infer=customer-attribute-restrictions]' ) as InternalQueryBuilderControl; + expect(control).to.exist; + expect(control).to.have.attribute('layout', 'summary-item'); + }); + + it('renders switch control for auto-apply inside of the Customer Restrictions summary', async () => { + const element = await fixture(html``); + const control = element.renderRoot.querySelector( + '[infer=customer-restrictions] foxy-internal-switch-control[infer=customer-auto-apply]' + ); + expect(control).to.exist; }); diff --git a/src/elements/public/CouponForm/CouponForm.ts b/src/elements/public/CouponForm/CouponForm.ts index 883b0525..4e685078 100644 --- a/src/elements/public/CouponForm/CouponForm.ts +++ b/src/elements/public/CouponForm/CouponForm.ts @@ -240,18 +240,6 @@ export class CouponForm extends Base { > - - - - - - { > - - + + + + + + + + + + + { -