Skip to content

Commit e568492

Browse files
committed
feat(foxy-coupon-form): add stubs for controls that are active only in snapshot state
1 parent 646a659 commit e568492

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

src/elements/public/CouponForm/CouponForm.test.ts

+21
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,18 @@ describe('CouponForm', () => {
269269
expect(element.hiddenSelector.matches('coupon-codes', true)).to.be.true;
270270
expect(element.hiddenSelector.matches('category-restrictions', true)).to.be.true;
271271
expect(element.hiddenSelector.matches('attributes', true)).to.be.true;
272+
expect(element.hiddenSelector.matches('coupon-codes-stub', true)).to.be.false;
273+
expect(element.hiddenSelector.matches('category-restrictions-stub', true)).to.be.false;
274+
expect(element.hiddenSelector.matches('attributes-stub', true)).to.be.false;
272275

273276
element.data = await getTestData('./hapi/coupons/0');
274277

275278
expect(element.hiddenSelector.matches('coupon-codes', true)).to.be.false;
276279
expect(element.hiddenSelector.matches('category-restrictions', true)).to.be.false;
277280
expect(element.hiddenSelector.matches('attributes', true)).to.be.false;
281+
expect(element.hiddenSelector.matches('coupon-codes-stub', true)).to.be.true;
282+
expect(element.hiddenSelector.matches('category-restrictions-stub', true)).to.be.true;
283+
expect(element.hiddenSelector.matches('attributes-stub', true)).to.be.true;
278284
});
279285

280286
it('renders a form header', () => {
@@ -363,10 +369,15 @@ describe('CouponForm', () => {
363369
</foxy-coupon-form>
364370
`);
365371

372+
const controlStub = element.renderRoot.querySelector(
373+
'foxy-internal-summary-control[infer="coupon-codes-stub"] foxy-i18n[infer=""][key="text"]'
374+
);
375+
366376
const control = element.renderRoot.querySelector(
367377
'foxy-internal-async-list-control[infer=coupon-codes]'
368378
) as InternalAsyncListControl;
369379

380+
expect(controlStub).to.exist;
370381
expect(control).to.exist;
371382

372383
expect(control).to.have.attribute(
@@ -460,7 +471,12 @@ describe('CouponForm', () => {
460471
'foxy-internal-async-resource-link-list-control[infer=category-restrictions]'
461472
);
462473

474+
const controlStub = element.renderRoot.querySelector(
475+
'foxy-internal-summary-control[infer="category-restrictions-stub"] foxy-i18n[infer=""][key="text"]'
476+
);
477+
463478
expect(control).to.exist;
479+
expect(controlStub).to.exist;
464480
await waitUntil(() => !!control?.hasAttribute('options-href'));
465481

466482
expect(control).to.have.attribute('foreign-key-for-uri', 'item_category_uri');
@@ -683,7 +699,12 @@ describe('CouponForm', () => {
683699
'foxy-internal-async-list-control[infer=attributes]'
684700
) as InternalAsyncListControl;
685701

702+
const controlStub = element.renderRoot.querySelector(
703+
'foxy-internal-summary-control[infer="category-restrictions-stub"] foxy-i18n[infer=""][key="text"]'
704+
);
705+
686706
expect(control).to.exist;
707+
expect(controlStub).to.exist;
687708
expect(control).to.have.attribute(
688709
'first',
689710
'https://demo.api/hapi/coupon_attributes?coupon_id=0'

src/elements/public/CouponForm/CouponForm.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ export class CouponForm extends Base<Data> {
203203
get hiddenSelector(): BooleanSelector {
204204
const alwaysMatch = [super.hiddenSelector.toString()];
205205

206-
if (!this.data) {
206+
if (this.data) {
207+
alwaysMatch.push('coupon-codes-stub', 'category-restrictions-stub', 'attributes-stub');
208+
} else {
207209
alwaysMatch.push('coupon-codes', 'category-restrictions', 'attributes');
208210
}
209211

@@ -258,6 +260,10 @@ export class CouponForm extends Base<Data> {
258260
<foxy-internal-coupon-form-rules-control infer="rules">
259261
</foxy-internal-coupon-form-rules-control>
260262
263+
<foxy-internal-summary-control infer="coupon-codes-stub">
264+
<p class="text-disabled"><foxy-i18n infer="" key="text"></foxy-i18n></p>
265+
</foxy-internal-summary-control>
266+
261267
<foxy-internal-async-list-control
262268
first=${codesUrl}
263269
limit="5"
@@ -306,6 +312,10 @@ export class CouponForm extends Base<Data> {
306312
<foxy-internal-switch-control infer="customer-auto-apply"></foxy-internal-switch-control>
307313
</foxy-internal-summary-control>
308314
315+
<foxy-internal-summary-control infer="category-restrictions-stub">
316+
<p class="text-disabled"><foxy-i18n infer="" key="text"></foxy-i18n></p>
317+
</foxy-internal-summary-control>
318+
309319
<foxy-internal-async-resource-link-list-control
310320
foreign-key-for-uri="item_category_uri"
311321
foreign-key-for-id="item_category_id"
@@ -374,6 +384,10 @@ export class CouponForm extends Base<Data> {
374384
<foxy-internal-switch-control infer="shared-codes-allowed"></foxy-internal-switch-control>
375385
</foxy-internal-summary-control>
376386
387+
<foxy-internal-summary-control infer="attributes-stub">
388+
<p class="text-disabled"><foxy-i18n infer="" key="text"></foxy-i18n></p>
389+
</foxy-internal-summary-control>
390+
377391
<foxy-internal-async-list-control
378392
first=${ifDefined(this.data?._links['fx:attributes'].href)}
379393
limit="5"

src/static/translations/coupon-form/en.json

+15
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@
171171
"description": "Description",
172172
"url_parameter": "URL parameter"
173173
},
174+
"coupon-codes-stub": {
175+
"label": "Codes",
176+
"helper_text": "",
177+
"text": "Coupon codes can be added after creating the coupon."
178+
},
174179
"coupon-codes": {
175180
"label": "Codes",
176181
"delete_header": "Remove code?",
@@ -349,6 +354,11 @@
349354
"value": "Value"
350355
}
351356
},
357+
"attributes-stub": {
358+
"label": "Attributes",
359+
"helper_text": "",
360+
"text": "Attributes can be added after creating the coupon."
361+
},
352362
"attributes": {
353363
"label": "Attributes",
354364
"delete_header": "Remove attribute?",
@@ -546,6 +556,11 @@
546556
"option_name": "Option name",
547557
"rule": "Rule"
548558
},
559+
"category-restrictions-stub": {
560+
"label": "Item category restrictions",
561+
"helper_text": "",
562+
"text": "Item category restrictions can be added after creating the coupon."
563+
},
549564
"category-restrictions": {
550565
"label": "Item category restrictions",
551566
"status_saving": "Saving...",

0 commit comments

Comments
 (0)