@ordergroove/offers 2.48.7-alpha-PR-1482-3.31 → 2.48.7
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/CHANGELOG.md +11 -0
- package/dist/bundle-report.html +12 -15
- package/dist/offers.js +35 -41
- package/dist/offers.js.map +4 -4
- package/package.json +2 -2
- package/src/__tests__/offers.spec.js +0 -1
- package/src/components/Tooltip.js +1 -1
- package/src/components/__tests__/OG.fspec.js +0 -1
- package/src/components/__tests__/Tooltip.spec.js +6 -0
- package/src/core/__tests__/reducer.spec.js +0 -4
- package/src/core/actions.js +0 -11
- package/src/core/constants.js +0 -1
- package/src/core/reducer.ts +1 -13
- package/src/core/types/reducer.ts +1 -5
- package/src/index.js +0 -1
- package/src/make-api.js +0 -12
- package/src/shopify/shopifyReducer.ts +1 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/src/components/BenefitMessages.js +0 -66
- package/src/components/__tests__/BenefitMessages.spec.js +0 -221
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import { BenefitMessages, mapStateToProps } from '../BenefitMessages';
|
|
2
|
-
import { appendToBody } from './utils';
|
|
3
|
-
|
|
4
|
-
customElements.define('og-benefit-messages-test', BenefitMessages);
|
|
5
|
-
|
|
6
|
-
describe('BenefitMessages', () => {
|
|
7
|
-
it('renders one li per message inside a ul', async () => {
|
|
8
|
-
const el = new BenefitMessages();
|
|
9
|
-
el.messages = ['Free shipping', 'Cancel anytime', '5% off every order'];
|
|
10
|
-
await appendToBody(el);
|
|
11
|
-
|
|
12
|
-
const ul = el.querySelector('ul.og-benefit-messages');
|
|
13
|
-
expect(ul).toBeTruthy();
|
|
14
|
-
const items = el.querySelectorAll('li');
|
|
15
|
-
expect(items.length).toBe(3);
|
|
16
|
-
expect(items[0].textContent.trim()).toBe('Free shipping');
|
|
17
|
-
expect(items[1].textContent.trim()).toBe('Cancel anytime');
|
|
18
|
-
expect(items[2].textContent.trim()).toBe('5% off every order');
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('renders nothing when messages is an empty array', async () => {
|
|
22
|
-
const el = new BenefitMessages();
|
|
23
|
-
el.messages = [];
|
|
24
|
-
await appendToBody(el);
|
|
25
|
-
|
|
26
|
-
expect(el.querySelector('ul')).toBeNull();
|
|
27
|
-
expect(el.querySelectorAll('li').length).toBe(0);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('renders nothing when messages is undefined', async () => {
|
|
31
|
-
const el = new BenefitMessages();
|
|
32
|
-
await appendToBody(el);
|
|
33
|
-
|
|
34
|
-
expect(el.querySelector('ul')).toBeNull();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('escapes message strings as text (no HTML interpolation)', async () => {
|
|
38
|
-
const el = new BenefitMessages();
|
|
39
|
-
el.messages = ['<img src=x onerror="alert(1)">'];
|
|
40
|
-
await appendToBody(el);
|
|
41
|
-
|
|
42
|
-
const li = el.querySelector('li');
|
|
43
|
-
expect(li).toBeTruthy();
|
|
44
|
-
expect(li.querySelector('img')).toBeNull();
|
|
45
|
-
expect(li.textContent.trim()).toBe('<img src=x onerror="alert(1)">');
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('re-renders correctly after disconnect and reconnect', async () => {
|
|
49
|
-
const el = new BenefitMessages();
|
|
50
|
-
el.messages = ['First'];
|
|
51
|
-
await appendToBody(el);
|
|
52
|
-
expect(el.querySelector('li').textContent.trim()).toBe('First');
|
|
53
|
-
|
|
54
|
-
el.remove();
|
|
55
|
-
|
|
56
|
-
el.messages = ['After remount A', 'After remount B'];
|
|
57
|
-
await appendToBody(el);
|
|
58
|
-
|
|
59
|
-
const items = el.querySelectorAll('li');
|
|
60
|
-
expect(items.length).toBe(2);
|
|
61
|
-
expect(items[0].textContent.trim()).toBe('After remount A');
|
|
62
|
-
expect(items[1].textContent.trim()).toBe('After remount B');
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe('BenefitMessages mapStateToProps', () => {
|
|
67
|
-
const state = ({ incentivesForProduct, benefitMessages, productId = 'prod-1' } = {}) => ({
|
|
68
|
-
incentives: incentivesForProduct ? { [productId]: incentivesForProduct } : {},
|
|
69
|
-
benefitMessages: benefitMessages || {}
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('returns messages for the product, initial first then ongoing', () => {
|
|
73
|
-
expect(
|
|
74
|
-
mapStateToProps(
|
|
75
|
-
state({
|
|
76
|
-
incentivesForProduct: {
|
|
77
|
-
initial: [{ enhanced: true, id: 'inc-init' }],
|
|
78
|
-
ongoing: [{ enhanced: true, id: 'inc-ongoing' }]
|
|
79
|
-
},
|
|
80
|
-
benefitMessages: {
|
|
81
|
-
'inc-init': 'First-order bonus',
|
|
82
|
-
'inc-ongoing': 'Every-order discount'
|
|
83
|
-
}
|
|
84
|
-
}),
|
|
85
|
-
{ product: { id: 'prod-1' } }
|
|
86
|
-
)
|
|
87
|
-
).toEqual({ messages: ['First-order bonus', 'Every-order discount'] });
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('dedupes by incentive id when the same id appears in both initial and ongoing', () => {
|
|
91
|
-
expect(
|
|
92
|
-
mapStateToProps(
|
|
93
|
-
state({
|
|
94
|
-
incentivesForProduct: {
|
|
95
|
-
initial: [{ enhanced: true, id: 'inc-shared' }],
|
|
96
|
-
ongoing: [
|
|
97
|
-
{ enhanced: true, id: 'inc-shared' },
|
|
98
|
-
{ enhanced: true, id: 'inc-extra' }
|
|
99
|
-
]
|
|
100
|
-
},
|
|
101
|
-
benefitMessages: {
|
|
102
|
-
'inc-shared': 'Shared',
|
|
103
|
-
'inc-extra': 'Extra'
|
|
104
|
-
}
|
|
105
|
-
}),
|
|
106
|
-
{ product: { id: 'prod-1' } }
|
|
107
|
-
)
|
|
108
|
-
).toEqual({ messages: ['Shared', 'Extra'] });
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('skips incentives that have no configured message', () => {
|
|
112
|
-
expect(
|
|
113
|
-
mapStateToProps(
|
|
114
|
-
state({
|
|
115
|
-
incentivesForProduct: {
|
|
116
|
-
initial: [
|
|
117
|
-
{ enhanced: true, id: 'inc-1' },
|
|
118
|
-
{ enhanced: true, id: 'inc-2' }
|
|
119
|
-
],
|
|
120
|
-
ongoing: [{ enhanced: true, id: 'inc-3' }]
|
|
121
|
-
},
|
|
122
|
-
benefitMessages: {
|
|
123
|
-
'inc-2': 'Only this one is configured'
|
|
124
|
-
}
|
|
125
|
-
}),
|
|
126
|
-
{ product: { id: 'prod-1' } }
|
|
127
|
-
)
|
|
128
|
-
).toEqual({ messages: ['Only this one is configured'] });
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('handles missing initial array (only ongoing)', () => {
|
|
132
|
-
expect(
|
|
133
|
-
mapStateToProps(
|
|
134
|
-
state({
|
|
135
|
-
incentivesForProduct: { ongoing: [{ enhanced: true, id: 'inc-1' }] },
|
|
136
|
-
benefitMessages: { 'inc-1': 'Ongoing only' }
|
|
137
|
-
}),
|
|
138
|
-
{ product: { id: 'prod-1' } }
|
|
139
|
-
)
|
|
140
|
-
).toEqual({ messages: ['Ongoing only'] });
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('handles missing ongoing array (only initial)', () => {
|
|
144
|
-
expect(
|
|
145
|
-
mapStateToProps(
|
|
146
|
-
state({
|
|
147
|
-
incentivesForProduct: { initial: [{ enhanced: true, id: 'inc-1' }] },
|
|
148
|
-
benefitMessages: { 'inc-1': 'Initial only' }
|
|
149
|
-
}),
|
|
150
|
-
{ product: { id: 'prod-1' } }
|
|
151
|
-
)
|
|
152
|
-
).toEqual({ messages: ['Initial only'] });
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it('returns [] when both initial and ongoing are empty', () => {
|
|
156
|
-
expect(
|
|
157
|
-
mapStateToProps(
|
|
158
|
-
state({
|
|
159
|
-
incentivesForProduct: { initial: [], ongoing: [] },
|
|
160
|
-
benefitMessages: { 'inc-1': 'Should not appear' }
|
|
161
|
-
}),
|
|
162
|
-
{ product: { id: 'prod-1' } }
|
|
163
|
-
)
|
|
164
|
-
).toEqual({ messages: [] });
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it('returns [] when the product has no incentives entry', () => {
|
|
168
|
-
expect(
|
|
169
|
-
mapStateToProps(
|
|
170
|
-
{ incentives: {}, benefitMessages: { 'inc-1': 'Should not appear' } },
|
|
171
|
-
{ product: { id: 'prod-1' } }
|
|
172
|
-
)
|
|
173
|
-
).toEqual({ messages: [] });
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it('returns [] when state has no benefitMessages key', () => {
|
|
177
|
-
expect(
|
|
178
|
-
mapStateToProps(
|
|
179
|
-
{ incentives: { 'prod-1': { initial: [{ enhanced: true, id: 'inc-1' }], ongoing: [] } } },
|
|
180
|
-
{ product: { id: 'prod-1' } }
|
|
181
|
-
)
|
|
182
|
-
).toEqual({ messages: [] });
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it('returns [] when no incentive has a matching message', () => {
|
|
186
|
-
expect(
|
|
187
|
-
mapStateToProps(
|
|
188
|
-
state({
|
|
189
|
-
incentivesForProduct: {
|
|
190
|
-
initial: [{ enhanced: true, id: 'inc-1' }],
|
|
191
|
-
ongoing: [{ enhanced: true, id: 'inc-2' }]
|
|
192
|
-
},
|
|
193
|
-
benefitMessages: { 'inc-other': 'Unrelated' }
|
|
194
|
-
}),
|
|
195
|
-
{ product: { id: 'prod-1' } }
|
|
196
|
-
)
|
|
197
|
-
).toEqual({ messages: [] });
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it('returns [] when ownProps has no product', () => {
|
|
201
|
-
expect(mapStateToProps({ benefitMessages: { 'inc-1': 'm' } }, {})).toEqual({ messages: [] });
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it('skips incentives that were not in incentives_display_enhanced', () => {
|
|
205
|
-
expect(
|
|
206
|
-
mapStateToProps(
|
|
207
|
-
state({
|
|
208
|
-
incentivesForProduct: {
|
|
209
|
-
initial: [{ id: 'inc-non-enhanced' }, { enhanced: true, id: 'inc-enhanced' }],
|
|
210
|
-
ongoing: []
|
|
211
|
-
},
|
|
212
|
-
benefitMessages: {
|
|
213
|
-
'inc-non-enhanced': 'Should not appear',
|
|
214
|
-
'inc-enhanced': 'Should appear'
|
|
215
|
-
}
|
|
216
|
-
}),
|
|
217
|
-
{ product: { id: 'prod-1' } }
|
|
218
|
-
)
|
|
219
|
-
).toEqual({ messages: ['Should appear'] });
|
|
220
|
-
});
|
|
221
|
-
});
|