@ordergroove/offers 2.27.1 → 2.27.2-alpha-PR-637-2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle-report.html +9 -9
- package/dist/offers.js +26 -26
- package/dist/offers.js.map +2 -2
- package/package.json +2 -2
- package/src/components/Offer.js +6 -3
- package/src/components/Price.js +25 -3
- package/src/components/__tests__/Offer.spec.js +29 -0
- package/src/components/__tests__/Price.fspec.js +32 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ordergroove/offers",
|
|
3
|
-
"version": "2.27.
|
|
3
|
+
"version": "2.27.2-alpha-PR-637-2.10+4eac3e2c",
|
|
4
4
|
"description": "offer state component",
|
|
5
5
|
"author": "Eugenio Lattanzio <eugenio63@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/ordergroove/plush-toys#readme",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@ordergroove/offers-templates": "^0.4.12"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "4eac3e2c172a063bacb123d1a20bd74250c57b48"
|
|
49
49
|
}
|
package/src/components/Offer.js
CHANGED
|
@@ -44,6 +44,9 @@ export class Offer extends TemplateElement {
|
|
|
44
44
|
offerId: { type: String, attribute: false },
|
|
45
45
|
auth: authProp,
|
|
46
46
|
preview: { type: String, attribute: 'preview', reflect: 'true' },
|
|
47
|
+
previewRegularPrice: { type: String, attribute: 'preview-regular-price', reflect: 'true' },
|
|
48
|
+
previewDiscountRate: { type: String, attribute: 'preview-discount-rate', reflect: 'true' },
|
|
49
|
+
previewSubscriptionPrice: { type: String, attribute: 'preview-subscription-price', reflect: 'true' },
|
|
47
50
|
location: { type: String },
|
|
48
51
|
autoshipByDefault: { type: Boolean, attribute: 'autoship-by-default' },
|
|
49
52
|
productDefaultFrequency: { type: String, attribute: false },
|
|
@@ -149,11 +152,11 @@ export class Offer extends TemplateElement {
|
|
|
149
152
|
<og-price discount>
|
|
150
153
|
<span slot="prepend">Subscribe and get</span>
|
|
151
154
|
<span slot="append">off</span>
|
|
152
|
-
<og-text key="offerOptInLabel" slot="fallback"></og-text>
|
|
155
|
+
<og-text key="offerOptInLabel" slot="fallback"></og-text>
|
|
153
156
|
</og-price>
|
|
154
157
|
<og-price regular></og-price>
|
|
155
158
|
<og-price subscription></og-price>
|
|
156
|
-
|
|
159
|
+
|
|
157
160
|
</og-optin-button>
|
|
158
161
|
<og-tooltip placement="bottom">
|
|
159
162
|
<div slot="trigger">
|
|
@@ -217,7 +220,7 @@ export class Offer extends TemplateElement {
|
|
|
217
220
|
The product is in your next upcomming order
|
|
218
221
|
</og-when>
|
|
219
222
|
</og-when>
|
|
220
|
-
|
|
223
|
+
|
|
221
224
|
`;
|
|
222
225
|
}
|
|
223
226
|
|
package/src/components/Price.js
CHANGED
|
@@ -24,19 +24,41 @@ export class Price extends withProduct(TemplateElement) {
|
|
|
24
24
|
const frequency = this.frequency || this.configDefaultFrequency || this.offer?.defaultFrequency;
|
|
25
25
|
const plans = this.productPlans[realProductId] || {};
|
|
26
26
|
const currentPlan = plans[frequency] || [];
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
let hasFakePreviewPrice = false;
|
|
28
|
+
|
|
29
|
+
let [regularPrice, discountRate, subscriptionPrice] = currentPlan;
|
|
30
|
+
|
|
31
|
+
if (this.offer?.isPreview) {
|
|
32
|
+
if (this.offer?.previewRegularPrice) {
|
|
33
|
+
regularPrice = this.offer?.previewRegularPrice;
|
|
34
|
+
hasFakePreviewPrice = true;
|
|
35
|
+
}
|
|
36
|
+
if (this.offer?.previewDiscountRate) {
|
|
37
|
+
discountRate = this.offer?.previewDiscountRate;
|
|
38
|
+
hasFakePreviewPrice = true;
|
|
39
|
+
}
|
|
40
|
+
if (this.offer?.previewSubscriptionPrice) {
|
|
41
|
+
subscriptionPrice = this.offer?.previewSubscriptionPrice;
|
|
42
|
+
hasFakePreviewPrice = true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!currentPlan && !hasFakePreviewPrice) return '';
|
|
29
47
|
if (subscriptionPrice === regularPrice) return '';
|
|
30
48
|
|
|
31
49
|
if (this.regular) {
|
|
32
50
|
return regularPrice;
|
|
33
51
|
}
|
|
34
|
-
if (this.discount)
|
|
52
|
+
if (this.discount) {
|
|
53
|
+
return discountRate;
|
|
54
|
+
}
|
|
55
|
+
|
|
35
56
|
return subscriptionPrice;
|
|
36
57
|
}
|
|
37
58
|
|
|
38
59
|
render() {
|
|
39
60
|
const value = this.value;
|
|
61
|
+
|
|
40
62
|
if (value)
|
|
41
63
|
return html`
|
|
42
64
|
<slot name="prepend"></slot>
|
|
@@ -301,4 +301,33 @@ describe('previewMode', () => {
|
|
|
301
301
|
await el.updateComplete;
|
|
302
302
|
expect(el.preview).toEqual('upsell');
|
|
303
303
|
});
|
|
304
|
+
|
|
305
|
+
describe('preview values', () => {
|
|
306
|
+
it('should be compatible with preview-regular-price', async () => {
|
|
307
|
+
const el = document.createElement('og-offer');
|
|
308
|
+
el.setAttribute('preview-standard-offer', true);
|
|
309
|
+
el.setAttribute('preview-regular-price', 'mock-regular-price');
|
|
310
|
+
document.body.appendChild(el);
|
|
311
|
+
await el.updateComplete;
|
|
312
|
+
expect(el.previewRegularPrice).toEqual('mock-regular-price');
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it('should be compatible with preview-discount-price', async () => {
|
|
316
|
+
const el = document.createElement('og-offer');
|
|
317
|
+
el.setAttribute('preview-standard-offer', true);
|
|
318
|
+
el.setAttribute('preview-discount-rate', 'mock-discount-rate');
|
|
319
|
+
document.body.appendChild(el);
|
|
320
|
+
await el.updateComplete;
|
|
321
|
+
expect(el.previewDiscountRate).toEqual('mock-discount-rate');
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it('should be compatible with preview-subscription-price', async () => {
|
|
325
|
+
const el = document.createElement('og-offer');
|
|
326
|
+
el.setAttribute('preview-standard-offer', true);
|
|
327
|
+
el.setAttribute('preview-subscription-price', 'mock-subscription-price');
|
|
328
|
+
document.body.appendChild(el);
|
|
329
|
+
await el.updateComplete;
|
|
330
|
+
expect(el.previewSubscriptionPrice).toEqual('mock-subscription-price');
|
|
331
|
+
});
|
|
332
|
+
});
|
|
304
333
|
});
|
|
@@ -41,3 +41,35 @@ describe('Select Frequency', function() {
|
|
|
41
41
|
expect(htmlSelectElement.innerText).toEqual('Buy one time\n2 weeks (recomended)\n1 month');
|
|
42
42
|
});
|
|
43
43
|
});
|
|
44
|
+
|
|
45
|
+
describe('Preview Values', () => {
|
|
46
|
+
it('should render preview values if preview mode is enabled', async () => {
|
|
47
|
+
og.offers.clear();
|
|
48
|
+
document.body.innerHTML = `
|
|
49
|
+
<og-offer product="123" preview="regular" id="regular1" preview-regular-price="5.00" preview-discount-rate="10%" preview-subscription-price="$4.00"></og-offer>
|
|
50
|
+
`;
|
|
51
|
+
const element = document.querySelector('og-offer');
|
|
52
|
+
await element.updateComplete;
|
|
53
|
+
expect(
|
|
54
|
+
element.querySelector('og-optin-button og-price[regular]').shadowRoot.textContent.indexOf('5.00') !== -1
|
|
55
|
+
).toBe(true);
|
|
56
|
+
expect(
|
|
57
|
+
element.querySelector('og-optin-button og-price[discount]').shadowRoot.textContent.indexOf('10%') !== -1
|
|
58
|
+
).toBe(true);
|
|
59
|
+
expect(
|
|
60
|
+
element.querySelector('og-optin-button og-price[subscription]').shadowRoot.textContent.indexOf('$4.00') !== -1
|
|
61
|
+
).toBe(true);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should render not preview values if preview values is not set', async () => {
|
|
65
|
+
og.offers.clear();
|
|
66
|
+
document.body.innerHTML = `
|
|
67
|
+
<og-offer product="123" preview="regular" id="regular1" ></og-offer>
|
|
68
|
+
`;
|
|
69
|
+
const element = document.querySelector('og-offer');
|
|
70
|
+
await element.updateComplete;
|
|
71
|
+
expect(element.querySelector('og-optin-button og-price[regular]').shadowRoot.textContent.trim()).toEqual('');
|
|
72
|
+
expect(element.querySelector('og-optin-button og-price[discount]').shadowRoot.textContent.trim()).toEqual('');
|
|
73
|
+
expect(element.querySelector('og-optin-button og-price[subscription]').shadowRoot.textContent.trim()).toEqual('');
|
|
74
|
+
});
|
|
75
|
+
});
|