@ordergroove/offers 2.32.0 → 2.32.1-alpha-PR-727-3.3
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/README.md +1 -1
- package/dist/bundle-report.html +8 -8
- package/dist/examples.js +4 -4
- package/dist/examples.js.map +2 -2
- package/dist/offers.js +4 -4
- package/dist/offers.js.map +2 -2
- package/package.json +3 -3
- package/src/components/PrepaidToggle.js +14 -4
- package/src/components/__tests__/PrepaidToggle.spec.js +28 -7
- package/src/core/__tests__/selectors.spec.js +23 -0
- package/src/core/selectors.js +4 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ordergroove/offers",
|
|
3
|
-
"version": "2.32.
|
|
3
|
+
"version": "2.32.1-alpha-PR-727-3.3+d76cb26d",
|
|
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,7 +45,7 @@
|
|
|
45
45
|
"throttle-debounce": "^2.1.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@ordergroove/offers-templates": "^0.7.
|
|
48
|
+
"@ordergroove/offers-templates": "^0.7.1-alpha-PR-727-3.3+d76cb26d"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "d76cb26d161d1053a3b0d037a73cff98fa63eeba"
|
|
51
51
|
}
|
|
@@ -20,7 +20,8 @@ export class PrepaidToggle extends withProduct(LitElement) {
|
|
|
20
20
|
options: { type: Array },
|
|
21
21
|
text: { type: String },
|
|
22
22
|
shipmentsOptedIn: { type: Number },
|
|
23
|
-
prepaidShipmentsSelected: { type: Number }
|
|
23
|
+
prepaidShipmentsSelected: { type: Number },
|
|
24
|
+
defaultPrepaidShipments: { type: Number, attribute: 'default-prepaid-shipments' }
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
27
|
|
|
@@ -50,10 +51,19 @@ export class PrepaidToggle extends withProduct(LitElement) {
|
|
|
50
51
|
return this.shipmentsOptedIn > 1;
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
get selectedShipments() {
|
|
55
|
+
return this.prepaidShipmentsSelected || this.shipmentsOptedIn || this.getDefaultPrepaidShipments();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
getDefaultPrepaidShipments() {
|
|
59
|
+
return this.options.includes(this.defaultPrepaidShipments)
|
|
60
|
+
? this.defaultPrepaidShipments
|
|
61
|
+
: this.options[1] || this.options[0];
|
|
62
|
+
}
|
|
63
|
+
|
|
53
64
|
handleChange(e) {
|
|
54
65
|
if (e.target.checked) {
|
|
55
|
-
|
|
56
|
-
this.productChangePrepaidShipments(this.product, selectedShipments, this.offer);
|
|
66
|
+
this.productChangePrepaidShipments(this.product, this.selectedShipments, this.offer);
|
|
57
67
|
} else {
|
|
58
68
|
this.productChangePrepaidShipments(this.product, null, this.offer);
|
|
59
69
|
}
|
|
@@ -83,7 +93,7 @@ export class PrepaidToggle extends withProduct(LitElement) {
|
|
|
83
93
|
? html`
|
|
84
94
|
<og-select
|
|
85
95
|
.options=${displayOptions}
|
|
86
|
-
.selected=${this.
|
|
96
|
+
.selected=${this.selectedShipments}
|
|
87
97
|
.onChange="${e => this.handleSelect(e)}"
|
|
88
98
|
></og-select>
|
|
89
99
|
`
|
|
@@ -61,29 +61,35 @@ describe('PrepaidToggle', () => {
|
|
|
61
61
|
]);
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
-
it('should render static text when only one option', async () => {
|
|
64
|
+
it('should render static text when only one option and opt in', async () => {
|
|
65
65
|
const toggle = await renderTemplate(getPrepaidToggleTemplate([3]));
|
|
66
|
+
toggle.productChangePrepaidShipments = jasmine.createSpy('productChangePrepaidShipments');
|
|
67
|
+
|
|
66
68
|
const select = toggle.shadowRoot.querySelector('og-select');
|
|
67
69
|
expect(select).toBeFalsy();
|
|
68
70
|
const label = toggle.shadowRoot.querySelector('label');
|
|
69
71
|
expect(label.innerText).toBe('Prepay for 3 shipments');
|
|
72
|
+
|
|
73
|
+
const checkbox = toggle.shadowRoot.querySelector('input');
|
|
74
|
+
toggleCheckbox(checkbox);
|
|
75
|
+
expectPrepaidShipmentsAction(toggle, 3);
|
|
70
76
|
});
|
|
71
77
|
|
|
72
|
-
it('should opt into prepaid', async () => {
|
|
78
|
+
it('should opt into prepaid when no default shipments set', async () => {
|
|
73
79
|
const toggle = await renderTemplate(getPrepaidToggleTemplate());
|
|
74
80
|
toggle.productChangePrepaidShipments = jasmine.createSpy('productChangePrepaidShipments');
|
|
75
81
|
const checkbox = toggle.shadowRoot.querySelector('input');
|
|
76
82
|
|
|
77
83
|
// checking checkbox selects default value
|
|
78
84
|
toggleCheckbox(checkbox);
|
|
79
|
-
expectPrepaidShipmentsAction(toggle,
|
|
85
|
+
expectPrepaidShipmentsAction(toggle, 6);
|
|
80
86
|
|
|
81
87
|
// changing select changes selection
|
|
82
88
|
const select = toggle.shadowRoot.querySelector('og-select');
|
|
83
|
-
selectOption(select,
|
|
89
|
+
selectOption(select, 3);
|
|
84
90
|
// This is changed on the prepaidShipmentsSelected reducer by the productChangePrepaidShipments action
|
|
85
|
-
toggle.prepaidShipmentsSelected =
|
|
86
|
-
expectPrepaidShipmentsAction(toggle,
|
|
91
|
+
toggle.prepaidShipmentsSelected = 3;
|
|
92
|
+
expectPrepaidShipmentsAction(toggle, 3);
|
|
87
93
|
|
|
88
94
|
// unchecking checkbox opts out of prepaid
|
|
89
95
|
toggleCheckbox(checkbox);
|
|
@@ -91,7 +97,7 @@ describe('PrepaidToggle', () => {
|
|
|
91
97
|
|
|
92
98
|
// checking checkbox again opts into previously selected value
|
|
93
99
|
toggleCheckbox(checkbox);
|
|
94
|
-
expectPrepaidShipmentsAction(toggle,
|
|
100
|
+
expectPrepaidShipmentsAction(toggle, 3);
|
|
95
101
|
});
|
|
96
102
|
|
|
97
103
|
it('should preselect a value if shipments is set', async () => {
|
|
@@ -112,4 +118,19 @@ describe('PrepaidToggle', () => {
|
|
|
112
118
|
// should render an empty component and not throw
|
|
113
119
|
expect(toggle.shadowRoot.textContent).toBe('');
|
|
114
120
|
});
|
|
121
|
+
|
|
122
|
+
it('should select default prepaid shipments if provided', async () => {
|
|
123
|
+
const toggle = await renderTemplate(getPrepaidToggleTemplate([3, 6, 9]));
|
|
124
|
+
toggle.defaultPrepaidShipments = 9;
|
|
125
|
+
|
|
126
|
+
await toggle.updateComplete;
|
|
127
|
+
|
|
128
|
+
const select = toggle.shadowRoot.querySelector('og-select');
|
|
129
|
+
expect(select.selected).toBe(9);
|
|
130
|
+
|
|
131
|
+
// if provided default value is not present in options, it should fall back to the 2nd option
|
|
132
|
+
toggle.defaultPrepaidShipments = 10;
|
|
133
|
+
await toggle.updateComplete;
|
|
134
|
+
expect(select.selected).toBe(6);
|
|
135
|
+
});
|
|
115
136
|
});
|
|
@@ -117,4 +117,27 @@ describe('makeProductPrepaidShipmentOptionsSelector', () => {
|
|
|
117
117
|
const selector = makeProductPrepaidShipmentOptionsSelector(123);
|
|
118
118
|
expect(selector({ config: { prepaidSellingPlans: { 456: [{ numberShipments: 3 }] } } })).toEqual([]);
|
|
119
119
|
});
|
|
120
|
+
|
|
121
|
+
it('should sort the options', () => {
|
|
122
|
+
const selector = makeProductPrepaidShipmentOptionsSelector(123);
|
|
123
|
+
expect(
|
|
124
|
+
selector({
|
|
125
|
+
config: {
|
|
126
|
+
prepaidSellingPlans: {
|
|
127
|
+
123: [
|
|
128
|
+
{
|
|
129
|
+
numberShipments: 6
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
numberShipments: 3
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
numberShipments: 12
|
|
136
|
+
}
|
|
137
|
+
]
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
})
|
|
141
|
+
).toEqual([3, 6, 12]);
|
|
142
|
+
});
|
|
120
143
|
});
|
package/src/core/selectors.js
CHANGED
|
@@ -140,10 +140,10 @@ export const makeProductPrepaidShipmentsOptedInSelector = memoize(productId =>
|
|
|
140
140
|
);
|
|
141
141
|
|
|
142
142
|
export const makeProductPrepaidShipmentOptionsSelector = memoize(productId =>
|
|
143
|
-
createSelector(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
)
|
|
143
|
+
createSelector(prepaidSellingPlansSelector, prepaidSellingPlans => {
|
|
144
|
+
const shipmentsList = prepaidSellingPlans[productId]?.map(({ numberShipments }) => numberShipments) || [];
|
|
145
|
+
return shipmentsList.sort((a, b) => a - b);
|
|
146
|
+
})
|
|
147
147
|
);
|
|
148
148
|
|
|
149
149
|
/**
|